func TestInit_2(t *testing.T) { // Reset the args os.Args = os.Args[:2] os.Args = append(os.Args, "cmd", "arg1") // Init cli var cli = gocli.Cli{ Name: "test", Version: "1.0.0", Description: "test desc", Commands: map[string]string{ "cmd": "Test command", }, } cli.Init() if cli.SubCommand != "cmd" { t.Error("invalid SubCommand") } if len(cli.SubCommandArgs) != 1 { t.Error("invalid SubCommandArgs") } if cli.SubCommandArgs[0] != "arg1" { t.Error("invalid SubCommandArgs arg") } }
func ExampleF_PrintUsage() { // Init cli var cli = gocli.Cli{ Name: "test", Version: "1.0.0", Description: "test desc", Commands: map[string]string{ "cmd": "Test command", }, } cli.Init() cli.PrintUsage() // Output: // Usage: test [OPTIONS] COMMAND [arg...] // // test desc // // Options: // --arg : Arg flag (default "test") // -h, --help : Display usage // -v, --version : Display version information // // Commands: // cmd : Test command }
func ExampleF_PrintVersionExtra() { var cli = gocli.Cli{ Version: "1.0.0", } cli.Init() cli.PrintVersion(true) }
func ExampleF_PrintVersion() { var cli = gocli.Cli{ Version: "1.0.0", } cli.Init() cli.PrintVersion(false) // Output: 1.0.0 }
func TestInit_1(t *testing.T) { // Reset the args os.Args = os.Args[:2] // Init cli var cli = gocli.Cli{ Name: "test", Version: "1.0.0", Description: "test desc", Commands: map[string]string{ "cmd": "Test command", }, } cli.Init() if cli.Name != "test" { t.Error("invalid Name") } if cli.Version != "1.0.0" { t.Error("invalid Version") } if cli.Description != "test desc" { t.Error("invalid Description") } if len(cli.Commands) != 1 { t.Error("invalid Commands") } if cli.Commands["cmd"] != "Test command" { t.Error("invalid Commands") } if cli.SubCommand != "" { t.Error("invalid SubCommand") } if len(cli.SubCommandArgs) > 0 { t.Error("invalid SubCommandArgs") } }