Merge pull request #146 from eparis/is-available-rework
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Update IsAvailableCommand checks
authored by Eric Paris · committed by Eric Paris · parents 75d96d7, 3eac143 · Browse files · 5 files·+16 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+16 added−12 removed
- other:+16 added−12 removed
Provenance
- Commit
4b86c66- Tree
e5a32f9- Author
Eric Paris <eparis@redhat.com>- Committer
Eric Paris <eparis@redhat.com>- Parent 1
75d96d7- Parent 2
3eac143
5 files changed+16 added−12 removed
modified:bash_completions.go+2 added-2 removed
221 unmodified lines222 223 func writeCommands(cmd *Command, out *bytes.Buffer) {224 fmt.Fprintf(out, " commands=()\n")225 for _, c := range cmd.Commands() {226- if len(c.Deprecated) > 0 || c == cmd.helpCommand {226+ if !c.IsAvailableCommand() || c == cmd.helpCommand {227 continue228 }229 fmt.Fprintf(out, " commands+=(%q)\n", c.Name())230 }100 unmodified lines331 }332 333 func gen(cmd *Command, out *bytes.Buffer) {334 for _, c := range cmd.Commands() {335- if len(c.Deprecated) > 0 || c == cmd.helpCommand {335+ if !c.IsAvailableCommand() || c == cmd.helpCommand {336 continue337 }338 gen(c, out)339 }59 unmodified linesmodified:command.go+8 added-2 removed
853 unmodified lines854 855 // IsAvailableCommand determines if a command is available as a non-help command856 // (this includes all non deprecated/hidden commands)857 func (c *Command) IsAvailableCommand() bool {858+ if len(c.Deprecated) != 0 || c.Hidden {859+ return false860+ }861 859- // a command is 'available' if it is runnable and is not deprecated/hidden860- return c.Runnable() && len(c.Deprecated) == 0 && !c.Hidden862+ if c.Runnable() || c.HasAvailableSubCommands() {863+ return true864+ }865+866+ return false867 }868 869 // IsHelpCommand determines if a command is a 'help' command; a help command is870 // determined by the fact that it is NOT runnable/hidden/deprecated, and has no239 unmodified linesmodified:doc_util.go+1 added-3 removed
11 unmodified lines12 // limitations under the License.13 14 package cobra15 16-import ()17-16 // Test to see if we have a reason to print See Also information in docs17 // Basically this is a test for a parent commend or a subcommand which is18 // both not deprecated and not the autogenerated help command.19 func (cmd *Command) hasSeeAlso() bool {4 unmodified lines24 if len(children) == 0 {25 return false26 }27 for _, c := range children {30- if len(c.Deprecated) != 0 || c == cmd.helpCommand {28+ if !c.IsAvailableCommand() || c == cmd.helpCommand {29 continue30 }31 return true32 }2 unmodified linesmodified:man_docs.go+3 added-3 removed
38 unmodified lines39 if header == nil {40 header = &GenManHeader{}41 }42 for _, c := range cmd.Commands() {43- if len(c.Deprecated) != 0 || c == cmd.helpCommand {43+ if !c.IsAvailableCommand() || c == cmd.helpCommand {44 continue45 }46 GenManTree(c, header, dir)47 }76 unmodified lines124 }125 126 func manPrintFlags(out *bytes.Buffer, flags *pflag.FlagSet) {127 flags.VisitAll(func(flag *pflag.Flag) {128- if len(flag.Deprecated) > 0 {128+ if len(flag.Deprecated) > 0 || flag.Hidden {129 return130 }131 format := ""132 if len(flag.Shorthand) > 0 {66 unmodified lines199 200 children := cmd.Commands()201 sort.Sort(byName(children))202 for _, c := range children {203- if len(c.Deprecated) != 0 || c == cmd.helpCommand {203+ if !c.IsAvailableCommand() || c == cmd.helpCommand {204 continue205 }206 fmt.Fprintf(buf, "**%s-%s(%s)**, ", dashCommandName, c.Name(), header.Section)207 }6 unmodified linesmodified:md_docs.go+2 added-2 removed
95 unmodified lines96 children := cmd.Commands()97 sort.Sort(byName(children))98 99 for _, child := range children {100- if len(child.Deprecated) > 0 || child == cmd.helpCommand {100+ if !child.IsAvailableCommand() || child == cmd.helpCommand {101 continue102 }103 cname := name + " " + child.Name()104 link := cname + ".md"21 unmodified lines126 }127 128 func (cmd *Command) GenMarkdownTreeCustom(dir string, filePrepender func(string) string, linkHandler func(string) string) {129 for _, c := range cmd.Commands() {130- if len(c.Deprecated) != 0 || c == cmd.helpCommand {130+ if !c.IsAvailableCommand() || c == cmd.helpCommand {131 continue132 }133 c.GenMarkdownTreeCustom(dir, filePrepender, linkHandler)134 }23 unmodified lines