Skip to content

Commit

Permalink
commands: cleanup help and synopsis.
Browse files Browse the repository at this point in the history
* move Help and Synopsis to bottom
* make help and synopsis constants
* make sure all help output is formatted
  • Loading branch information
magiconair committed Oct 17, 2017
1 parent 7ebdb16 commit e4721d1
Show file tree
Hide file tree
Showing 76 changed files with 480 additions and 372 deletions.
27 changes: 15 additions & 12 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type cmd struct {
UI cli.Ui
flags *flag.FlagSet
http *flags.HTTPFlags
usage string
help string
revision string
version string
versionPrerelease string
Expand All @@ -70,15 +70,7 @@ type cmd struct {
func (c *cmd) init() {
c.flags = flag.NewFlagSet("", flag.ContinueOnError)
config.AddFlags(c.flags, &c.flagArgs)
c.usage = flags.Usage(usage, c.flags, nil, nil)
}

func (c *cmd) Synopsis() string {
return "Runs a Consul agent"
}

func (c *cmd) Help() string {
return c.usage
c.help = flags.Usage(help, c.flags, nil, nil)
}

func (c *cmd) Run(args []string) int {
Expand Down Expand Up @@ -499,7 +491,18 @@ func (c *cmd) handleReload(agent *agent.Agent, cfg *config.RuntimeConfig) (*conf
return cfg, errs
}

const usage = `Usage: consul agent [options]
func (c *cmd) Synopsis() string {
return synopsis
}

func (c *cmd) Help() string {
return c.help
}

const synopsis = "Runs a Consul agent"
const help = `
Usage: consul agent [options]
Starts the Consul agent and runs until an interrupt is received. The
agent represents a single node in a cluster.`
agent represents a single node in a cluster.
`
14 changes: 9 additions & 5 deletions command/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ func (c *cmd) Run(args []string) int {
}

func (c *cmd) Synopsis() string {
return "Interact with the catalog"
return synopsis
}

func (c *cmd) Help() string {
s := `Usage: consul catalog <subcommand> [options] [args]
return flags.Usage(help, nil, nil, nil)
}

const synopsis = "Interact with the catalog"
const help = `
Usage: consul catalog <subcommand> [options] [args]
This command has subcommands for interacting with Consul's catalog. The
catalog should not be confused with the agent, although the APIs and
Expand All @@ -41,6 +46,5 @@ func (c *cmd) Help() string {
$ consul catalog services
For more examples, ask for subcommand help or view the documentation.`
return flags.Usage(s, nil, nil, nil)
}
For more examples, ask for subcommand help or view the documentation.
`
2 changes: 1 addition & 1 deletion command/catalog/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import (

func TestCatalogCommand_noTabs(t *testing.T) {
if strings.ContainsRune(New().Help(), '\t') {
t.Fatal("usage has tabs")
t.Fatal("help has tabs")
}
}
15 changes: 9 additions & 6 deletions command/catalog/list/dc/catalog_list_datacenters.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ type cmd struct {
UI cli.Ui
flags *flag.FlagSet
http *flags.HTTPFlags
usage string
help string
}

func (c *cmd) init() {
c.flags = flag.NewFlagSet("", flag.ContinueOnError)
c.http = &flags.HTTPFlags{}
flags.Merge(c.flags, c.http.ClientFlags())
flags.Merge(c.flags, c.http.ServerFlags())
c.usage = flags.Usage(usage, c.flags, c.http.ClientFlags(), c.http.ServerFlags())
c.help = flags.Usage(help, c.flags, c.http.ClientFlags(), c.http.ServerFlags())
}

func (c *cmd) Run(args []string) int {
Expand Down Expand Up @@ -59,14 +59,16 @@ func (c *cmd) Run(args []string) int {
}

func (c *cmd) Synopsis() string {
return "Lists all known datacenters"
return synopsis
}

func (c *cmd) Help() string {
return c.usage
return c.help
}

const usage = `Usage: consul catalog datacenters [options]
const synopsis = "Lists all known datacenters"
const help = `
Usage: consul catalog datacenters [options]
Retrieves the list of all known datacenters. This datacenters are sorted in
ascending order based on the estimated median round trip time from the servers
Expand All @@ -76,4 +78,5 @@ const usage = `Usage: consul catalog datacenters [options]
$ consul catalog datacenters
For a full list of options and examples, please see the Consul documentation.`
For a full list of options and examples, please see the Consul documentation.
`
2 changes: 1 addition & 1 deletion command/catalog/list/dc/catalog_list_datacenters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestCatalogListDatacentersCommand_noTabs(t *testing.T) {
if strings.ContainsRune(New(nil).Help(), '\t') {
t.Fatal("usage has tabs")
t.Fatal("help has tabs")
}
}

Expand Down
28 changes: 15 additions & 13 deletions command/catalog/list/nodes/catalog_list_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type cmd struct {
UI cli.Ui
flags *flag.FlagSet
http *flags.HTTPFlags
usage string
help string

// flags
detailed bool
Expand All @@ -48,8 +48,7 @@ func (c *cmd) init() {
c.http = &flags.HTTPFlags{}
flags.Merge(c.flags, c.http.ClientFlags())
flags.Merge(c.flags, c.http.ServerFlags())

c.usage = flags.Usage(usage, c.flags, c.http.ClientFlags(), c.http.ServerFlags())
c.help = flags.Usage(help, c.flags, c.http.ClientFlags(), c.http.ServerFlags())
}

func (c *cmd) Run(args []string) int {
Expand Down Expand Up @@ -121,14 +120,6 @@ func (c *cmd) Run(args []string) int {
return 0
}

func (c *cmd) Synopsis() string {
return "Lists all nodes in the given datacenter"
}

func (c *cmd) Help() string {
return c.usage
}

// printNodes accepts a list of nodes and prints information in a tabular
// format about the nodes.
func printNodes(nodes []*api.Node, detailed bool) (string, error) {
Expand Down Expand Up @@ -191,7 +182,17 @@ func mapToKV(m map[string]string, joiner string) string {
return strings.Join(r, joiner)
}

const usage = `Usage: consul catalog nodes [options]
func (c *cmd) Synopsis() string {
return synopsis
}

func (c *cmd) Help() string {
return c.help
}

const synopsis = "Lists all nodes in the given datacenter"
const help = `
Usage: consul catalog nodes [options]
Retrieves the list nodes registered in a given datacenter. By default, the
datacenter of the local agent is queried.
Expand All @@ -217,4 +218,5 @@ const usage = `Usage: consul catalog nodes [options]
$ consul catalog nodes -near=node-web
For a full list of options and examples, please see the Consul documentation.`
For a full list of options and examples, please see the Consul documentation.
`
2 changes: 1 addition & 1 deletion command/catalog/list/nodes/catalog_list_nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestCatalogListNodesCommand_noTabs(t *testing.T) {
if strings.ContainsRune(New(nil).Help(), '\t') {
t.Fatal("usage has tabs")
t.Fatal("help has tabs")
}
}

Expand Down
15 changes: 9 additions & 6 deletions command/catalog/list/services/catalog_list_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type cmd struct {
UI cli.Ui
flags *flag.FlagSet
http *flags.HTTPFlags
usage string
help string

// flags
node string
Expand All @@ -46,7 +46,7 @@ func (c *cmd) init() {
c.http = &flags.HTTPFlags{}
flags.Merge(c.flags, c.http.ClientFlags())
flags.Merge(c.flags, c.http.ServerFlags())
c.usage = flags.Usage(usage, c.flags, c.http.ClientFlags(), c.http.ServerFlags())
c.help = flags.Usage(help, c.flags, c.http.ClientFlags(), c.http.ServerFlags())
}

func (c *cmd) Run(args []string) int {
Expand Down Expand Up @@ -126,14 +126,16 @@ func (c *cmd) Run(args []string) int {
}

func (c *cmd) Synopsis() string {
return "Lists all registered services in a datacenter"
return synopsis
}

func (c *cmd) Help() string {
return c.usage
return c.help
}

const usage = `Usage: consul catalog services [options]
const synopsis = "Lists all registered services in a datacenter"
const help = `
Usage: consul catalog services [options]
Retrieves the list services registered in a given datacenter. By default, the
datacenter of the local agent is queried.
Expand All @@ -154,4 +156,5 @@ const usage = `Usage: consul catalog services [options]
$ consul catalog services -node-meta="foo=bar"
For a full list of options and examples, please see the Consul documentation.`
For a full list of options and examples, please see the Consul documentation.
`
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestCatalogListServicesCommand_noTabs(t *testing.T) {
if strings.ContainsRune(New(nil).Help(), '\t') {
t.Fatal("usage has tabs")
t.Fatal("help has tabs")
}
}

Expand Down
15 changes: 9 additions & 6 deletions command/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type cmd struct {
node string
service string
tag string
usage string
help string
}

func (c *cmd) init() {
Expand All @@ -40,7 +40,7 @@ func (c *cmd) init() {

c.http = &flags.HTTPFlags{}
flags.Merge(c.flags, c.http.ClientFlags())
c.usage = flags.Usage(usage, c.flags, c.http.ClientFlags(), nil)
c.help = flags.Usage(help, c.flags, c.http.ClientFlags(), nil)
}

func (c *cmd) Run(args []string) int {
Expand Down Expand Up @@ -129,15 +129,18 @@ func (c *cmd) Run(args []string) int {
}

func (c *cmd) Synopsis() string {
return "Fire a new event"
return synopsis
}

func (c *cmd) Help() string {
return c.usage
return c.help
}

const usage = `Usage: consul event [options] [payload]
const synopsis = "Fire a new event"
const help = `
Usage: consul event [options] [payload]
Dispatches a custom user event across a datacenter. An event must provide
a name, but a payload is optional. Events support filtering using
regular expressions on node name, service, and tag definitions.`
regular expressions on node name, service, and tag definitions.
`
2 changes: 1 addition & 1 deletion command/event/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestEventCommand_noTabs(t *testing.T) {
if strings.ContainsRune(New(nil).Help(), '\t') {
t.Fatal("usage has tabs")
t.Fatal("help has tabs")
}
}

Expand Down
25 changes: 14 additions & 11 deletions command/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type cmd struct {
UI cli.Ui
flags *flag.FlagSet
http *flags.HTTPFlags
usage string
help string

shutdownCh <-chan struct{}
conf rExecConf
Expand Down Expand Up @@ -60,7 +60,7 @@ func (c *cmd) init() {
c.http = &flags.HTTPFlags{}
flags.Merge(c.flags, c.http.ClientFlags())
flags.Merge(c.flags, c.http.ServerFlags())
c.usage = flags.Usage(usage, c.flags, c.http.ClientFlags(), c.http.ServerFlags())
c.help = flags.Usage(help, c.flags, c.http.ClientFlags(), c.http.ServerFlags())
}

func (c *cmd) Run(args []string) int {
Expand Down Expand Up @@ -183,13 +183,23 @@ func (c *cmd) Run(args []string) int {
}

func (c *cmd) Synopsis() string {
return "Executes a command on Consul nodes"
return synopsis
}

func (c *cmd) Help() string {
return c.usage
return c.help
}

const synopsis = "Executes a command on Consul nodes"
const help = `
Usage: consul exec [options] [-|command...]
Evaluates a command on remote Consul nodes. The nodes responding can
be filtered using regular expressions on node name, service, and tag
definitions. If a command is '-', stdin will be read until EOF
and used as a script input.
`

// waitForJob is used to poll for results and wait until the job is terminated
func (c *cmd) waitForJob() int {
// Although the session destroy is already deferred, we do it again here,
Expand Down Expand Up @@ -685,10 +695,3 @@ func (u *TargetedUI) prefixLines(arrow bool, message string) string {

return strings.TrimRightFunc(result.String(), unicode.IsSpace)
}

const usage = `Usage: consul exec [options] [-|command...]
Evaluates a command on remote Consul nodes. The nodes responding can
be filtered using regular expressions on node name, service, and tag
definitions. If a command is '-', stdin will be read until EOF
and used as a script input. `
2 changes: 1 addition & 1 deletion command/exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func TestExecCommand_noTabs(t *testing.T) {
if strings.ContainsRune(New(nil, nil).Help(), '\t') {
t.Fatal("usage has tabs")
t.Fatal("help has tabs")
}
}

Expand Down
Loading

0 comments on commit e4721d1

Please sign in to comment.