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

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


The following commit(s) were added to refs/heads/main by this push:
     new 8448b2dc4 fix(cli): kamel panics when unknown command is passed
8448b2dc4 is described below

commit 8448b2dc473595c0858f9fb3b35240ca7776bd76
Author: Tadayoshi Sato <[email protected]>
AuthorDate: Thu Apr 14 15:38:18 2022 +0900

    fix(cli): kamel panics when unknown command is passed
    
    Fix #3203
    
    createKamelWithModelineCommand() should always return rootCmd instance
    even when it gets err, as its out and err outputs may be used downstream.
---
 pkg/cmd/modeline.go | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/pkg/cmd/modeline.go b/pkg/cmd/modeline.go
index 38b135a58..1b7ed9e1f 100644
--- a/pkg/cmd/modeline.go
+++ b/pkg/cmd/modeline.go
@@ -89,12 +89,12 @@ func NewKamelWithModelineCommand(ctx context.Context, 
osArgs []string) (*cobra.C
 func createKamelWithModelineCommand(ctx context.Context, args []string) 
(*cobra.Command, []string, error) {
        rootCmd, err := NewKamelCommand(ctx)
        if err != nil {
-               return nil, nil, err
+               return rootCmd, nil, err
        }
 
        target, flags, err := rootCmd.Find(args)
        if err != nil {
-               return nil, nil, err
+               return rootCmd, nil, err
        }
 
        isLocalBuild := target.Name() == buildCmdName && target.Parent().Name() 
== localCmdName
@@ -108,7 +108,7 @@ func createKamelWithModelineCommand(ctx context.Context, 
args []string) (*cobra.
        if errors.Is(err, pflag.ErrHelp) {
                return rootCmd, args, nil
        } else if err != nil {
-               return nil, nil, err
+               return rootCmd, nil, err
        }
 
        fg := target.Flags()
@@ -119,7 +119,7 @@ func createKamelWithModelineCommand(ctx context.Context, 
args []string) (*cobra.
        if target.Name() == runCmdName && target.Parent().Name() != 
localCmdName {
                additionalSources, err = fg.GetStringArray(runCmdSourcesArgs)
                if err != nil {
-                       return nil, nil, err
+                       return rootCmd, nil, err
                }
        }
 
@@ -129,7 +129,7 @@ func createKamelWithModelineCommand(ctx context.Context, 
args []string) (*cobra.
 
        opts, err := extractModelineOptions(ctx, files, rootCmd)
        if err != nil {
-               return nil, nil, errors.Wrap(err, "cannot read sources")
+               return rootCmd, nil, errors.Wrap(err, "cannot read sources")
        }
 
        // Extract list of property/trait names already specified by the user.
@@ -184,7 +184,7 @@ func createKamelWithModelineCommand(ctx context.Context, 
args []string) (*cobra.
        // Recreating the command as it's dirty
        rootCmd, err = NewKamelCommand(ctx)
        if err != nil {
-               return nil, nil, err
+               return rootCmd, nil, err
        }
        rootCmd.SetArgs(args)
 

Reply via email to