Skip to content

Commit 4acb77b

Browse files
committed
unify parsing errors
1 parent f294490 commit 4acb77b

16 files changed

+38
-32
lines changed

cmd/flux/create_helmrelease_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestCreateHelmRelease(t *testing.T) {
4545
{
4646
name: "unknown source kind",
4747
args: "create helmrelease podinfo --source foobar/podinfo --chart podinfo --export",
48-
assert: assertError(`invalid argument "foobar/podinfo" for "--source" flag: source kind 'foobar' is not supported, must be one of: HelmRepository, GitRepository, Bucket`),
48+
assert: assertError(`invalid argument "foobar/podinfo" for "--source" flag: source kind 'foobar' is not supported, must be one of: HelmRepository|GitRepository|Bucket`),
4949
},
5050
{
5151
name: "unknown chart reference kind",

cmd/flux/create_source_chart_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestCreateSourceChart(t *testing.T) {
5050
{
5151
name: "unknown source kind",
5252
args: "create source chart podinfo --source foobar/podinfo --export",
53-
assert: assertError(`invalid argument "foobar/podinfo" for "--source" flag: source kind 'foobar' is not supported, must be one of: HelmRepository, GitRepository, Bucket`),
53+
assert: assertError(`invalid argument "foobar/podinfo" for "--source" flag: source kind 'foobar' is not supported, must be one of: HelmRepository|GitRepository|Bucket`),
5454
},
5555
{
5656
name: "basic chart",

cmd/flux/create_source_git_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func TestCreateSourceGitExport(t *testing.T) {
152152
{
153153
name: "source with empty provider",
154154
args: "create source git podinfo --namespace=flux-system --url=https://dev.azure.com/foo/bar/_git/podinfo --provider \"\" --branch=test --interval=1m0s --export",
155-
assert: assertError("invalid argument \"\" for \"--provider\" flag: no source Git provider given, please specify the Git provider name"),
155+
assert: assertError("invalid argument \"\" for \"--provider\" flag: no source Git provider given, please specify the Git provider name, available options are: (generic|azure)"),
156156
},
157157
{
158158
name: "source with no provider",

internal/flags/crds.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ func (a *CRDsPolicy) String() string {
4040
func (a *CRDsPolicy) Set(str string) error {
4141
if strings.TrimSpace(str) == "" {
4242
return fmt.Errorf("no upgrade CRDs policy given, must be one of: %s",
43-
strings.Join(supportedCRDsPolicies, ", "))
43+
a.Type())
4444
}
4545
if !utils.ContainsItemString(supportedCRDsPolicies, str) {
4646
return fmt.Errorf("unsupported upgrade CRDs policy '%s', must be one of: %s",
47-
str, strings.Join(supportedCRDsPolicies, ", "))
47+
str, a.Type())
4848

4949
}
5050
*a = CRDsPolicy(str)
@@ -56,5 +56,5 @@ func (a *CRDsPolicy) Type() string {
5656
}
5757

5858
func (a *CRDsPolicy) Description() string {
59-
return fmt.Sprintf("upgrade CRDs policy, available options are: (%s)", strings.Join(supportedCRDsPolicies, ", "))
59+
return fmt.Sprintf("upgrade CRDs policy, available options are: (%s)", a.Type())
6060
}

internal/flags/decryption_provider.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ func (d *DecryptionProvider) String() string {
3434
func (d *DecryptionProvider) Set(str string) error {
3535
if strings.TrimSpace(str) == "" {
3636
return fmt.Errorf("no decryption provider given, must be one of: %s",
37-
strings.Join(supportedDecryptionProviders, ", "))
37+
d.Type())
3838
}
3939
if !utils.ContainsItemString(supportedDecryptionProviders, str) {
4040
return fmt.Errorf("unsupported decryption provider '%s', must be one of: %s",
41-
str, strings.Join(supportedDecryptionProviders, ", "))
41+
str, d.Type())
4242

4343
}
4444
*d = DecryptionProvider(str)
@@ -50,5 +50,5 @@ func (d *DecryptionProvider) Type() string {
5050
}
5151

5252
func (d *DecryptionProvider) Description() string {
53-
return fmt.Sprintf("decryption provider, available options are: (%s)", strings.Join(supportedDecryptionProviders, ", "))
53+
return fmt.Sprintf("decryption provider, available options are: (%s)", d.Type())
5454
}

internal/flags/ecdsa_curve.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ func (c *ECDSACurve) Set(str string) error {
4545
*c = ECDSACurve{v}
4646
return nil
4747
}
48-
return fmt.Errorf("unsupported curve '%s', must be one of: %s", str, strings.Join(ecdsaCurves(), ", "))
48+
return fmt.Errorf("unsupported curve '%s', must be one of: %s", str, c.Type())
4949
}
5050

5151
func (c *ECDSACurve) Type() string {
5252
return strings.Join(ecdsaCurves(), "|")
5353
}
5454

5555
func (c *ECDSACurve) Description() string {
56-
return fmt.Sprintf("SSH ECDSA public key curve (%s)", strings.Join(ecdsaCurves(), ", "))
56+
return fmt.Sprintf("SSH ECDSA public key curve, available options are: (%s)", c.Type())
5757
}
5858

5959
func ecdsaCurves() []string {

internal/flags/gitlab_visibility.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (d *GitLabVisibility) Set(str string) error {
5151
}
5252
var visibility = gitprovider.RepositoryVisibility(str)
5353
if ValidateRepositoryVisibility(visibility) != nil {
54-
return fmt.Errorf("unsupported visibility '%s'", str)
54+
return fmt.Errorf("unsupported visibility '%s', must be one of: %s", str, d.Type())
5555
}
5656
*d = GitLabVisibility(visibility)
5757
return nil
@@ -66,5 +66,8 @@ func (d *GitLabVisibility) Type() string {
6666
}
6767

6868
func (d *GitLabVisibility) Description() string {
69-
return fmt.Sprintf("specifies the visibility of the repository. Valid values are public, private, internal")
69+
return fmt.Sprintf(
70+
"specifies the visibility of the repository, available options are: (%s)",
71+
d.Type(),
72+
)
7073
}

internal/flags/helm_chart_source.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (s *HelmChartSource) Set(str string) error {
5353
cleanSourceKind, ok := utils.ContainsEqualFoldItemString(supportedHelmChartSourceKinds, sourceKind)
5454
if !ok {
5555
return fmt.Errorf("source kind '%s' is not supported, must be one of: %s",
56-
sourceKind, strings.Join(supportedHelmChartSourceKinds, ", "))
56+
sourceKind, s.Type())
5757
}
5858

5959
s.Kind = cleanSourceKind
@@ -71,6 +71,6 @@ func (s *HelmChartSource) Description() string {
7171
return fmt.Sprintf(
7272
"source that contains the chart in the format '<kind>/<name>.<namespace>', "+
7373
"where kind must be one of: (%s)",
74-
strings.Join(supportedHelmChartSourceKinds, ", "),
74+
s.Type(),
7575
)
7676
}

internal/flags/kustomization_source.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (s *KustomizationSource) Set(str string) error {
6060
cleanSourceKind, ok := utils.ContainsEqualFoldItemString(supportedKustomizationSourceKinds, sourceKind)
6161
if !ok {
6262
return fmt.Errorf("source kind '%s' is not supported, must be one of: %s",
63-
sourceKind, strings.Join(supportedKustomizationSourceKinds, ", "))
63+
sourceKind, s.Type())
6464
}
6565

6666
s.Kind = cleanSourceKind
@@ -78,6 +78,6 @@ func (s *KustomizationSource) Description() string {
7878
return fmt.Sprintf(
7979
"source that contains the Kubernetes manifests in the format '[<kind>/]<name>.<namespace>', "+
8080
"where kind must be one of: (%s), if kind is not specified it defaults to GitRepository",
81-
strings.Join(supportedKustomizationSourceKinds, ", "),
81+
s.Type(),
8282
)
8383
}

internal/flags/local_helm_chart_source.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (s *LocalHelmChartSource) Set(str string) error {
4848
cleanSourceKind, ok := utils.ContainsEqualFoldItemString(supportedHelmChartSourceKinds, sourceKind)
4949
if !ok {
5050
return fmt.Errorf("source kind '%s' is not supported, must be one of: %s",
51-
sourceKind, strings.Join(supportedHelmChartSourceKinds, ", "))
51+
sourceKind, s.Type())
5252
}
5353

5454
s.Kind = cleanSourceKind
@@ -65,6 +65,6 @@ func (s *LocalHelmChartSource) Description() string {
6565
return fmt.Sprintf(
6666
"source that contains the chart in the format '<kind>/<name>', "+
6767
"where kind must be one of: (%s)",
68-
strings.Join(supportedHelmChartSourceKinds, ", "),
68+
s.Type(),
6969
)
7070
}

internal/flags/log_level.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ func (l *LogLevel) String() string {
3434
func (l *LogLevel) Set(str string) error {
3535
if strings.TrimSpace(str) == "" {
3636
return fmt.Errorf("no log level given, must be one of: %s",
37-
strings.Join(supportedLogLevels, ", "))
37+
l.Type())
3838
}
3939
if !utils.ContainsItemString(supportedLogLevels, str) {
4040
return fmt.Errorf("unsupported log level '%s', must be one of: %s",
41-
str, strings.Join(supportedLogLevels, ", "))
41+
str, l.Type())
4242

4343
}
4444
*l = LogLevel(str)
@@ -50,5 +50,5 @@ func (l *LogLevel) Type() string {
5050
}
5151

5252
func (l *LogLevel) Description() string {
53-
return fmt.Sprintf("log level, available options are: (%s)", strings.Join(supportedLogLevels, ", "))
53+
return fmt.Sprintf("log level, available options are: (%s)", l.Type())
5454
}

internal/flags/public_key_algorithm.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (a *PublicKeyAlgorithm) String() string {
3232
func (a *PublicKeyAlgorithm) Set(str string) error {
3333
if strings.TrimSpace(str) == "" {
3434
return fmt.Errorf("no public key algorithm given, must be one of: %s",
35-
strings.Join(supportedPublicKeyAlgorithms, ", "))
35+
a.Type())
3636
}
3737
for _, v := range supportedPublicKeyAlgorithms {
3838
if str == v {
@@ -41,13 +41,13 @@ func (a *PublicKeyAlgorithm) Set(str string) error {
4141
}
4242
}
4343
return fmt.Errorf("unsupported public key algorithm '%s', must be one of: %s",
44-
str, strings.Join(supportedPublicKeyAlgorithms, ", "))
44+
str, a.Type())
4545
}
4646

4747
func (a *PublicKeyAlgorithm) Type() string {
4848
return strings.Join(supportedPublicKeyAlgorithms, "|")
4949
}
5050

5151
func (a *PublicKeyAlgorithm) Description() string {
52-
return fmt.Sprintf("SSH public key algorithm (%s)", strings.Join(supportedPublicKeyAlgorithms, ", "))
52+
return fmt.Sprintf("SSH public key algorithm, available options are: (%s)", a.Type())
5353
}

internal/flags/source_bucket_provider.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (p *SourceBucketProvider) Set(str string) error {
4545
}
4646
if !utils.ContainsItemString(supportedSourceBucketProviders, str) {
4747
return fmt.Errorf("source bucket provider '%s' is not supported, must be one of: %v",
48-
str, strings.Join(supportedSourceBucketProviders, ", "))
48+
str, p.Type())
4949
}
5050
*p = SourceBucketProvider(str)
5151
return nil
@@ -58,6 +58,6 @@ func (p *SourceBucketProvider) Type() string {
5858
func (p *SourceBucketProvider) Description() string {
5959
return fmt.Sprintf(
6060
"the S3 compatible storage provider name, available options are: (%s)",
61-
strings.Join(supportedSourceBucketProviders, ", "),
61+
p.Type(),
6262
)
6363
}

internal/flags/source_git_provider.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,8 @@ func (p *SourceGitProvider) Type() string {
5353
}
5454

5555
func (p *SourceGitProvider) Description() string {
56-
return "the Git provider name"
56+
return fmt.Sprintf(
57+
"the Git provider name, available options are: (%s)",
58+
p.Type(),
59+
)
5760
}

internal/flags/source_oci_provider.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (p *SourceOCIProvider) Set(str string) error {
5252
}
5353
if !utils.ContainsItemString(supportedSourceOCIProviders, str) {
5454
return fmt.Errorf("source OCI provider '%s' is not supported, must be one of: %v",
55-
str, strings.Join(supportedSourceOCIProviders, ", "))
55+
str, p.Type())
5656
}
5757
*p = SourceOCIProvider(str)
5858
return nil
@@ -65,7 +65,7 @@ func (p *SourceOCIProvider) Type() string {
6565
func (p *SourceOCIProvider) Description() string {
6666
return fmt.Sprintf(
6767
"the OCI provider name, available options are: (%s)",
68-
strings.Join(supportedSourceOCIProviders, ", "),
68+
p.Type(),
6969
)
7070
}
7171

internal/flags/source_oci_verify_provider.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (p *SourceOCIVerifyProvider) Set(str string) error {
4040
}
4141
if !utils.ContainsItemString(supportedSourceOCIVerifyProviders, str) {
4242
return fmt.Errorf("source OCI verify provider '%s' is not supported, must be one of: %v",
43-
str, strings.Join(supportedSourceOCIVerifyProviders, ", "))
43+
str, p.Type())
4444
}
4545
*p = SourceOCIVerifyProvider(str)
4646
return nil
@@ -53,6 +53,6 @@ func (p *SourceOCIVerifyProvider) Type() string {
5353
func (p *SourceOCIVerifyProvider) Description() string {
5454
return fmt.Sprintf(
5555
"the OCI verify provider name to use for signature verification, available options are: (%s)",
56-
strings.Join(supportedSourceOCIVerifyProviders, ", "),
56+
p.Type(),
5757
)
5858
}

0 commit comments

Comments
 (0)