Skip to content

Commit c272f38

Browse files
committed
Use subcommands's VisitCommands instead of hardcoded map
1 parent 9d78e0a commit c272f38

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

cmd/wire/main.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,22 @@ func main() {
5252
log.SetPrefix("wire: ")
5353
log.SetOutput(os.Stderr)
5454

55-
// TODO(rvangent): Use subcommands's VisitCommands instead of hardcoded map,
56-
// once there is a release that contains it:
57-
// allCmds := map[string]bool{}
58-
// subcommands.DefaultCommander.VisitCommands(func(_ *subcommands.CommandGroup, cmd subcommands.Command) { allCmds[cmd.Name()] = true })
59-
allCmds := map[string]bool{
60-
"commands": true, // builtin
61-
"help": true, // builtin
62-
"flags": true, // builtin
63-
"check": true,
64-
"diff": true,
65-
"gen": true,
66-
"show": true,
55+
if args := flag.Args(); len(args) != 0 {
56+
argCmd := args[0]
57+
subcommands.DefaultCommander.VisitCommands(func(cg *subcommands.CommandGroup, cmd subcommands.Command) {
58+
if cg.Name() != "" {
59+
return
60+
}
61+
if cmd.Name() == argCmd {
62+
// Execute command from argument.
63+
os.Exit(int(subcommands.Execute(context.Background())))
64+
}
65+
})
6766
}
67+
6868
// Default to running the "gen" command.
69-
if args := flag.Args(); len(args) == 0 || !allCmds[args[0]] {
70-
genCmd := &genCmd{}
71-
os.Exit(int(genCmd.Execute(context.Background(), flag.CommandLine)))
72-
}
73-
os.Exit(int(subcommands.Execute(context.Background())))
69+
genCmd := &genCmd{}
70+
os.Exit(int(genCmd.Execute(context.Background(), flag.CommandLine)))
7471
}
7572

7673
// packages returns the slice of packages to run wire over based on f.

0 commit comments

Comments
 (0)