diff --git a/z/cmd.go b/z/cmd.go index f95a5ff..1800594 100644 --- a/z/cmd.go +++ b/z/cmd.go @@ -11,6 +11,7 @@ import ( "strconv" "strings" "text/template" + "unicode" "github.com/rwxrob/bonzai" "github.com/rwxrob/fn/each" @@ -80,10 +81,18 @@ func (s Section) GetTitle() string { return s.Title } func (s Section) GetBody() string { return s.Body } // Names returns the Name and any Aliases grouped such that the Name is -// always last. +// always last. Any alias beginning with anything but a letter (L) is +// omitted. func (x *Cmd) Names() []string { var names []string - names = append(names, x.Aliases...) + for _, a := range x.Aliases { + if len(a) == 0 { + continue + } + if unicode.IsLetter([]rune(a)[0]) { + names = append(names, a) + } + } names = append(names, x.Name) return names } @@ -389,12 +398,16 @@ func (x *Cmd) CmdNames() []string { // UsageCmdTitles returns a single string with the titles of each // subcommand indented and with a maximum title signature length for -// justification. Hidden commands are not included. Note that the order +// justification. Hidden commands are not included. Aliases that begin +// with anything but a letter (L) are not included. Note that the order // of the Commands is preserved (not necessarily alphabetic). func (x *Cmd) UsageCmdTitles() string { var set []string var summaries []string for _, c := range x.Commands { + if x.IsHidden(c.Name) { + continue + } set = append(set, strings.Join(c.Names(), "|")) summaries = append(summaries, c.GetSummary()) } diff --git a/z/cmd_test.go b/z/cmd_test.go index 7bcf55c..1c68200 100644 --- a/z/cmd_test.go +++ b/z/cmd_test.go @@ -144,7 +144,7 @@ func ExampleCmd_Names() { x := &Z.Cmd{ Name: `foo`, - Aliases: []string{"f", "FOO"}, + Aliases: []string{"-f", "@f", "f", "FOO"}, } fmt.Println(x.Names()) @@ -226,6 +226,7 @@ func ExampleCmd_UsageCmdTitles() { x := &Z.Cmd{ Name: `cmd`, Params: []string{"p1", "p2"}, + Hidden: []string{"hidden"}, Commands: []*Z.Cmd{ &Z.Cmd{ Name: "foo", @@ -239,6 +240,10 @@ func ExampleCmd_UsageCmdTitles() { &Z.Cmd{ Name: "nosum", }, + &Z.Cmd{ + Name: "hidden", + Summary: "not listed, but works", + }, }, } fmt.Println(x.UsageCmdTitles())