diff --git a/cmd/flux/create_helmrelease_test.go b/cmd/flux/create_helmrelease_test.go index ffdef081d0..d5d76d3668 100644 --- a/cmd/flux/create_helmrelease_test.go +++ b/cmd/flux/create_helmrelease_test.go @@ -45,7 +45,7 @@ func TestCreateHelmRelease(t *testing.T) { { name: "unknown source kind", args: "create helmrelease podinfo --source foobar/podinfo --chart podinfo --export", - assert: assertError(`invalid argument "foobar/podinfo" for "--source" flag: source kind 'foobar' is not supported, must be one of: HelmRepository, GitRepository, Bucket`), + assert: assertError(`invalid argument "foobar/podinfo" for "--source" flag: source kind 'foobar' is not supported, must be one of: HelmRepository|GitRepository|Bucket`), }, { name: "unknown chart reference kind", diff --git a/cmd/flux/create_source_chart_test.go b/cmd/flux/create_source_chart_test.go index 9566708636..87d0e3fd78 100644 --- a/cmd/flux/create_source_chart_test.go +++ b/cmd/flux/create_source_chart_test.go @@ -50,7 +50,7 @@ func TestCreateSourceChart(t *testing.T) { { name: "unknown source kind", args: "create source chart podinfo --source foobar/podinfo --export", - assert: assertError(`invalid argument "foobar/podinfo" for "--source" flag: source kind 'foobar' is not supported, must be one of: HelmRepository, GitRepository, Bucket`), + assert: assertError(`invalid argument "foobar/podinfo" for "--source" flag: source kind 'foobar' is not supported, must be one of: HelmRepository|GitRepository|Bucket`), }, { name: "basic chart", diff --git a/cmd/flux/create_source_git_test.go b/cmd/flux/create_source_git_test.go index d2ece63651..a652429cf1 100644 --- a/cmd/flux/create_source_git_test.go +++ b/cmd/flux/create_source_git_test.go @@ -152,7 +152,7 @@ func TestCreateSourceGitExport(t *testing.T) { { name: "source with empty provider", args: "create source git podinfo --namespace=flux-system --url=https://dev.azure.com/foo/bar/_git/podinfo --provider \"\" --branch=test --interval=1m0s --export", - assert: assertError("invalid argument \"\" for \"--provider\" flag: no source Git provider given, please specify the Git provider name"), + assert: assertError("invalid argument \"\" for \"--provider\" flag: no source Git provider given, must be one of: generic|azure"), }, { name: "source with no provider", diff --git a/internal/flags/crds.go b/internal/flags/crds.go index 81f6d604c8..22f1c87757 100644 --- a/internal/flags/crds.go +++ b/internal/flags/crds.go @@ -40,11 +40,11 @@ func (a *CRDsPolicy) String() string { func (a *CRDsPolicy) Set(str string) error { if strings.TrimSpace(str) == "" { return fmt.Errorf("no upgrade CRDs policy given, must be one of: %s", - strings.Join(supportedCRDsPolicies, ", ")) + a.Type()) } if !utils.ContainsItemString(supportedCRDsPolicies, str) { return fmt.Errorf("unsupported upgrade CRDs policy '%s', must be one of: %s", - str, strings.Join(supportedCRDsPolicies, ", ")) + str, a.Type()) } *a = CRDsPolicy(str) @@ -52,9 +52,9 @@ func (a *CRDsPolicy) Set(str string) error { } func (a *CRDsPolicy) Type() string { - return "crds" + return strings.Join(supportedCRDsPolicies, "|") } func (a *CRDsPolicy) Description() string { - return fmt.Sprintf("upgrade CRDs policy, available options are: (%s)", strings.Join(supportedCRDsPolicies, ", ")) + return "upgrade CRDs policy" } diff --git a/internal/flags/decryption_provider.go b/internal/flags/decryption_provider.go index 085340aba7..c92c2d46a5 100644 --- a/internal/flags/decryption_provider.go +++ b/internal/flags/decryption_provider.go @@ -34,11 +34,11 @@ func (d *DecryptionProvider) String() string { func (d *DecryptionProvider) Set(str string) error { if strings.TrimSpace(str) == "" { return fmt.Errorf("no decryption provider given, must be one of: %s", - strings.Join(supportedDecryptionProviders, ", ")) + d.Type()) } if !utils.ContainsItemString(supportedDecryptionProviders, str) { return fmt.Errorf("unsupported decryption provider '%s', must be one of: %s", - str, strings.Join(supportedDecryptionProviders, ", ")) + str, d.Type()) } *d = DecryptionProvider(str) @@ -46,9 +46,9 @@ func (d *DecryptionProvider) Set(str string) error { } func (d *DecryptionProvider) Type() string { - return "decryptionProvider" + return strings.Join(supportedDecryptionProviders, "|") } func (d *DecryptionProvider) Description() string { - return fmt.Sprintf("decryption provider, available options are: (%s)", strings.Join(supportedDecryptionProviders, ", ")) + return "decryption provider" } diff --git a/internal/flags/ecdsa_curve.go b/internal/flags/ecdsa_curve.go index 9be8469bfe..f38e53f2cd 100644 --- a/internal/flags/ecdsa_curve.go +++ b/internal/flags/ecdsa_curve.go @@ -45,15 +45,15 @@ func (c *ECDSACurve) Set(str string) error { *c = ECDSACurve{v} return nil } - return fmt.Errorf("unsupported curve '%s', must be one of: %s", str, strings.Join(ecdsaCurves(), ", ")) + return fmt.Errorf("unsupported curve '%s', must be one of: %s", str, c.Type()) } func (c *ECDSACurve) Type() string { - return "ecdsaCurve" + return strings.Join(ecdsaCurves(), "|") } func (c *ECDSACurve) Description() string { - return fmt.Sprintf("SSH ECDSA public key curve (%s)", strings.Join(ecdsaCurves(), ", ")) + return "SSH ECDSA public key curve" } func ecdsaCurves() []string { diff --git a/internal/flags/gitlab_visibility.go b/internal/flags/gitlab_visibility.go index 924dd898d1..e2b52698e8 100644 --- a/internal/flags/gitlab_visibility.go +++ b/internal/flags/gitlab_visibility.go @@ -18,6 +18,7 @@ package flags import ( "fmt" + "sort" "strings" "github.com/fluxcd/go-git-providers/gitprovider" @@ -51,16 +52,25 @@ func (d *GitLabVisibility) Set(str string) error { } var visibility = gitprovider.RepositoryVisibility(str) if ValidateRepositoryVisibility(visibility) != nil { - return fmt.Errorf("unsupported visibility '%s'", str) + return fmt.Errorf("unsupported visibility '%s', must be one of: %s", str, d.Type()) } *d = GitLabVisibility(visibility) return nil } func (d *GitLabVisibility) Type() string { - return "gitLabVisibility" + return strings.Join(gitLabVisibilities(), "|") } func (d *GitLabVisibility) Description() string { - return fmt.Sprintf("specifies the visibility of the repository. Valid values are public, private, internal") + return "specifies the visibility of the repository" +} + +func gitLabVisibilities() []string { + visibilities := make([]string, 0, len(supportedGitLabVisibilities)) + for visibility := range supportedGitLabVisibilities { + visibilities = append(visibilities, string(visibility)) + } + sort.Strings(visibilities) + return visibilities } diff --git a/internal/flags/helm_chart_source.go b/internal/flags/helm_chart_source.go index 079ca4d3d1..246decee9f 100644 --- a/internal/flags/helm_chart_source.go +++ b/internal/flags/helm_chart_source.go @@ -53,7 +53,7 @@ func (s *HelmChartSource) Set(str string) error { cleanSourceKind, ok := utils.ContainsEqualFoldItemString(supportedHelmChartSourceKinds, sourceKind) if !ok { return fmt.Errorf("source kind '%s' is not supported, must be one of: %s", - sourceKind, strings.Join(supportedHelmChartSourceKinds, ", ")) + sourceKind, s.Type()) } s.Kind = cleanSourceKind @@ -64,13 +64,9 @@ func (s *HelmChartSource) Set(str string) error { } func (s *HelmChartSource) Type() string { - return "helmChartSource" + return strings.Join(supportedHelmChartSourceKinds, "|") } func (s *HelmChartSource) Description() string { - return fmt.Sprintf( - "source that contains the chart in the format '/.', "+ - "where kind must be one of: (%s)", - strings.Join(supportedHelmChartSourceKinds, ", "), - ) + return "source that contains the chart in the format '/.'" } diff --git a/internal/flags/kustomization_source.go b/internal/flags/kustomization_source.go index 4dc124ab76..408371ab50 100644 --- a/internal/flags/kustomization_source.go +++ b/internal/flags/kustomization_source.go @@ -60,7 +60,7 @@ func (s *KustomizationSource) Set(str string) error { cleanSourceKind, ok := utils.ContainsEqualFoldItemString(supportedKustomizationSourceKinds, sourceKind) if !ok { return fmt.Errorf("source kind '%s' is not supported, must be one of: %s", - sourceKind, strings.Join(supportedKustomizationSourceKinds, ", ")) + sourceKind, s.Type()) } s.Kind = cleanSourceKind @@ -71,13 +71,9 @@ func (s *KustomizationSource) Set(str string) error { } func (s *KustomizationSource) Type() string { - return "kustomizationSource" + return strings.Join(supportedKustomizationSourceKinds, "|") } func (s *KustomizationSource) Description() string { - return fmt.Sprintf( - "source that contains the Kubernetes manifests in the format '[/].', "+ - "where kind must be one of: (%s), if kind is not specified it defaults to GitRepository", - strings.Join(supportedKustomizationSourceKinds, ", "), - ) + return "source that contains the Kubernetes manifests in the format '[/].', if kind is not specified it defaults to GitRepository" } diff --git a/internal/flags/local_helm_chart_source.go b/internal/flags/local_helm_chart_source.go index 19d2e5305c..cdf7e6896b 100644 --- a/internal/flags/local_helm_chart_source.go +++ b/internal/flags/local_helm_chart_source.go @@ -48,7 +48,7 @@ func (s *LocalHelmChartSource) Set(str string) error { cleanSourceKind, ok := utils.ContainsEqualFoldItemString(supportedHelmChartSourceKinds, sourceKind) if !ok { return fmt.Errorf("source kind '%s' is not supported, must be one of: %s", - sourceKind, strings.Join(supportedHelmChartSourceKinds, ", ")) + sourceKind, s.Type()) } s.Kind = cleanSourceKind @@ -58,13 +58,9 @@ func (s *LocalHelmChartSource) Set(str string) error { } func (s *LocalHelmChartSource) Type() string { - return "helmChartSource" + return strings.Join(supportedHelmChartSourceKinds, "|") } func (s *LocalHelmChartSource) Description() string { - return fmt.Sprintf( - "source that contains the chart in the format '/', "+ - "where kind must be one of: (%s)", - strings.Join(supportedHelmChartSourceKinds, ", "), - ) + return "source that contains the chart in the format '/'" } diff --git a/internal/flags/log_level.go b/internal/flags/log_level.go index 4101a90296..6464e1961d 100644 --- a/internal/flags/log_level.go +++ b/internal/flags/log_level.go @@ -34,11 +34,11 @@ func (l *LogLevel) String() string { func (l *LogLevel) Set(str string) error { if strings.TrimSpace(str) == "" { return fmt.Errorf("no log level given, must be one of: %s", - strings.Join(supportedLogLevels, ", ")) + l.Type()) } if !utils.ContainsItemString(supportedLogLevels, str) { return fmt.Errorf("unsupported log level '%s', must be one of: %s", - str, strings.Join(supportedLogLevels, ", ")) + str, l.Type()) } *l = LogLevel(str) @@ -46,9 +46,9 @@ func (l *LogLevel) Set(str string) error { } func (l *LogLevel) Type() string { - return "logLevel" + return strings.Join(supportedLogLevels, "|") } func (l *LogLevel) Description() string { - return fmt.Sprintf("log level, available options are: (%s)", strings.Join(supportedLogLevels, ", ")) + return "log level" } diff --git a/internal/flags/public_key_algorithm.go b/internal/flags/public_key_algorithm.go index ed4902a7a5..1bdb70233e 100644 --- a/internal/flags/public_key_algorithm.go +++ b/internal/flags/public_key_algorithm.go @@ -32,7 +32,7 @@ func (a *PublicKeyAlgorithm) String() string { func (a *PublicKeyAlgorithm) Set(str string) error { if strings.TrimSpace(str) == "" { return fmt.Errorf("no public key algorithm given, must be one of: %s", - strings.Join(supportedPublicKeyAlgorithms, ", ")) + a.Type()) } for _, v := range supportedPublicKeyAlgorithms { if str == v { @@ -41,13 +41,13 @@ func (a *PublicKeyAlgorithm) Set(str string) error { } } return fmt.Errorf("unsupported public key algorithm '%s', must be one of: %s", - str, strings.Join(supportedPublicKeyAlgorithms, ", ")) + str, a.Type()) } func (a *PublicKeyAlgorithm) Type() string { - return "publicKeyAlgorithm" + return strings.Join(supportedPublicKeyAlgorithms, "|") } func (a *PublicKeyAlgorithm) Description() string { - return fmt.Sprintf("SSH public key algorithm (%s)", strings.Join(supportedPublicKeyAlgorithms, ", ")) + return "SSH public key algorithm" } diff --git a/internal/flags/rsa_key_bits.go b/internal/flags/rsa_key_bits.go index 716a461771..d8ec7d98f5 100644 --- a/internal/flags/rsa_key_bits.go +++ b/internal/flags/rsa_key_bits.go @@ -50,7 +50,7 @@ func (b *RSAKeyBits) Set(str string) error { } func (b *RSAKeyBits) Type() string { - return "rsaKeyBits" + return "int" } func (b *RSAKeyBits) Description() string { diff --git a/internal/flags/source_bucket_provider.go b/internal/flags/source_bucket_provider.go index bd93b41dfc..e83c3835ef 100644 --- a/internal/flags/source_bucket_provider.go +++ b/internal/flags/source_bucket_provider.go @@ -45,19 +45,16 @@ func (p *SourceBucketProvider) Set(str string) error { } if !utils.ContainsItemString(supportedSourceBucketProviders, str) { return fmt.Errorf("source bucket provider '%s' is not supported, must be one of: %v", - str, strings.Join(supportedSourceBucketProviders, ", ")) + str, p.Type()) } *p = SourceBucketProvider(str) return nil } func (p *SourceBucketProvider) Type() string { - return "sourceBucketProvider" + return strings.Join(supportedSourceBucketProviders, "|") } func (p *SourceBucketProvider) Description() string { - return fmt.Sprintf( - "the S3 compatible storage provider name, available options are: (%s)", - strings.Join(supportedSourceBucketProviders, ", "), - ) + return "the S3 compatible storage provider name" } diff --git a/internal/flags/source_git_provider.go b/internal/flags/source_git_provider.go index 63cec33e91..144b7865df 100644 --- a/internal/flags/source_git_provider.go +++ b/internal/flags/source_git_provider.go @@ -37,8 +37,8 @@ func (p *SourceGitProvider) String() string { func (p *SourceGitProvider) Set(str string) error { if strings.TrimSpace(str) == "" { - return fmt.Errorf("no source Git provider given, please specify %s", - p.Description()) + return fmt.Errorf("no source Git provider given, must be one of: %s", + p.Type()) } if !utils.ContainsItemString(supportedSourceGitProviders, str) { return fmt.Errorf("source Git provider '%s' is not supported, must be one of: %v", diff --git a/internal/flags/source_oci_provider.go b/internal/flags/source_oci_provider.go index 77ff044183..a21c337a93 100644 --- a/internal/flags/source_oci_provider.go +++ b/internal/flags/source_oci_provider.go @@ -52,21 +52,18 @@ func (p *SourceOCIProvider) Set(str string) error { } if !utils.ContainsItemString(supportedSourceOCIProviders, str) { return fmt.Errorf("source OCI provider '%s' is not supported, must be one of: %v", - str, strings.Join(supportedSourceOCIProviders, ", ")) + str, p.Type()) } *p = SourceOCIProvider(str) return nil } func (p *SourceOCIProvider) Type() string { - return "sourceOCIProvider" + return strings.Join(supportedSourceOCIProviders, "|") } func (p *SourceOCIProvider) Description() string { - return fmt.Sprintf( - "the OCI provider name, available options are: (%s)", - strings.Join(supportedSourceOCIProviders, ", "), - ) + return "the OCI provider name" } func (p *SourceOCIProvider) ToOCIProvider() (oci.Provider, error) { diff --git a/internal/flags/source_oci_verify_provider.go b/internal/flags/source_oci_verify_provider.go index acd57a9d2f..b2fdaba4b1 100644 --- a/internal/flags/source_oci_verify_provider.go +++ b/internal/flags/source_oci_verify_provider.go @@ -40,19 +40,16 @@ func (p *SourceOCIVerifyProvider) Set(str string) error { } if !utils.ContainsItemString(supportedSourceOCIVerifyProviders, str) { return fmt.Errorf("source OCI verify provider '%s' is not supported, must be one of: %v", - str, strings.Join(supportedSourceOCIVerifyProviders, ", ")) + str, p.Type()) } *p = SourceOCIVerifyProvider(str) return nil } func (p *SourceOCIVerifyProvider) Type() string { - return "sourceOCIVerifyProvider" + return strings.Join(supportedSourceOCIVerifyProviders, "|") } func (p *SourceOCIVerifyProvider) Description() string { - return fmt.Sprintf( - "the OCI verify provider name to use for signature verification, available options are: (%s)", - strings.Join(supportedSourceOCIVerifyProviders, ", "), - ) + return "the OCI verify provider name to use for signature verification" }