Skip to content

Commit 64739b4

Browse files
committed
unify parsing errors
Signed-off-by: h3nryc0ding <[email protected]>
1 parent de7e9ff commit 64739b4

16 files changed

+38
-32
lines changed

cmd/flux/create_helmrelease_test.go

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 5 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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
}

0 commit comments

Comments
 (0)