Updated help command to add in examples and more details

This commit is contained in:
deniseschannon 2016-08-11 21:51:54 -07:00
parent e49cbd5f96
commit e297b3892a
18 changed files with 131 additions and 85 deletions

View File

@ -16,9 +16,11 @@ func CatalogCommand() cli.Command {
Flags: []cli.Flag{},
Subcommands: []cli.Command{
cli.Command{
Name: "ls",
Usage: "List catalog templates",
Action: catalogLs,
Name: "ls",
Usage: "List catalog templates",
Description: "\nList all catalog templates in the current $RANCHER_ENVIRONMENT. Use `--env <envID>` or `--env <envName>` to select a different environment.\n\nExample:\n\t$ rancher --env k8slab catalog ls\n",
ArgsUsage: "None",
Action: catalogLs,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "quiet,q",
@ -34,12 +36,15 @@ func CatalogCommand() cli.Command {
Name: "install",
Usage: "Install catalog template",
Action: errorWrapper(catalogInstall),
ArgsUsage: "[ID or NAME]"
Flags: []cli.Flag{},
},
cli.Command{
Name: "upgrade",
Usage: "Upgrade catalog template",
Action: errorWrapper(envUpdate),
ArgsUsage: "[ID or NAME]"
Flags: []cli.Flag{},
},
*/
},

View File

@ -87,9 +87,10 @@ func LoadConfig(path string) (Config, error) {
func ConfigCommand() cli.Command {
return cli.Command{
Name: "config",
Usage: "Setup client configuration",
Action: errorWrapper(configSetup),
Name: "config",
Usage: "Setup client configuration",
Action: errorWrapper(configSetup),
ArgsUsage: "None",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "dump",

View File

@ -15,10 +15,11 @@ import (
func DockerCommand() cli.Command {
return cli.Command{
Name: "docker",
Usage: "Run docker CLI on a host",
Action: hostDocker,
Flags: []cli.Flag{},
Name: "docker",
Usage: "Run docker CLI on a host",
Description: "\nUses the $RANCHER_DOCKER_HOST to run docker commands. Use `--host <hostID>` or `--host <hostName>` to select a different host.\n\nExample:\n\t$ rancher --host 1h1 docker ps\n",
Action: hostDocker,
Flags: []cli.Flag{},
}
}

View File

@ -17,9 +17,11 @@ func EnvCommand() cli.Command {
Action: defaultAction(envLs),
Subcommands: []cli.Command{
cli.Command{
Name: "ls",
Usage: "List environments",
Action: errorWrapper(envLs),
Name: "ls",
Usage: "List environments",
Description: "\nExample:\n\t$ rancher env ls\n",
ArgsUsage: "None",
Action: errorWrapper(envLs),
Flags: []cli.Flag{
cli.BoolFlag{
Name: "quiet,q",
@ -32,9 +34,11 @@ func EnvCommand() cli.Command {
},
},
cli.Command{
Name: "create",
Usage: "Create an environment",
Action: errorWrapper(envCreate),
Name: "create",
Usage: "Create an environment",
Description: "\nBy default, an environment with cattle orchestration framework will be created.\n\nExample:\n\t$ rancher env create newEnv\n\t$ rancher env create -o kubernetes newK8sEnv\n\t$ rancher env create -o mesos newMesosEnv\n\t$ rancher env create -o swarm newSwarmEnv\n",
ArgsUsage: "[NEWENVNAME...]",
Action: errorWrapper(envCreate),
Flags: []cli.Flag{
cli.StringFlag{
Name: "orchestration,o",
@ -43,15 +47,19 @@ func EnvCommand() cli.Command {
},
},
cli.Command{
Name: "rm",
Usage: "Remove environment(s) by ID",
Action: errorWrapper(envRm),
Flags: []cli.Flag{},
Name: "rm",
Usage: "Remove environment(s) by ID",
Description: "\nExample:\n\t$ rancher env rm 1a5\n",
ArgsUsage: "[ENVID...]",
Action: errorWrapper(envRm),
Flags: []cli.Flag{},
},
cli.Command{
Name: "update",
Usage: "Update environment",
Action: errorWrapper(envUpdate),
Name: "update",
Usage: "Update environment",
Description: "\nChange the orchestration framework of the environment.\n\nExample:\n\t$ rancher env update -o kubernetes 1a5\n",
ArgsUsage: "[ENVID ENVNAME...]",
Action: errorWrapper(envUpdate),
Flags: []cli.Flag{
cli.StringFlag{
Name: "orchestration,o",
@ -143,7 +151,7 @@ func envUpdate(ctx *cli.Context) error {
return err
}
fmt.Println(env.Id)
fmt.Println(env.Name + " (" + env.Id + ")")
return nil
}
@ -169,7 +177,7 @@ func envCreate(ctx *cli.Context) error {
return err
}
fmt.Println(newEnv.Id)
fmt.Println(newEnv.Name + " (" + newEnv.Id + ")")
return nil
}

View File

@ -11,9 +11,11 @@ import (
func EventsCommand() cli.Command {
return cli.Command{
Name: "events",
Usage: "Displays resource change events",
Action: events,
Name: "events",
Usage: "Displays resource change events",
Description: "\nOnly events that are actively occuring in Rancher are listed.\n",
ArgsUsage: "None",
Action: events,
Flags: []cli.Flag{
//cli.StringFlag{
// Name: "format",

View File

@ -11,9 +11,11 @@ import (
func ExportCommand() cli.Command {
return cli.Command{
Name: "export",
Usage: "Export configuration yml for a service",
Action: exportService,
Name: "export",
Usage: "Export configuration yml for a stack",
Description: "\nExports the docker-compose.yml and rancher-compose.yml for the specified stack.\n\nExample:\n\t$ rancher export mystack\n",
ArgsUsage: "[STACKNAME...]",
Action: exportService,
Flags: []cli.Flag{
cli.StringFlag{
Name: "output,o",

View File

@ -13,9 +13,11 @@ func HostCommand() cli.Command {
Action: defaultAction(hostLs),
Subcommands: []cli.Command{
cli.Command{
Name: "ls",
Usage: "List hosts",
Action: errorWrapper(hostLs),
Name: "ls",
Usage: "List hosts",
Description: "\nLists all hosts in the current $RANCHER_ENVIRONMENT. Use `--env <envID>` or `--env <envName>` to select a different environment.\n\nExample:\n\t$ rancher hosts ls\n\t$ rancher --env 1a5 hosts ls\n",
ArgsUsage: "None",
Action: errorWrapper(hostLs),
Flags: []cli.Flag{
cli.BoolFlag{
Name: "quiet,q",
@ -30,6 +32,8 @@ func HostCommand() cli.Command {
cli.Command{
Name: "create",
Usage: "Create a host",
Description: "\nCreates a host in the $RANCHER_ENVIRONMENT. Use `--env <envID>` or `--env <envName>` to select a different environment.\n\nExample:\n\t$ rancher --env k8slab host create newHostName\n",
ArgsUsage: "[NEWHOSTNAME...]",
SkipFlagParsing: true,
Action: errorWrapper(hostCreate),
},

View File

@ -23,10 +23,12 @@ var loggerFactory = logger.NewColorLoggerFactory()
func LogsCommand() cli.Command {
return cli.Command{
Name: "logs",
Usage: "Fetch the logs of a container",
HideHelp: true,
Action: logsCommand,
Name: "logs",
Usage: "Fetch the logs of a container",
Description: "\nExample:\n\t$ rancher logs web\n",
ArgsUsage: "[CONTAINERNAME CONTAINERID...]",
HideHelp: true,
Action: logsCommand,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "follow,f",

View File

@ -10,9 +10,11 @@ import (
func PsCommand() cli.Command {
return cli.Command{
Name: "ps",
Usage: "Show services/containers",
Action: servicePs,
Name: "ps",
Usage: "Show services/containers",
Description: "\nLists all services or containers in the current $RANCHER_ENVIRONMENT. Use `--env <envID>` or `--env <envName>` to select a different environment.\n\nExample:\n\t$ rancher ps\n\t$ rancher ps -c\n\t$ rancher --env 1a5 ps\n",
ArgsUsage: "None",
Action: servicePs,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "containers,c",

View File

@ -14,9 +14,11 @@ var (
func RestartCommand() cli.Command {
return cli.Command{
Name: "restart",
Usage: "Restart " + strings.Join(restartTypes, ", "),
Action: restartResources,
Name: "restart",
Usage: "Restart " + strings.Join(restartTypes, ", "),
Description: "\nRestart resources by ID or name in the current $RANCHER_ENVIRONMENT. Use `--env <envID>` or `--env <envName>` to select a different environment.\n\nExample:\n\t$ rancher restart 1s70\n\t$ rancher --env 1a5 restart stackName/serviceName \n",
ArgsUsage: "[ID NAME...]",
Action: restartResources,
Flags: []cli.Flag{
cli.StringSliceFlag{
Name: "type",

View File

@ -12,9 +12,11 @@ var (
func RmCommand() cli.Command {
return cli.Command{
Name: "rm",
Usage: "Delete resources",
Action: deleteResources,
Name: "rm",
Usage: "Delete resources",
Description: "\nDeletes resources by ID or name in the current $RANCHER_ENVIRONMENT. Use `--env <envID>` or `--env <envName>` to select a different environment.\n\nExample:\n\t$ rancher rm 1s70\n\t$ rancher --env 1a5 rm stackName/serviceName \n",
ArgsUsage: "[ID NAME...]",
Action: deleteResources,
Flags: []cli.Flag{
cli.StringSliceFlag{
Name: "type",

View File

@ -11,9 +11,11 @@ import (
func ScaleCommand() cli.Command {
return cli.Command{
Name: "scale",
Usage: "Scale a service",
Action: serviceScale,
Name: "scale",
Usage: "Set number of containers to run for a service",
Action: serviceScale,
Description: "\nNumbers are specified in the form `service=num` as arguments.\n\nExample:\n\t$ rancher scale web=2 worker=3\n",
ArgsUsage: "[SERVICE=NUM...]",
}
}

View File

@ -18,10 +18,12 @@ import (
func SSHCommand() cli.Command {
return cli.Command{
Name: "ssh",
Usage: "SSH into host",
Action: hostSSH,
Flags: []cli.Flag{},
Name: "ssh",
Usage: "SSH into host",
Description: "\nFor any hosts created through Rancher using docker-machine, you can SSH into the host. This is not supported for any custom hosts. If the host is not in the current $RANCHER_ENVIRONMENT, use `--env <envID>` or `--env <envName>` to select a different environment.\n\nExample:\n\t$ rancher ssh 1h1\n\t$ rancher --env 1a5 ssh 1h5\n",
ArgsUsage: "[HOSTID HOSTNAME...]",
Action: hostSSH,
Flags: []cli.Flag{},
}
}

View File

@ -12,15 +12,24 @@ func StackCommand() cli.Command {
Name: "stacks",
ShortName: "stack",
Usage: "Operations on stacks",
Action: stackLs,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "quiet,q",
Usage: "Only display IDs",
},
cli.StringFlag{
Name: "format",
Usage: "'json' or Custom format: {{.Id}} {{.Name}}",
Action: defaultAction(stackLs),
Subcommands: []cli.Command{
cli.Command{
Name: "ls",
Usage: "List stacks",
Description: "\nLists all stacks in the current $RANCHER_ENVIRONMENT. Use `--env <envID>` or `--env <envName>` to select a different environment.\n\nExample:\n\t$ rancher stacks ls\n\t$ rancher --env 1a5 stacks ls\n",
ArgsUsage: "None",
Action: stackLs,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "quiet,q",
Usage: "Only display IDs",
},
cli.StringFlag{
Name: "format",
Usage: "'json' or Custom format: {{.Id}} {{.Name}}",
},
},
},
},
}

View File

@ -13,10 +13,12 @@ var (
func StartCommand() cli.Command {
return cli.Command{
Name: "start",
ShortName: "activate",
Usage: "Start or activate " + strings.Join(startTypes, ", "),
Action: startResources,
Name: "start",
ShortName: "activate",
Usage: "Start or activate " + strings.Join(startTypes, ", "),
Description: "\nStart resources by ID or name in the current $RANCHER_ENVIRONMENT. Use `--env <envID>` or `--env <envName>` to select a different environment.\n\nExample:\n\t$ rancher start 1s70\n\t$ rancher --env 1a5 start stackName/serviceName \n",
ArgsUsage: "[ID NAME...]",
Action: startResources,
Flags: []cli.Flag{
cli.StringSliceFlag{
Name: "type",

View File

@ -13,10 +13,12 @@ var (
func StopCommand() cli.Command {
return cli.Command{
Name: "stop",
ShortName: "deactivate",
Usage: "Stop or deactivate " + strings.Join(stopTypes, ", "),
Action: stopResources,
Name: "stop",
ShortName: "deactivate",
Usage: "Stop or deactivate " + strings.Join(stopTypes, ", "),
Description: "\nStop resources by ID or name in the current $RANCHER_ENVIRONMENT. Use `--env <envID>` or `--env <envName>` to select a different environment.\n\nExample:\n\t$ rancher stop 1s70\n\t$ rancher --env 1a5 stop stackName/serviceName \n",
ArgsUsage: "[ID NAME...]",
Action: stopResources,
Flags: []cli.Flag{
cli.StringSliceFlag{
Name: "type",

View File

@ -17,10 +17,11 @@ var (
func WaitCommand() cli.Command {
return cli.Command{
Name: "wait",
Usage: "Wait for resources",
Action: waitForResources,
Flags: []cli.Flag{},
Name: "wait",
Usage: "Wait for resources " + strings.Join(waitTypes, ", "),
ArgsUsage: "[ID NAME...]",
Action: waitForResources,
Flags: []cli.Flag{},
}
}

17
main.go
View File

@ -10,9 +10,9 @@ import (
var VERSION = "dev"
var AppHelpTemplate = `Usage: {{.Name}} {{if .Flags}}[OPTIONS] {{end}}COMMAND [arg...]
var AppHelpTemplate = `{{.Usage}}
{{.Usage}}
Usage: {{.Name}} {{if .Flags}}[OPTIONS] {{end}}COMMAND [arg...]
Version: {{.Version}}
{{if .Flags}}
@ -25,15 +25,12 @@ Commands:
Run '{{.Name}} COMMAND --help' for more information on a command.
`
var CommandHelpTemplate = `Usage: rancher [global options] {{.Name}}{{if .Flags}} [OPTIONS]{{end}} [arg...]
var CommandHelpTemplate = `{{.Usage}}
{{if .Description}}{{.Description}}{{end}}
Usage: rancher [global options] {{.Name}} {{if .Flags}}[OPTIONS] {{end}}{{if ne "None" .ArgsUsage}}{{if ne "" .ArgsUsage}}{{.ArgsUsage}}{{else}}[arg...]{{end}}{{end}}
{{.Usage}}{{if .Description}}
Description:
{{.Description}}{{end}}{{if .Flags}}
Options:{{range .Flags}}
{{.}}{{end}}{{ end }}
{{if .Flags}}Options:{{range .Flags}}
{{.}}{{end}}{{end}}
`
func main() {