Skip to content

Commit

Permalink
help: allow for variants of -h, --help
Browse files Browse the repository at this point in the history
* Fixes rakyll#45 by setting a custom usage function
* Also allows for multiple topics to be selected
on `drive --help/help/-h [topics...]
  • Loading branch information
odeke-em committed Jun 3, 2015
1 parent 2f68a1d commit 1c6438d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
11 changes: 4 additions & 7 deletions cmd/drive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
"strconv"
"strings"

"github.com/odeke-em/command"
"github.com/odeke-em/drive/config"
"github.com/odeke-em/drive/gen"
"github.com/odeke-em/drive/src"
"github.com/rakyll/command"
)

var context *config.Context
Expand Down Expand Up @@ -75,6 +75,8 @@ func main() {
bindCommandWithAliases(drive.DeleteKey, drive.DescDelete, &deleteCmd{}, []string{})
bindCommandWithAliases(drive.UnpubKey, drive.DescUnpublish, &unpublishCmd{}, []string{})
bindCommandWithAliases(drive.VersionKey, drive.Version, &versionCmd{}, []string{})

command.DefineHelp(&helpCmd{})
command.ParseAndRun()
}

Expand All @@ -87,12 +89,7 @@ func (cmd *helpCmd) Flags(fs *flag.FlagSet) *flag.FlagSet {
}

func (cmd *helpCmd) Run(args []string) {
arg := drive.AllKey
if len(args) >= 1 {
arg = args[0]
}

drive.ShowDescription(arg)
drive.ShowDescriptions(args...)
exitWithError(nil)
}

Expand Down
11 changes: 11 additions & 0 deletions src/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ func ShowAllDescriptions() {
}
}

func ShowDescriptions(topics ...string) {
if len(topics) < 1 {
topics = append(topics, AllKey)
}

for _, topic := range topics {
ShowDescription(topic)
fmt.Println()
}
}

func ShowDescription(topic string) {
if topic == AllKey {
ShowAllDescriptions()
Expand Down

0 comments on commit 1c6438d

Please sign in to comment.