command: remove -namespace from help options when not applicable

This commit is contained in:
Tim Gross 2020-11-19 11:15:23 -05:00
parent 0cd73b44e9
commit de6b023af2
94 changed files with 118 additions and 97 deletions

View File

@ -20,7 +20,7 @@ Usage: nomad acl bootstrap [options]
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
`
return strings.TrimSpace(helpText)

View File

@ -23,7 +23,7 @@ Usage: nomad acl policy apply [options] <name> <path>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Apply Options:

View File

@ -19,7 +19,7 @@ Usage: nomad acl policy delete <name>
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace)
return strings.TrimSpace(helpText)
}

View File

@ -19,7 +19,7 @@ Usage: nomad acl policy info <name>
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace)
return strings.TrimSpace(helpText)
}

View File

@ -20,7 +20,7 @@ Usage: nomad acl policy list
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
List Options:

View File

@ -20,7 +20,7 @@ Usage: nomad acl token create [options]
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Create Options:

View File

@ -19,7 +19,7 @@ Usage: nomad acl token delete <token_accessor_id>
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace)
return strings.TrimSpace(helpText)
}

View File

@ -19,7 +19,7 @@ Usage: nomad acl token info <token_accessor_id>
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace)
return strings.TrimSpace(helpText)
}

View File

@ -20,7 +20,7 @@ Usage: nomad acl token list
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
List Options:

View File

@ -19,7 +19,7 @@ Usage: nomad acl token self
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace)
return strings.TrimSpace(helpText)
}

View File

@ -19,7 +19,7 @@ Usage: nomad acl token update <token_accessor_id>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Update Options:

View File

@ -20,7 +20,7 @@ Usage: nomad agent-info [options]
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace)
return strings.TrimSpace(helpText)
}

View File

@ -29,7 +29,7 @@ Usage: nomad monitor [options]
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Monitor Specific Options:

View File

@ -34,7 +34,7 @@ Usage: nomad alloc exec [options] <allocation> <command>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Exec Specific Options:

View File

@ -42,7 +42,7 @@ Alias: nomad fs
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
FS Specific Options:

View File

@ -28,7 +28,7 @@ Alias: nomad logs
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Logs Specific Options:

View File

@ -23,7 +23,7 @@ Usage: nomad alloc restart [options] <allocation> <task>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Restart Specific Options:

View File

@ -23,7 +23,7 @@ Usage: nomad alloc signal [options] <signal> <allocation> <task>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Signal Specific Options:

View File

@ -31,7 +31,7 @@ Usage: nomad alloc status [options] <allocation>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Alloc Status Options:

View File

@ -24,7 +24,7 @@ Alias: nomad stop
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Stop Specific Options:

View File

@ -29,7 +29,7 @@ Usage: nomad check [options]
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Agent Check Options:

View File

@ -23,7 +23,7 @@ Usage: nomad deployment fail [options] <deployment id>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Fail Options:

View File

@ -20,7 +20,7 @@ Usage: nomad deployment list [options]
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
List Options:

View File

@ -21,7 +21,7 @@ Usage: nomad deployment pause [options] <deployment id>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Pause Options:

View File

@ -28,7 +28,7 @@ Usage: nomad deployment promote [options] <deployment id>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Promote Options:

View File

@ -21,7 +21,7 @@ Usage: nomad deployment resume [options] <deployment id>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Resume Options:

View File

@ -24,7 +24,7 @@ Usage: nomad deployment status [options] <deployment id>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Status Options:

View File

@ -21,7 +21,7 @@ Usage: nomad deployment unblock [options] <deployment id>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Unblock Options:

View File

@ -25,7 +25,7 @@ Usage: nomad eval status [options] <evaluation>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Eval Status Options:

View File

@ -16,7 +16,7 @@ Usage: nomad event sink deregister <event sink id>
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault)
return helpText
}

View File

@ -20,7 +20,7 @@ Usage: nomad event sink list
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault)
return helpText
}

View File

@ -25,7 +25,7 @@ Usage: nomad event sink register <path>
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault)
return helpText
}

View File

@ -21,7 +21,7 @@ Usage: nomad job deployments [options] <job>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Deployments Options:
@ -38,7 +38,7 @@ Deployments Options:
Display full information.
-all
Display all deployments matching the job ID, including those
Display all deployments matching the job ID, including those
from an older instance of the job.
`
return strings.TrimSpace(helpText)

View File

@ -30,7 +30,7 @@ Usage: nomad job dispatch [options] <parameterized job> [input source]
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Dispatch Options:

View File

@ -24,7 +24,7 @@ Usage: nomad job eval [options] <job_id>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Eval Options:

View File

@ -28,7 +28,7 @@ Usage: nomad job history [options] <job>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
History Options:

View File

@ -22,7 +22,7 @@ Alias: nomad inspect
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Inspect Options:

View File

@ -22,7 +22,7 @@ Usage: nomad job periodic force <job id>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Periodic Force Options:

View File

@ -65,7 +65,7 @@ Alias: nomad plan
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Plan Options:

View File

@ -29,7 +29,7 @@ Usage: nomad job promote [options] <job id>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Promote Options:

View File

@ -23,7 +23,7 @@ Usage: nomad job revert [options] <job> <version>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Revert Options:
@ -36,8 +36,8 @@ Revert Options:
The Consul token used to verify that the caller has access to the Service
Identity policies associated in the targeted version of the job.
-vault-token
The Vault token used to verify that the caller has access to the Vault
-vault-token
The Vault token used to verify that the caller has access to the Vault
policies in the targeted version of the job.
-verbose

View File

@ -63,7 +63,7 @@ Alias: nomad run
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Run Options:

View File

@ -34,7 +34,7 @@ Usage: nomad job scale [options] <job> [<group>] <count>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Scale Options:

View File

@ -29,7 +29,7 @@ Usage: nomad job scaling-events [options] <args>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Scaling-Events Options:

View File

@ -35,7 +35,7 @@ Usage: nomad status [options] <job>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Status Options:

View File

@ -26,7 +26,7 @@ Alias: nomad stop
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Stop Options:

View File

@ -15,7 +15,7 @@ Usage: nomad license get [options]
Gets a new license in Servers and Clients
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace)
return helpText
}

View File

@ -25,7 +25,7 @@ Puts a new license in Servers and Clients
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Install a new license from a file:

View File

@ -161,8 +161,16 @@ func (m *Meta) Colorize() *colorstring.Colorize {
}
}
type usageOptsFlags uint8
const (
usageOptsDefault usageOptsFlags = 0
usageOptsNoNamespace = 1 << iota
)
// generalOptionsUsage returns the help string for the global options.
func generalOptionsUsage() string {
func generalOptionsUsage(usageOpts usageOptsFlags) string {
helpText := `
-address=<addr>
The address of the Nomad server.
@ -173,14 +181,21 @@ func generalOptionsUsage() string {
The region of the Nomad servers to forward commands to.
Overrides the NOMAD_REGION environment variable if set.
Defaults to the Agent's local region.
`
namespaceText := `
-namespace=<namespace>
The target namespace for queries and actions bound to a namespace.
Overrides the NOMAD_NAMESPACE environment variable if set.
If set to '*', job and alloc subcommands query all namespaces authorized
to user.
Defaults to the "default" namespace.
`
// note: that although very few commands use color explicitly, all of them
// return red-colored text on error so we don't want to make this
// configurable
remainingText := `
-no-color
Disables colored command output. Alternatively, NOMAD_CLI_NO_COLOR may be
set.
@ -218,6 +233,12 @@ func generalOptionsUsage() string {
The SecretID of an ACL token to use to authenticate API requests with.
Overrides the NOMAD_TOKEN environment variable if set.
`
if usageOpts&usageOptsNoNamespace == 0 {
helpText = helpText + namespaceText
}
helpText = helpText + remainingText
return strings.TrimSpace(helpText)
}

View File

@ -19,7 +19,7 @@ Usage: nomad operator metrics [options]
Get Nomad metrics
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Metrics Specific Options

View File

@ -22,7 +22,7 @@ Usage: nomad namespace apply [options] <namespace>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Apply Options:

View File

@ -19,7 +19,7 @@ Usage: nomad namespace delete [options] <namespace>
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace)
return strings.TrimSpace(helpText)
}

View File

@ -19,7 +19,7 @@ Usage: nomad namespace inspect [options] <namespace>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Inspect Options:

View File

@ -21,7 +21,7 @@ Usage: nomad namespace list [options]
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
List Options:

View File

@ -20,7 +20,7 @@ Usage: nomad namespace status [options] <namespace>
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace)
return strings.TrimSpace(helpText)
}

View File

@ -24,7 +24,7 @@ Usage: nomad node config [options]
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Client Config Options:

View File

@ -31,7 +31,7 @@ Usage: nomad node drain [options] <node>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Node Drain Options:

View File

@ -25,7 +25,7 @@ Usage: nomad node eligibility [options] <node>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Node Eligibility Options:

View File

@ -51,7 +51,7 @@ Usage: nomad node status [options] <node>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Node Status Options:

View File

@ -66,7 +66,7 @@ Usage: nomad operator autopilot get-config [options]
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace)
return strings.TrimSpace(helpText)
}

View File

@ -112,7 +112,7 @@ Usage: nomad operator autopilot set-config [options]
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Set Config Options:

View File

@ -57,7 +57,7 @@ Usage: nomad operator debug [options]
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Debug Options:

View File

@ -33,7 +33,7 @@ Usage: nomad operator keyring [options]
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Keyring Options:

View File

@ -21,7 +21,7 @@ Usage: nomad operator raft list-peers [options]
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
List Peers Options:

View File

@ -27,7 +27,7 @@ Usage: nomad operator raft remove-peer [options]
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Remove Peer Options:

View File

@ -34,7 +34,7 @@ Usage: nomad operator snapshot restore [options] <file>
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace)
return strings.TrimSpace(helpText)
}

View File

@ -41,7 +41,7 @@ Usage: nomad operator snapshot save [options] <file>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Snapshot Save Options:

View File

@ -26,7 +26,7 @@ Usage nomad plugin status [options] <plugin>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Status Options:

View File

@ -31,7 +31,7 @@ Usage: nomad quota apply [options] <input>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Apply Options:

View File

@ -19,7 +19,7 @@ Usage: nomad quota delete [options] <quota>
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault)
return strings.TrimSpace(helpText)
}

View File

@ -26,7 +26,7 @@ Usage: nomad quota inspect [options] <quota>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Inspect Options:

View File

@ -21,7 +21,7 @@ Usage: nomad quota list [options]
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
List Options:

View File

@ -23,7 +23,7 @@ Usage: nomad quota status [options] <quota>
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault)
return strings.TrimSpace(helpText)
}

View File

@ -27,7 +27,7 @@ Usage: nomad recommendation apply [options] <recommendation_ids>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Recommendation Apply Options:

View File

@ -48,7 +48,7 @@ Usage: nomad recommendation dismiss [options] <recommendation_ids>
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault)
return strings.TrimSpace(helpText)
}

View File

@ -26,7 +26,7 @@ Usage: nomad recommendation info [options] <recommendation_id>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Recommendation Info Options:

View File

@ -27,7 +27,7 @@ Usage: nomad recommendation list [options]
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Recommendation List Options:

View File

@ -25,7 +25,7 @@ Usage: nomad scaling policy info [options] <policy_id>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Policy Info Options:

View File

@ -27,7 +27,7 @@ Usage: nomad scaling policy list [options]
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Policy Info Options:

View File

@ -24,7 +24,7 @@ Usage: nomad sentinel apply [options] <name> <file>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Apply Options:

View File

@ -19,7 +19,7 @@ Usage: nomad sentinel delete [options] <name>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
`
return strings.TrimSpace(helpText)

View File

@ -19,7 +19,7 @@ Usage: nomad sentinel list [options]
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
`
return strings.TrimSpace(helpText)

View File

@ -19,7 +19,7 @@ Usage: nomad sentinel read [options] <name>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Read Options:

View File

@ -22,7 +22,7 @@ Usage: nomad server force-leave [options] <node>
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace)
return strings.TrimSpace(helpText)
}

View File

@ -23,7 +23,7 @@ Usage: nomad server join [options] <addr> [<addr>...]
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace)
return strings.TrimSpace(helpText)
}

View File

@ -25,7 +25,7 @@ Usage: nomad server members [options]
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
Server Members Options:

View File

@ -26,7 +26,7 @@ Usage: nomad status [options] <identifier>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Status Options:

View File

@ -19,7 +19,7 @@ Usage: nomad system gc [options]
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace)
return strings.TrimSpace(helpText)
}

View File

@ -19,7 +19,7 @@ Usage: nomad system reconcile summaries [options]
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace)
return strings.TrimSpace(helpText)
}

View File

@ -29,7 +29,7 @@ object. Supported identifiers are jobs, allocations and nodes.
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace)
return strings.TrimSpace(helpText)
}

View File

@ -20,7 +20,7 @@ Usage: nomad volume deregister [options] <id>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Volume Deregister Options:

View File

@ -20,7 +20,7 @@ Usage: nomad volume detach [options] <vol id> <node id>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
`
return strings.TrimSpace(helpText)

View File

@ -27,7 +27,7 @@ Usage: nomad volume register [options] <input>
General Options:
` + generalOptionsUsage()
` + generalOptionsUsage(usageOptsDefault)
return strings.TrimSpace(helpText)
}

View File

@ -26,7 +26,7 @@ Usage: nomad volume status [options] <id>
General Options:
` + generalOptionsUsage() + `
` + generalOptionsUsage(usageOptsDefault) + `
Status Options: