Skip to content

Commit 1ee9a77

Browse files
leodidofntlnz
authored andcommitted
feat(cmd): override help for all commands
Signed-off-by: Leonardo Di Donato <[email protected]>
1 parent 350fc53 commit 1ee9a77

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

pkg/cmd/run.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ type RunOptions struct {
5353
namespace string
5454
explicitNamespace bool
5555

56-
// Local to this command
56+
// Flags local to this command
5757
container string
5858
eval string
5959
program string
60-
resourceArg string
61-
attach bool
62-
isPod bool
63-
podUID string
6460
serviceAccount string
6561

66-
nodeName string
62+
resourceArg string
63+
attach bool
64+
isPod bool
65+
podUID string
66+
nodeName string
6767

6868
clientConfig *rest.Config
6969
}

pkg/cmd/trace.go

+13
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,18 @@ func NewTraceCommand(streams genericclioptions.IOStreams) *cobra.Command {
7676
cmd.AddCommand(NewVersionCommand(streams))
7777
cmd.AddCommand(NewLogCommand(f, streams))
7878

79+
// Override help on all the commands tree
80+
walk(cmd, func(c *cobra.Command) {
81+
c.Flags().BoolP("help", "h", false, fmt.Sprintf("Help for the %s command", c.Name()))
82+
})
83+
7984
return cmd
8085
}
86+
87+
// walk calls f for c and all of its children.
88+
func walk(c *cobra.Command, f func(*cobra.Command)) {
89+
f(c)
90+
for _, c := range c.Commands() {
91+
walk(c, f)
92+
}
93+
}

0 commit comments

Comments
 (0)