Skip to content
Myr

Issue #267: Ensure hidden flags/subcommands do not change help

Before adoption: this commit came in with the history the project adopted, so no landing records it.

If a command has one flag which is hidden, it should not, for instance, show the `Flags: ` heading. Likewise there are other items in the help template which should respect hidden/deprecated state.

authored by John Schnake · committed by Steve Francia · parent 9a8186d · Browse files · 1 file+28 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+28 added−4 removed

  • other:+28 added−4 removed

1 file+28 added−4 removed

modified:command.go+28 added-4 removed
259 unmodified lines
260 if c.HasParent() {261 return c.parent.UsageTemplate()262 }263 return `Usage:{{if .Runnable}}264 {{if .HasFlags}}{{appendIfNotPresent .UseLine "[flags]"}}{{else}}{{.UseLine}}{{end}}{{end}}{{if .HasSubCommands}}264 {{if .HasAvailableFlags}}{{appendIfNotPresent .UseLine "[flags]"}}{{else}}{{.UseLine}}{{end}}{{end}}{{if .HasAvailableSubCommands}}265 {{ .CommandPath}} [command]{{end}}{{if gt .Aliases 0}}266267Aliases:268 {{.NameAndAliases}}
2 unmodified lines
271Examples:272{{ .Example }}{{end}}{{ if .HasAvailableSubCommands}}273274Available Commands:{{range .Commands}}{{if .IsAvailableCommand}}275 {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{ if .HasLocalFlags}}275 {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{ if .HasAvailableLocalFlags}}276277Flags:278{{.LocalFlags.FlagUsages | trimRightSpace}}{{end}}{{ if .HasInheritedFlags}}278{{.LocalFlags.FlagUsages | trimRightSpace}}{{end}}{{ if .HasAvailableInheritedFlags}}279280Global Flags:281{{.InheritedFlags.FlagUsages | trimRightSpace}}{{end}}{{if .HasHelpSubCommands}}282283Additional help topics:{{range .Commands}}{{if .IsHelpCommand}}284 {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{ if .HasSubCommands }}284 {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{ if .HasAvailableSubCommands }}285286Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}287`288}
824 unmodified lines
1113func (c *Command) HasLocalFlags() bool {1114 return c.LocalFlags().HasFlags()1115}11161117// Does the command have flags inherited from its parent command1118func (c *Command) HasInheritedFlags() bool {1119 return c.InheritedFlags().HasFlags()1120}11211122// Does the command contain any flags (local plus persistent from the entire1123// structure) which are not hidden or deprecated1124func (c *Command) HasAvailableFlags() bool {1125 return c.Flags().HasAvailableFlags()1126}11271128// Does the command contain persistent flags which are not hidden or deprecated1129func (c *Command) HasAvailablePersistentFlags() bool {1130 return c.PersistentFlags().HasAvailableFlags()1131}11321133// Does the command has flags specifically declared locally which are not hidden1134// or deprecated1135func (c *Command) HasAvailableLocalFlags() bool {1136 return c.LocalFlags().HasAvailableFlags()1137}11381139// Does the command have flags inherited from its parent command which are1140// not hidden or deprecated1141func (c *Command) HasAvailableInheritedFlags() bool {1142 return c.InheritedFlags().HasAvailableFlags()1143}11441145// Flag climbs up the command tree looking for matching flag1146func (c *Command) Flag(name string) (flag *flag.Flag) {1147 flag = c.Flags().Lookup(name)1148
69 unmodified lines