Skip to content

Commit 2f3f26c

Browse files
vihangmcopybaranaut
authored andcommitted
Fix pflag binding for demo cmd
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 <vihang@pixielabs.ai> Differential Revision: https://phab.corp.pixielabs.ai/D12006 GitOrigin-RevId: 1f8cdfb
1 parent b8c2817 commit 2f3f26c

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/pixie_cli/pkg/cmd/demo.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ var DemoCmd = &cobra.Command{
6767
Use: "demo",
6868
Short: "Manage demo apps",
6969
PersistentPreRun: func(cmd *cobra.Command, args []string) {
70-
viper.BindPFlag("artifacts", cmd.PersistentFlags().Lookup("artifacts"))
70+
// This pre run might be run from a subcommand. To bind the correct flag, we should check
71+
// the persistent flags on both the current command and the parent.
72+
if cmd.PersistentFlags().Lookup("artifacts") != nil {
73+
viper.BindPFlag("artifacts", cmd.PersistentFlags().Lookup("artifacts"))
74+
return
75+
}
76+
viper.BindPFlag("artifacts", cmd.Parent().PersistentFlags().Lookup("artifacts"))
7177
},
7278
Run: func(cmd *cobra.Command, args []string) {
7379
utils.Info("Nothing here... Please execute one of the subcommands")

0 commit comments

Comments
 (0)