This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 738d39ef06167c8f4657f2eb92586741bb1c9ea7
Author: Gaelle Fournier <[email protected]>
AuthorDate: Thu Dec 8 12:11:08 2022 +0100

    feat(cli): Update Kamel bind step index in properties to start at 1 instead 
of 0
    
    fix #2586
---
 pkg/cmd/bind.go      | 5 +++--
 pkg/cmd/bind_test.go | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/pkg/cmd/bind.go b/pkg/cmd/bind.go
index a5d4a3826..06150e61f 100644
--- a/pkg/cmd/bind.go
+++ b/pkg/cmd/bind.go
@@ -56,7 +56,7 @@ func newCmdBind(rootCmdOptions *RootCmdOptions) 
(*cobra.Command, *bindCmdOptions
        cmd.Flags().String("error-handler", "", `Add error handler 
(none|log|sink:<endpoint>). Sink endpoints are expected in the format 
"[[apigroup/]version:]kind:[namespace/]name", plain Camel URIs or Kamelet 
name.`)
        cmd.Flags().String("name", "", "Name for the binding")
        cmd.Flags().StringP("output", "o", "", "Output format. One of: 
json|yaml")
-       cmd.Flags().StringArrayP("property", "p", nil, `Add a binding property 
in the form of "source.<key>=<value>", "sink.<key>=<value>", 
"error-handler.<key>=<value>" or "step-<n>.<key>=<value>"`)
+       cmd.Flags().StringArrayP("property", "p", nil, `Add a binding property 
in the form of "source.<key>=<value>", "sink.<key>=<value>", 
"error-handler.<key>=<value>" or "step-<n>.<key>=<value> where <n> is the step 
order starting from 1"`)
        cmd.Flags().Bool("skip-checks", false, "Do not verify the binding for 
compliance with Kamelets and other Kubernetes resources")
        cmd.Flags().StringArray("step", nil, `Add binding steps as Kubernetes 
resources. Endpoints are expected in the format 
"[[apigroup/]version:]kind:[namespace/]name", plain Camel URIs or Kamelet 
name.`)
        cmd.Flags().StringArrayP("trait", "t", nil, `Add a trait to the 
corresponding Integration.`)
@@ -210,7 +210,8 @@ func (o *bindCmdOptions) run(cmd *cobra.Command, args 
[]string) error {
        if len(o.Steps) > 0 {
                binding.Spec.Steps = make([]v1alpha1.Endpoint, 0)
                for idx, stepDesc := range o.Steps {
-                       stepKey := fmt.Sprintf("%s%d", stepKeyPrefix, idx)
+                       stepIndex := idx + 1
+                       stepKey := fmt.Sprintf("%s%d", stepKeyPrefix, stepIndex)
                        step, err := o.decode(stepDesc, stepKey)
                        if err != nil {
                                return err
diff --git a/pkg/cmd/bind_test.go b/pkg/cmd/bind_test.go
index 9d263b784..a2729784a 100644
--- a/pkg/cmd/bind_test.go
+++ b/pkg/cmd/bind_test.go
@@ -206,8 +206,8 @@ func TestBindSteps(t *testing.T) {
        buildCmdOptions, bindCmd, _ := initializeBindCmdOptions(t)
        output, err := test.ExecuteCommand(bindCmd, cmdBind, "my:src", 
"my:dst", "-o", "yaml",
                "--step", "dst:step1", "--step", "src:step2",
-               "-p", "step-0.var1=my-step1-var1", "-p", 
"step-0.var2=my-step1-var2",
-               "-p", "step-1.var1=my-step2-var1", "-p", 
"step-1.var2=my-step2-var2")
+               "-p", "step-1.var1=my-step1-var1", "-p", 
"step-1.var2=my-step1-var2",
+               "-p", "step-2.var1=my-step2-var1", "-p", 
"step-2.var2=my-step2-var2")
        assert.Equal(t, "yaml", buildCmdOptions.OutputFormat)
 
        assert.Nil(t, err)

Reply via email to