Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use subcommands's VisitCommands instead of hardcoded map. #345

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions cmd/wire/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,22 @@ func main() {
log.SetPrefix("wire: ")
log.SetOutput(os.Stderr)

// TODO(rvangent): Use subcommands's VisitCommands instead of hardcoded map,
// once there is a release that contains it:
// allCmds := map[string]bool{}
// subcommands.DefaultCommander.VisitCommands(func(_ *subcommands.CommandGroup, cmd subcommands.Command) { allCmds[cmd.Name()] = true })
allCmds := map[string]bool{
"commands": true, // builtin
"help": true, // builtin
"flags": true, // builtin
"check": true,
"diff": true,
"gen": true,
"show": true,
if args := flag.Args(); len(args) != 0 {
argCmd := args[0]
subcommands.DefaultCommander.VisitCommands(func(cg *subcommands.CommandGroup, cmd subcommands.Command) {
if cg.Name() != "" {
return
}
if cmd.Name() == argCmd {
// Execute command from argument.
os.Exit(int(subcommands.Execute(context.Background())))
}
})
}

// Default to running the "gen" command.
if args := flag.Args(); len(args) == 0 || !allCmds[args[0]] {
genCmd := &genCmd{}
os.Exit(int(genCmd.Execute(context.Background(), flag.CommandLine)))
}
os.Exit(int(subcommands.Execute(context.Background())))
genCmd := &genCmd{}
os.Exit(int(genCmd.Execute(context.Background(), flag.CommandLine)))
}

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