Skip to content
Myr

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

5 files+16 added−12 removed

modified:bash_completions.go+2 added-2 removed
221 unmodified lines
222223func 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 lines
331}332333func 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 lines
modified:command.go+8 added-2 removed
853 unmodified lines
854855// IsAvailableCommand determines if a command is available as a non-help command856// (this includes all non deprecated/hidden commands)857func (c *Command) IsAvailableCommand() bool {858 if len(c.Deprecated) != 0 || c.Hidden {859 return false860 }861859 // 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 }865866 return false867}868869// 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 no
239 unmodified lines
modified:doc_util.go+1 added-3 removed
11 unmodified lines
12// limitations under the License.1314package cobra1516import ()1716// 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.19func (cmd *Command) hasSeeAlso() bool {
4 unmodified lines
24 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 lines
modified:man_docs.go+3 added-3 removed
38 unmodified lines
39 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 lines
124}125126func 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 lines
199200 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 lines
modified:md_docs.go+2 added-2 removed
95 unmodified lines
96 children := cmd.Commands()97 sort.Sort(byName(children))9899 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 lines
126}127128func (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