Skip to content

Commit 75d6a5e

Browse files
authored
fix(doctor): fix ignite doctor tool (#4575)
1 parent 6192dc0 commit 75d6a5e

File tree

5 files changed

+43
-22
lines changed

5 files changed

+43
-22
lines changed

ignite/cmd/doctor.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ func NewDoctor() *cobra.Command {
2525
return err
2626
}
2727

28+
if err := doc.MigrateToolsGo(appPath); err != nil {
29+
return err
30+
}
31+
2832
configPath, err := chainconfig.LocateDefault(appPath)
2933
if err != nil {
3034
return err
@@ -38,10 +42,6 @@ func NewDoctor() *cobra.Command {
3842
return err
3943
}
4044

41-
if err := doc.MigrateToolsGo(appPath); err != nil {
42-
return err
43-
}
44-
4545
if err := doc.MigratePluginsConfig(); err != nil {
4646
return err
4747
}

ignite/pkg/cosmosbuf/buf.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,15 @@ func (b Buf) Update(ctx context.Context, modDir string) error {
169169

170170
// Migrate runs the buf Migrate command for the files in the app directory.
171171
func (b Buf) Migrate(ctx context.Context, protoDir string) error {
172-
yamlFiles, err := xos.FindFiles(protoDir, xos.WithExtension(xos.YAMLFile), xos.WithPrefix(bufGenPrefix))
172+
yamlFiles, err := xos.FindFiles(protoDir, xos.WithExtension(xos.YMLFile), xos.WithExtension(xos.YAMLFile), xos.WithPrefix(bufGenPrefix))
173173
if err != nil {
174174
return err
175175
}
176-
ymlfiles, err := xos.FindFiles(protoDir, xos.WithExtension(xos.YMLFile), xos.WithPrefix(bufGenPrefix))
177-
if err != nil {
178-
return err
179-
}
180-
yamlFiles = append(yamlFiles, ymlfiles...)
181176

182177
flags := map[string]string{
183178
flagWorkspace: ".",
184179
}
180+
185181
if len(yamlFiles) > 0 {
186182
flags[flagBufGenYaml] = strings.Join(yamlFiles, ",")
187183
}
@@ -190,6 +186,7 @@ func (b Buf) Migrate(ctx context.Context, protoDir string) error {
190186
if err != nil {
191187
return err
192188
}
189+
193190
return b.runCommand(ctx, cmd...)
194191
}
195192

ignite/pkg/xos/files.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ const (
1515
)
1616

1717
type findFileOptions struct {
18-
extension string
18+
extension []string
1919
prefix string
2020
}
2121

2222
type FindFileOptions func(o *findFileOptions)
2323

24+
// WithExtension adds a file extension to the search options.
25+
// It can be called multiple times to add multiple extensions.
2426
func WithExtension(extension string) FindFileOptions {
2527
return func(o *findFileOptions) {
26-
o.extension = extension
28+
o.extension = append(o.extension, extension)
2729
}
2830
}
2931

@@ -48,7 +50,15 @@ func FindFiles(directory string, options ...FindFileOptions) ([]string, error) {
4850
}
4951

5052
// Filter by file extension if provided
51-
if opts.extension != "" && filepath.Ext(path) != fmt.Sprintf(".%s", opts.extension) {
53+
var matched bool
54+
for _, ext := range opts.extension {
55+
if filepath.Ext(path) == fmt.Sprintf(".%s", ext) {
56+
matched = true
57+
break
58+
}
59+
}
60+
61+
if len(opts.extension) > 0 && !matched {
5262
return nil // Skip files that don't match the extension
5363
}
5464

ignite/pkg/xos/files_test.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestFindFiles(t *testing.T) {
1515
tests := []struct {
1616
name string
1717
files []string
18-
extension string
18+
extension []string
1919
prefix string
2020
want []string
2121
err error
@@ -62,46 +62,53 @@ func TestFindFiles(t *testing.T) {
6262
{
6363
name: "test 3 extension json files",
6464
files: []string{"file1.json", "file2.txt", "file3.json", "file4.json"},
65-
extension: "json",
65+
extension: []string{"json"},
6666
want: []string{"file1.json", "file3.json", "file4.json"},
6767
err: nil,
6868
},
6969
{
7070
name: "test 3 extension json files with subfolder",
7171
files: []string{"testdata/file1.json", "file2.txt", "foo/file3.json", "file4.json"},
72-
extension: "json",
72+
extension: []string{"json"},
7373
want: []string{"testdata/file1.json", "foo/file3.json", "file4.json"},
7474
err: nil,
7575
},
7676
{
7777
name: "test 1 extension txt files",
7878
files: []string{"file1.json", "file2.txt", "file3.json", "file4.json"},
79-
extension: "txt",
79+
extension: []string{"txt"},
8080
want: []string{"file2.txt"},
8181
err: nil,
8282
},
8383
{
8484
name: "test 1 extension json files",
8585
files: []string{"file1.json"},
86-
extension: "json",
86+
extension: []string{"json"},
8787
want: []string{"file1.json"},
8888
err: nil,
8989
},
9090
{
9191
name: "test invalid files extension",
9292
files: []string{"file1.json", "file2.json", "file3.json", "file4.json"},
93-
extension: "txt",
93+
extension: []string{"txt"},
9494
want: []string{},
9595
err: nil,
9696
},
9797
{
9898
name: "test file prefix and extension",
9999
files: []string{"test.file1.json", "test.file2.txt", "test.file3.json"},
100100
prefix: "test.file",
101-
extension: "json",
101+
extension: []string{"json"},
102102
want: []string{"test.file1.json", "test.file3.json"},
103103
err: nil,
104104
},
105+
{
106+
name: "test 2 different extensions",
107+
files: []string{"file1.json", "file2.txt", "file3.json", "file4.json", "file.yaml"},
108+
extension: []string{"txt", "yaml"},
109+
want: []string{"file2.txt", "file.yaml"},
110+
err: nil,
111+
},
105112
}
106113
for _, tt := range tests {
107114
t.Run(tt.name, func(t *testing.T) {
@@ -124,8 +131,9 @@ func TestFindFiles(t *testing.T) {
124131
if tt.prefix != "" {
125132
opts = append(opts, xos.WithPrefix(tt.prefix))
126133
}
127-
if tt.extension != "" {
128-
opts = append(opts, xos.WithExtension(tt.extension))
134+
135+
for _, ext := range tt.extension {
136+
opts = append(opts, xos.WithExtension(ext))
129137
}
130138

131139
gotFiles, err := xos.FindFiles(tempDir, opts...)

ignite/services/doctor/doctor.go

+6
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ func (d *Doctor) MigrateBufConfig(ctx context.Context, cacheStorage cache.Storag
8282
return errf(err)
8383
}
8484

85+
d.ev.Send(
86+
"Important: Update the local field of buf files to use `go tool`",
87+
events.Icon(icons.Announcement),
88+
events.Indent(1),
89+
)
90+
8591
d.ev.Send(
8692
"buf config files migrated",
8793
events.Icon(icons.OK),

0 commit comments

Comments
 (0)