This is an automated email from the ASF dual-hosted git repository. astefanutti pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit b9dbe12e7d8d1e058bbdc796aebea87b29ac5e38 Author: Pasquale Congiusti <[email protected]> AuthorDate: Tue Jun 1 16:04:41 2021 +0200 feat(cmd/run): --resource filename compatibility Adding backward compatibility and a deprecation notice. Ref #2003 --- pkg/cmd/run.go | 2 +- pkg/cmd/run_help.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index 69fcfe8..9d8a0fe 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -544,7 +544,7 @@ func (o *runCmdOptions) updateIntegrationCode(c client.Client, sources []string, } for _, resource := range o.Resources { - if config, parseErr := ParseConfigOption(resource); parseErr == nil { + if config, parseErr := ParseResourceOption(resource); parseErr == nil { if applyResourceOptionErr := ApplyResourceOption(config, &integration.Spec, c, namespace, o.Compression); applyResourceOptionErr != nil { return nil, applyResourceOptionErr } diff --git a/pkg/cmd/run_help.go b/pkg/cmd/run_help.go index 927d7b8..ca36a91 100644 --- a/pkg/cmd/run_help.go +++ b/pkg/cmd/run_help.go @@ -22,6 +22,7 @@ import ( "fmt" "path" "regexp" + "strings" v1 "github.com/apache/camel-k/pkg/apis/camel/v1" "github.com/apache/camel-k/pkg/client" @@ -54,8 +55,27 @@ func newRunConfigOption(configType configOptionType, value string) *RunConfigOpt } } +// ParseResourceOption will parse and return a runConfigOption +func ParseResourceOption(item string) (*RunConfigOption, error) { + // Deprecated: ensure backward compatibility with `--resource filename` format until version 1.5.x + // then replace with parseOption() func directly + option, err := parseOption(item) + if err != nil { + if strings.HasPrefix(err.Error(), "could not match configuration") { + fmt.Printf("Warn: --resource %s has been deprecated. You should use --resource file:%s instead.\n", item, item) + return newRunConfigOption(ConfigOptionTypeFile, item), nil + } + return nil, err + } + return option, nil +} + // ParseConfigOption will parse and return a runConfigOption func ParseConfigOption(item string) (*RunConfigOption, error) { + return parseOption(item) +} + +func parseOption(item string) (*RunConfigOption, error) { if !validConfigRegexp.MatchString(item) { return nil, fmt.Errorf("could not match configuration %s, must match %v regular expression", item, validConfigRegexp) }
