Skip to content

Commit

Permalink
Special case Ansible use cases
Browse files Browse the repository at this point in the history
Special case `roster --list` and `roster --host hostname`.  I tried
doing this by making inventory the default command, but the way that cli
implemented you can't do '--host hostname', it tries to make 'hostname'
a subcommand and fails. See: mitchellh/cli#24
  • Loading branch information
George Hartzell committed Oct 28, 2015
1 parent 5329674 commit f78e8a7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ func main() {
}

func doIt(ui cli.Ui, args []string) (int, error) {

// special case `roster --list` and `roster --host hostname`. I
// tried doing this by making inventory the default command, but the
// way that cli implemented you can't do '--host hostname', it tries
// to make 'hostname' a subcommand and fails. See:
// https://github.com/mitchellh/cli/issues/24
//
if (len(args) == 1 && args[0] == "--list") ||
(len(args) == 2 && args[0] == "--host") {
command, err := CmdInventoryFactory(ui)()
if err != nil {
return 1, err
}
return command.Run(args), nil
}

c := cli.NewCLI("roster", "0.0.1")
c.Args = args
c.Commands = map[string]cli.CommandFactory{
Expand Down

0 comments on commit f78e8a7

Please sign in to comment.