From 0821008e945d0fa84c54136a18272a3b2fe3bf1a Mon Sep 17 00:00:00 2001 From: Guilherme Carvalho Date: Wed, 21 Dec 2022 11:13:34 -0300 Subject: [PATCH 1/2] Add default value to output format flag description Signed-off-by: Guilherme Carvalho --- cmd/spire-server/cli/agent/agent_posix_test.go | 10 +++++----- cmd/spire-server/cli/agent/agent_windows_test.go | 10 +++++----- cmd/spire-server/cli/bundle/bundle_posix_test.go | 10 +++++----- cmd/spire-server/cli/bundle/bundle_windows_test.go | 10 +++++----- cmd/spire-server/cli/entry/util_posix_test.go | 10 +++++----- cmd/spire-server/cli/entry/util_windows_test.go | 10 +++++----- cmd/spire-server/cli/federation/util_posix_test.go | 12 ++++++------ cmd/spire-server/cli/federation/util_windows_test.go | 12 ++++++------ pkg/common/cliprinter/flag.go | 4 +++- 9 files changed, 45 insertions(+), 43 deletions(-) diff --git a/cmd/spire-server/cli/agent/agent_posix_test.go b/cmd/spire-server/cli/agent/agent_posix_test.go index b6275c7ecc..c80fdb0081 100644 --- a/cmd/spire-server/cli/agent/agent_posix_test.go +++ b/cmd/spire-server/cli/agent/agent_posix_test.go @@ -8,7 +8,7 @@ var ( -matchSelectorsOn string The match mode used when filtering by selectors. Options: exact, any, superset and subset (default "superset") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -selector value A colon-delimited type:value selector. Can be used more than once -socketPath string @@ -16,7 +16,7 @@ var ( ` banUsage = `Usage of agent ban: -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -socketPath string Path to the SPIRE Server API socket (default "/tmp/spire-server/private/api.sock") -spiffeID string @@ -24,7 +24,7 @@ var ( ` evictUsage = `Usage of agent evict: -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -socketPath string Path to the SPIRE Server API socket (default "/tmp/spire-server/private/api.sock") -spiffeID string @@ -32,13 +32,13 @@ var ( ` countUsage = `Usage of agent count: -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -socketPath string Path to the SPIRE Server API socket (default "/tmp/spire-server/private/api.sock") ` showUsage = `Usage of agent show: -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -socketPath string Path to the SPIRE Server API socket (default "/tmp/spire-server/private/api.sock") -spiffeID string diff --git a/cmd/spire-server/cli/agent/agent_windows_test.go b/cmd/spire-server/cli/agent/agent_windows_test.go index bb1fc856c2..4b63d02443 100644 --- a/cmd/spire-server/cli/agent/agent_windows_test.go +++ b/cmd/spire-server/cli/agent/agent_windows_test.go @@ -10,7 +10,7 @@ var ( -namedPipeName string Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -selector value A colon-delimited type:value selector. Can be used more than once ` @@ -18,7 +18,7 @@ var ( -namedPipeName string Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -spiffeID string The SPIFFE ID of the agent to ban (agent identity) ` @@ -26,7 +26,7 @@ var ( -namedPipeName string Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -spiffeID string The SPIFFE ID of the agent to evict (agent identity) ` @@ -34,13 +34,13 @@ var ( -namedPipeName string Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. ` showUsage = `Usage of agent show: -namedPipeName string Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -spiffeID string The SPIFFE ID of the agent to show (agent identity) ` diff --git a/cmd/spire-server/cli/bundle/bundle_posix_test.go b/cmd/spire-server/cli/bundle/bundle_posix_test.go index 9bcaefd90e..ab18144c65 100644 --- a/cmd/spire-server/cli/bundle/bundle_posix_test.go +++ b/cmd/spire-server/cli/bundle/bundle_posix_test.go @@ -10,7 +10,7 @@ var ( -id string SPIFFE ID of the trust domain -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -path string Path to the bundle data -socketPath string @@ -18,7 +18,7 @@ var ( ` countUsage = `Usage of bundle count: -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -socketPath string Path to the SPIRE Server API socket (default "/tmp/spire-server/private/api.sock") ` @@ -28,7 +28,7 @@ var ( -mode string Deletion mode: one of restrict, delete, or dissociate (default "restrict") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -socketPath string Path to the SPIRE Server API socket (default "/tmp/spire-server/private/api.sock") ` @@ -38,7 +38,7 @@ var ( -id string SPIFFE ID of the trust domain -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -socketPath string Path to the SPIRE Server API socket (default "/tmp/spire-server/private/api.sock") ` @@ -46,7 +46,7 @@ var ( -format string The format to show the bundle (only pretty output format supports this flag). Either "pem" or "spiffe". (default "pem") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -socketPath string Path to the SPIRE Server API socket (default "/tmp/spire-server/private/api.sock") ` diff --git a/cmd/spire-server/cli/bundle/bundle_windows_test.go b/cmd/spire-server/cli/bundle/bundle_windows_test.go index 6f5d235f5d..c1e002f24d 100644 --- a/cmd/spire-server/cli/bundle/bundle_windows_test.go +++ b/cmd/spire-server/cli/bundle/bundle_windows_test.go @@ -12,7 +12,7 @@ var ( -namedPipeName string Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -path string Path to the bundle data ` @@ -22,13 +22,13 @@ var ( -namedPipeName string Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. ` countUsage = `Usage of bundle count: -namedPipeName string Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. ` listUsage = `Usage of bundle list: -format string @@ -38,7 +38,7 @@ var ( -namedPipeName string Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. ` deleteUsage = `Usage of bundle delete: -id string @@ -48,6 +48,6 @@ var ( -namedPipeName string Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. ` ) diff --git a/cmd/spire-server/cli/entry/util_posix_test.go b/cmd/spire-server/cli/entry/util_posix_test.go index d055fc2d77..f010b04de4 100644 --- a/cmd/spire-server/cli/entry/util_posix_test.go +++ b/cmd/spire-server/cli/entry/util_posix_test.go @@ -22,7 +22,7 @@ const ( -node If set, this entry will be applied to matching nodes rather than workloads -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -parentID string The SPIFFE ID of this record's parent -selector value @@ -50,7 +50,7 @@ const ( -matchSelectorsOn string The match mode used when filtering by selectors. Options: exact, any, superset and subset (default "superset") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -parentID string The Parent ID of the records to show -selector value @@ -78,7 +78,7 @@ const ( -jwtSVIDTTL int The lifetime, in seconds, for JWT-SVIDs issued based on this registration entry. Overrides ttl flag -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -parentID string The SPIFFE ID of this record's parent -selector value @@ -98,13 +98,13 @@ const ( -entryID string The Registration Entry ID of the record to delete -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -socketPath string Path to the SPIRE Server API socket (default "/tmp/spire-server/private/api.sock") ` countUsage = `Usage of entry count: -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -socketPath string Path to the SPIRE Server API socket (default "/tmp/spire-server/private/api.sock") ` diff --git a/cmd/spire-server/cli/entry/util_windows_test.go b/cmd/spire-server/cli/entry/util_windows_test.go index 945f0d354c..0f11661160 100644 --- a/cmd/spire-server/cli/entry/util_windows_test.go +++ b/cmd/spire-server/cli/entry/util_windows_test.go @@ -24,7 +24,7 @@ const ( -node If set, this entry will be applied to matching nodes rather than workloads -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -parentID string The SPIFFE ID of this record's parent -selector value @@ -52,7 +52,7 @@ const ( -namedPipeName string Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -parentID string The Parent ID of the records to show -selector value @@ -80,7 +80,7 @@ const ( -namedPipeName string Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -parentID string The SPIFFE ID of this record's parent -selector value @@ -100,12 +100,12 @@ const ( -namedPipeName string Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. ` countUsage = `Usage of entry count: -namedPipeName string Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. ` ) diff --git a/cmd/spire-server/cli/federation/util_posix_test.go b/cmd/spire-server/cli/federation/util_posix_test.go index d26d60c545..61549af1be 100644 --- a/cmd/spire-server/cli/federation/util_posix_test.go +++ b/cmd/spire-server/cli/federation/util_posix_test.go @@ -14,7 +14,7 @@ const ( -endpointSpiffeID string SPIFFE ID of the SPIFFE bundle endpoint server. Only used for 'spiffe' profile. -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -socketPath string Path to the SPIRE Server API socket (default "/tmp/spire-server/private/api.sock") -trustDomain string @@ -28,13 +28,13 @@ const ( -id string SPIFFE ID of the trust domain -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -socketPath string Path to the SPIRE Server API socket (default "/tmp/spire-server/private/api.sock") ` listUsage = `Usage of federation list: -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -socketPath string Path to the SPIRE Server API socket (default "/tmp/spire-server/private/api.sock") ` @@ -42,13 +42,13 @@ const ( -id string SPIFFE ID of the trust domain -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -socketPath string Path to the SPIRE Server API socket (default "/tmp/spire-server/private/api.sock") ` showUsage = `Usage of federation show: -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -socketPath string Path to the SPIRE Server API socket (default "/tmp/spire-server/private/api.sock") -trustDomain string @@ -64,7 +64,7 @@ const ( -endpointSpiffeID string SPIFFE ID of the SPIFFE bundle endpoint server. Only used for 'spiffe' profile. -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -socketPath string Path to the SPIRE Server API socket (default "/tmp/spire-server/private/api.sock") -trustDomain string diff --git a/cmd/spire-server/cli/federation/util_windows_test.go b/cmd/spire-server/cli/federation/util_windows_test.go index aa190f0344..3a694743dc 100644 --- a/cmd/spire-server/cli/federation/util_windows_test.go +++ b/cmd/spire-server/cli/federation/util_windows_test.go @@ -16,7 +16,7 @@ const ( -namedPipeName string Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -trustDomain string Name of the trust domain to federate with (e.g., example.org) -trustDomainBundleFormat string @@ -30,13 +30,13 @@ const ( -namedPipeName string Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. ` listUsage = `Usage of federation list: -namedPipeName string Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. ` refreshUsage = `Usage of federation refresh: -id string @@ -44,13 +44,13 @@ const ( -namedPipeName string Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. ` showUsage = `Usage of federation show: -namedPipeName string Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -trustDomain string The trust domain name of the federation relationship to show ` @@ -66,7 +66,7 @@ const ( -namedPipeName string Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") -output value - Desired output format (pretty, json) + Desired output format (pretty, json); default: pretty. -trustDomain string Name of the trust domain to federate with (e.g., example.org) -trustDomainBundleFormat string diff --git a/pkg/common/cliprinter/flag.go b/pkg/common/cliprinter/flag.go index 5711cc60e9..7224d69846 100644 --- a/pkg/common/cliprinter/flag.go +++ b/pkg/common/cliprinter/flag.go @@ -34,7 +34,9 @@ func AppendFlagWithCustomPretty(p *Printer, fs *flag.FlagSet, env *commoncli.Env customPretty: cp, } - fs.Var(f, defaultFlagName, "Desired output format (pretty, json)") + fs.Var(f, + defaultFlagName, + fmt.Sprintf("Desired output format (pretty, json); default: %s.", formatTypeToStr(defaultFormatType))) return f } From 14b43b1d193b3502f841a867a670a3d4af8c6062 Mon Sep 17 00:00:00 2001 From: Guilherme Carvalho Date: Wed, 21 Dec 2022 11:26:26 -0300 Subject: [PATCH 2/2] Isolate flag description into a var Signed-off-by: Guilherme Carvalho --- pkg/common/cliprinter/flag.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/common/cliprinter/flag.go b/pkg/common/cliprinter/flag.go index 7224d69846..fc4cf741b1 100644 --- a/pkg/common/cliprinter/flag.go +++ b/pkg/common/cliprinter/flag.go @@ -10,6 +10,13 @@ import ( const defaultFlagName = "output" +var flagDescription = fmt.Sprintf( + "Desired output format (%s, %s); default: %s.", + formatTypeToStr(pretty), + formatTypeToStr(json), + formatTypeToStr(defaultFormatType), +) + // AppendFlag adds the -format flag to the provided flagset, and populates // the referenced Printer interface with a properly configured printer. func AppendFlag(p *Printer, fs *flag.FlagSet, env *commoncli.Env) *FormatterFlag { @@ -34,9 +41,7 @@ func AppendFlagWithCustomPretty(p *Printer, fs *flag.FlagSet, env *commoncli.Env customPretty: cp, } - fs.Var(f, - defaultFlagName, - fmt.Sprintf("Desired output format (pretty, json); default: %s.", formatTypeToStr(defaultFormatType))) + fs.Var(f, defaultFlagName, flagDescription) return f }