mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-09 09:17:27 +00:00
unify parsing errors
Signed-off-by: h3nryc0ding <hr.richterhenry@gmail.com>
This commit is contained in:
parent
de7e9ff619
commit
64739b4019
16 changed files with 38 additions and 32 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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, please specify the Git provider name, available options are: (generic|azure)"),
|
||||
},
|
||||
{
|
||||
name: "source with no provider",
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -56,5 +56,5 @@ func (a *CRDsPolicy) Type() string {
|
|||
}
|
||||
|
||||
func (a *CRDsPolicy) Description() string {
|
||||
return fmt.Sprintf("upgrade CRDs policy, available options are: (%s)", strings.Join(supportedCRDsPolicies, ", "))
|
||||
return fmt.Sprintf("upgrade CRDs policy, available options are: (%s)", a.Type())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -50,5 +50,5 @@ func (d *DecryptionProvider) Type() string {
|
|||
}
|
||||
|
||||
func (d *DecryptionProvider) Description() string {
|
||||
return fmt.Sprintf("decryption provider, available options are: (%s)", strings.Join(supportedDecryptionProviders, ", "))
|
||||
return fmt.Sprintf("decryption provider, available options are: (%s)", d.Type())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ 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 {
|
||||
|
|
@ -53,7 +53,7 @@ func (c *ECDSACurve) Type() string {
|
|||
}
|
||||
|
||||
func (c *ECDSACurve) Description() string {
|
||||
return fmt.Sprintf("SSH ECDSA public key curve (%s)", strings.Join(ecdsaCurves(), ", "))
|
||||
return fmt.Sprintf("SSH ECDSA public key curve, available options are: (%s)", c.Type())
|
||||
}
|
||||
|
||||
func ecdsaCurves() []string {
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ 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
|
||||
|
|
@ -66,5 +66,8 @@ func (d *GitLabVisibility) Type() string {
|
|||
}
|
||||
|
||||
func (d *GitLabVisibility) Description() string {
|
||||
return fmt.Sprintf("specifies the visibility of the repository. Valid values are public, private, internal")
|
||||
return fmt.Sprintf(
|
||||
"specifies the visibility of the repository, available options are: (%s)",
|
||||
d.Type(),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -71,6 +71,6 @@ func (s *HelmChartSource) Description() string {
|
|||
return fmt.Sprintf(
|
||||
"source that contains the chart in the format '<kind>/<name>.<namespace>', "+
|
||||
"where kind must be one of: (%s)",
|
||||
strings.Join(supportedHelmChartSourceKinds, ", "),
|
||||
s.Type(),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -78,6 +78,6 @@ func (s *KustomizationSource) Description() string {
|
|||
return fmt.Sprintf(
|
||||
"source that contains the Kubernetes manifests in the format '[<kind>/]<name>.<namespace>', "+
|
||||
"where kind must be one of: (%s), if kind is not specified it defaults to GitRepository",
|
||||
strings.Join(supportedKustomizationSourceKinds, ", "),
|
||||
s.Type(),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -65,6 +65,6 @@ func (s *LocalHelmChartSource) Description() string {
|
|||
return fmt.Sprintf(
|
||||
"source that contains the chart in the format '<kind>/<name>', "+
|
||||
"where kind must be one of: (%s)",
|
||||
strings.Join(supportedHelmChartSourceKinds, ", "),
|
||||
s.Type(),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -50,5 +50,5 @@ func (l *LogLevel) Type() string {
|
|||
}
|
||||
|
||||
func (l *LogLevel) Description() string {
|
||||
return fmt.Sprintf("log level, available options are: (%s)", strings.Join(supportedLogLevels, ", "))
|
||||
return fmt.Sprintf("log level, available options are: (%s)", l.Type())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,7 +41,7 @@ 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 {
|
||||
|
|
@ -49,5 +49,5 @@ func (a *PublicKeyAlgorithm) Type() string {
|
|||
}
|
||||
|
||||
func (a *PublicKeyAlgorithm) Description() string {
|
||||
return fmt.Sprintf("SSH public key algorithm (%s)", strings.Join(supportedPublicKeyAlgorithms, ", "))
|
||||
return fmt.Sprintf("SSH public key algorithm, available options are: (%s)", a.Type())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ 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
|
||||
|
|
@ -58,6 +58,6 @@ func (p *SourceBucketProvider) Type() string {
|
|||
func (p *SourceBucketProvider) Description() string {
|
||||
return fmt.Sprintf(
|
||||
"the S3 compatible storage provider name, available options are: (%s)",
|
||||
strings.Join(supportedSourceBucketProviders, ", "),
|
||||
p.Type(),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,5 +53,8 @@ func (p *SourceGitProvider) Type() string {
|
|||
}
|
||||
|
||||
func (p *SourceGitProvider) Description() string {
|
||||
return "the Git provider name"
|
||||
return fmt.Sprintf(
|
||||
"the Git provider name, available options are: (%s)",
|
||||
p.Type(),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ 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
|
||||
|
|
@ -65,7 +65,7 @@ func (p *SourceOCIProvider) Type() string {
|
|||
func (p *SourceOCIProvider) Description() string {
|
||||
return fmt.Sprintf(
|
||||
"the OCI provider name, available options are: (%s)",
|
||||
strings.Join(supportedSourceOCIProviders, ", "),
|
||||
p.Type(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ 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
|
||||
|
|
@ -53,6 +53,6 @@ func (p *SourceOCIVerifyProvider) Type() string {
|
|||
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, ", "),
|
||||
p.Type(),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue