Skip to content

Commit

Permalink
chore: support arbitrary flags for fallback commands
Browse files Browse the repository at this point in the history
add test
  • Loading branch information
PeterSchafer committed Mar 10, 2023
1 parent 39b3652 commit c832be7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cliv2/cmd/cliv2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ func createCommandsForWorkflows(rootCommand *cobra.Command, engine workflow.Engi
subCmd := commandMap[currentParts]
if subCmd == nil {
subCmd = &cobra.Command{
Use: subCmdName,
Hidden: true,
RunE: emptyCommandFunction, // ensure to trigger the fallback case
Use: subCmdName,
Hidden: true,
RunE: emptyCommandFunction, // ensure to trigger the fallback case
DisableFlagParsing: true, // disable flag parsing to allow arbitrary flags for commands that will trigger the fallback
}
parentCommand.AddCommand(subCmd)
commandMap[currentParts] = subCmd
Expand All @@ -174,6 +175,7 @@ func createCommandsForWorkflows(rootCommand *cobra.Command, engine workflow.Engi
}
parentCommand.RunE = runCommand
parentCommand.Hidden = !workflowEntry.IsVisible()
parentCommand.DisableFlagParsing = false
}
}

Expand Down
3 changes: 3 additions & 0 deletions cliv2/cmd/cliv2/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func Test_CreateCommandsForWorkflowWithSubcommands(t *testing.T) {
assert.True(t, doFallback(subcmd1.RunE(subcmd1, []string{})))
assert.True(t, doFallback(cmd2.RunE(cmd2, []string{})))

assert.True(t, subcmd1.DisableFlagParsing)
assert.False(t, subcmd2.DisableFlagParsing)

assert.False(t, subcmd2.HasSubCommands())
assert.Equal(t, "subcmd2", subcmd2.Name())
assert.False(t, subcmd3.Hidden)
Expand Down

0 comments on commit c832be7

Please sign in to comment.