From f78e8a7dab214cab3b74fc435b38886602bedb97 Mon Sep 17 00:00:00 2001 From: George Hartzell Date: Tue, 27 Oct 2015 17:51:34 -0700 Subject: [PATCH] Special case Ansible use cases 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 --- main.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/main.go b/main.go index 263dee8..f00131d 100644 --- a/main.go +++ b/main.go @@ -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{