Skip to content

Commit

Permalink
Fix pflag binding for demo cmd
Browse files Browse the repository at this point in the history
Summary:
TSIA. The cmd object passed into PersistentPreRun is the lowermost
level cmd. So the flag lookup on the command only finds the local flags but
not inherited flags. This fixes the lookup for the demo commands.

Test Plan: Build a px binary and tried to deploy demo apps.

Reviewers: michelle

Reviewed By: michelle

Signed-off-by: Vihang Mehta <[email protected]>

Differential Revision: https://phab.corp.pixielabs.ai/D12006

GitOrigin-RevId: 1f8cdfb
  • Loading branch information
vihangm authored and copybaranaut committed Aug 3, 2022
1 parent b8c2817 commit 2f3f26c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/pixie_cli/pkg/cmd/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ var DemoCmd = &cobra.Command{
Use: "demo",
Short: "Manage demo apps",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlag("artifacts", cmd.PersistentFlags().Lookup("artifacts"))
// This pre run might be run from a subcommand. To bind the correct flag, we should check
// the persistent flags on both the current command and the parent.
if cmd.PersistentFlags().Lookup("artifacts") != nil {
viper.BindPFlag("artifacts", cmd.PersistentFlags().Lookup("artifacts"))
return
}
viper.BindPFlag("artifacts", cmd.Parent().PersistentFlags().Lookup("artifacts"))
},
Run: func(cmd *cobra.Command, args []string) {
utils.Info("Nothing here... Please execute one of the subcommands")
Expand Down

0 comments on commit 2f3f26c

Please sign in to comment.