Skip to content

Commit

Permalink
Add IsHidden flag (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg authored Dec 31, 2021
1 parent b8e458a commit 884e67f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions acmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ type Command struct {

// subcommands of the command.
Subcommands []Command

// IsHidden reports whether command should not be show in help. Default false.
IsHidden bool
}

// Config for the runner.
Expand Down Expand Up @@ -297,6 +300,9 @@ func printCommands(w io.Writer, cmds []Command) {
minwidth, tabwidth, padding, padchar, flags := 0, 0, 11, byte(' '), uint(0)
tw := tabwriter.NewWriter(w, minwidth, tabwidth, padding, padchar, flags)
for _, cmd := range cmds {
if cmd.IsHidden {
continue
}
desc := cmd.Description
if desc == "" {
desc = "<no description>"
Expand Down
21 changes: 21 additions & 0 deletions acmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,24 @@ func TestRunner_suggestCommand(t *testing.T) {
}
}
}

func TestCommand_IsHidden(t *testing.T) {
buf := &bytes.Buffer{}
cmds := []Command{
{Name: "for", Do: nopFunc},
{Name: "foo", Do: nopFunc, IsHidden: true},
{Name: "bar", Do: nopFunc},
}
r := RunnerOf(cmds, Config{
Args: []string{"help"},
AppName: "ci",
Output: buf,
})
if err := r.Run(); err != nil {
t.Fatal(err)
}

if strings.Contains(buf.String(), "foo") {
t.Fatal("should not show foo")
}
}

0 comments on commit 884e67f

Please sign in to comment.