-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cdk): handle -v flag for components (#1170)
Two issues here - parsing of -v would loop without returning. And executing with -v (which cobra handles and prints the version) didn't work.
- Loading branch information
Showing
3 changed files
with
25 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,7 +184,7 @@ func (c *cliState) LoadComponents() { | |
c.Log.Debugw("loading dynamic cli command", | ||
"component", component.Name, "version", ver, | ||
) | ||
rootCmd.AddCommand( | ||
componentCmd := | ||
&cobra.Command{ | ||
Use: component.Name, | ||
Short: component.Description, | ||
|
@@ -194,6 +194,15 @@ func (c *cliState) LoadComponents() { | |
DisableFlagParsing: true, | ||
DisableFlagsInUseLine: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
// cobra will automatically add a -v/--version flag to | ||
// the command, but because for components we're not | ||
// parsing the args at the usual point in time, we have | ||
// to repeat the check for -v here | ||
versionVal, _ := cmd.Flags().GetBool("version") | ||
if versionVal { | ||
cmd.Printf("%s version %s\n", cmd.Use, cmd.Version) | ||
return nil | ||
} | ||
go func() { | ||
// Start the gRPC server for components to communicate back | ||
if err := c.Serve(); err != nil { | ||
|
@@ -218,8 +227,8 @@ func (c *cliState) LoadComponents() { | |
// happens, let the user know that we would love to hear their feedback | ||
return errors.New("something went pretty wrong here, contact [email protected]") | ||
}, | ||
}, | ||
) | ||
} | ||
rootCmd.AddCommand(componentCmd) | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters