Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
internal/cli: --version reroutes to waypoint version
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Apr 20, 2021
1 parent 2ed8fe4 commit d706ad0
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions internal/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,27 @@ func Main(args []string) int {
base, commands := Commands(ctx, log, logOutput)
defer base.Close()

// Build the CLI
cli := &cli.CLI{
Name: args[0],
Args: args[1:],
Version: vsn.FullVersionNumber(true),
Commands: commands,
Autocomplete: true,
AutocompleteNoDefaultFlags: true,
HelpFunc: GroupedHelpFunc(cli.BasicHelpFunc(cliName)),
// Build the CLI. We use a CLI factory function because to modify the
// args once you call a func on CLI you need to create a new CLI instance.
cliFactory := func() *cli.CLI {
return &cli.CLI{
Name: args[0],
Args: args[1:],
Version: vsn.FullVersionNumber(true),
Commands: commands,
Autocomplete: true,
AutocompleteNoDefaultFlags: true,
HelpFunc: GroupedHelpFunc(cli.BasicHelpFunc(cliName)),
}
}

// Copy the CLI to check if it is a version call. If so, we modify
// the args to just be the version subcommand. This ensures that
// --version behaves by calling `waypoint version` and we get consistent
// behavior.
cli := cliFactory()
if cliFactory().IsVersion() {
cli.Args = []string{"version"}
}

// Run the CLI
Expand Down

0 comments on commit d706ad0

Please sign in to comment.