astefanutti commented on a change in pull request #3153:
URL: https://github.com/apache/camel-k/pull/3153#discussion_r839259620



##########
File path: pkg/cmd/debug.go
##########
@@ -100,15 +100,15 @@ func (o *debugCmdOptions) run(cmd *cobra.Command, args 
[]string) error {
                        // Context canceled
                        return
                }
-               fmt.Printf("Disabling debug mode on integration %q\n", name)
+               fmt.Fprintf(cmd.OutOrStdout(), "Disabling debug mode on 
integration %q\n", name)

Review comment:
       `Fprintln` can be used here also.

##########
File path: pkg/cmd/describe_kit.go
##########
@@ -81,12 +81,12 @@ func (command *describeKitCommandOptions) run(cmd 
*cobra.Command, args []string)
 
        if err := c.Get(command.Context, kitKey, kit); err == nil {
                if desc, err := command.describeIntegrationKit(cmd, kit); err 
== nil {
-                       fmt.Print(desc)
+                       fmt.Fprint(cmd.OutOrStdout(), desc)
                } else {
-                       fmt.Println(err)
+                       fmt.Fprintln(cmd.ErrOrStderr(), err)
                }
        } else {
-               fmt.Printf("IntegrationKit '%s' does not exist.\n", args[0])
+               fmt.Fprintf(cmd.OutOrStdout(), "IntegrationKit '%s' does not 
exist.\n", args[0])

Review comment:
       `Fprintln` can be used here also.

##########
File path: pkg/cmd/describe_kamelet.go
##########
@@ -82,12 +82,12 @@ func (command *describeKameletCommandOptions) run(cmd 
*cobra.Command, args []str
 
        if err := c.Get(command.Context, kameletKey, &kamelet); err == nil {
                if desc, err := command.describeKamelet(cmd, kamelet); err == 
nil {
-                       fmt.Print(desc)
+                       fmt.Fprint(cmd.OutOrStdout(), desc)
                } else {
-                       fmt.Println(err)
+                       fmt.Fprintln(cmd.ErrOrStderr(), err)
                }
        } else {
-               fmt.Printf("Kamelet '%s' does not exist.\n", args[0])
+               fmt.Fprintf(cmd.OutOrStdout(), "Kamelet '%s' does not 
exist.\n", args[0])

Review comment:
       `Fprintln` can be used here also.

##########
File path: pkg/cmd/kit_create.go
##########
@@ -175,22 +175,22 @@ func (command *kitCreateCommandOptions) run(_ 
*cobra.Command, args []string) err
                existing := v1.NewIntegrationKit(kit.Namespace, kit.Name)
                err = c.Get(command.Context, key, existing)
                if err != nil {
-                       fmt.Print(err.Error())
+                       fmt.Fprint(cmd.ErrOrStderr(), err.Error())
                        return nil
                }
                kit.ResourceVersion = existing.ResourceVersion
                err = c.Update(command.Context, kit)
        }
 
        if err != nil {
-               fmt.Print(err.Error())
+               fmt.Fprint(cmd.ErrOrStderr(), err.Error())
                return nil
        }
 
        if !existed {
-               fmt.Printf("integration kit \"%s\" created\n", kit.Name)
+               fmt.Fprintf(cmd.OutOrStdout(), "integration kit \"%s\" 
created\n", kit.Name)

Review comment:
       `Fprintln` can be used here also.

##########
File path: pkg/cmd/kamelet_delete.go
##########
@@ -139,6 +139,6 @@ func (command *kameletDeleteCommandOptions) delete(name 
string) error {
                }
                return fmt.Errorf("error deleting kamelet \"%s\": %w", name, 
err)
        }
-       fmt.Printf("kamelet \"%s\" has been deleted\n", name)
+       fmt.Fprintf(cmd.OutOrStdout(), "kamelet \"%s\" has been deleted\n", 
name)

Review comment:
       `Fprintln` can be used here also.

##########
File path: pkg/cmd/log.go
##########
@@ -128,8 +128,8 @@ func (o *logCmdOptions) run(cmd *cobra.Command, args 
[]string) error {
                        //
                        // Found the running integration so step over to 
scraping its pod log
                        //
-                       fmt.Printf("Integration '%s' is now running. Showing 
log ...\n", integrationID)
-                       if err := k8slog.Print(o.Context, c, &integration, 
cmd.OutOrStdout()); err != nil {
+                       fmt.Fprintf(cmd.OutOrStdout(), "Integration '%s' is now 
running. Showing log ...\n", integrationID)

Review comment:
       `Fprintln` can be used here also.

##########
File path: pkg/cmd/kit_create.go
##########
@@ -175,22 +175,22 @@ func (command *kitCreateCommandOptions) run(_ 
*cobra.Command, args []string) err
                existing := v1.NewIntegrationKit(kit.Namespace, kit.Name)
                err = c.Get(command.Context, key, existing)
                if err != nil {
-                       fmt.Print(err.Error())
+                       fmt.Fprint(cmd.ErrOrStderr(), err.Error())
                        return nil
                }
                kit.ResourceVersion = existing.ResourceVersion
                err = c.Update(command.Context, kit)
        }
 
        if err != nil {
-               fmt.Print(err.Error())
+               fmt.Fprint(cmd.ErrOrStderr(), err.Error())
                return nil
        }
 
        if !existed {
-               fmt.Printf("integration kit \"%s\" created\n", kit.Name)
+               fmt.Fprintf(cmd.OutOrStdout(), "integration kit \"%s\" 
created\n", kit.Name)
        } else {
-               fmt.Printf("integration kit \"%s\" updated\n", kit.Name)
+               fmt.Fprintf(cmd.OutOrStdout(), "integration kit \"%s\" 
updated\n", kit.Name)

Review comment:
       `Fprintln` can be used here also.

##########
File path: pkg/cmd/kit_delete.go
##########
@@ -144,7 +144,7 @@ func (command *kitDeleteCommandOptions) delete(name string) 
error {
                return fmt.Errorf("no integration kit found with name \"%s\"", 
kit.Name)
        }
 
-       fmt.Printf("integration kit \"%s\" has been deleted\n", kit.Name)
+       fmt.Fprintf(cmd.OutOrStdout(), "integration kit \"%s\" has been 
deleted\n", kit.Name)

Review comment:
       `Fprintln` can be used here also.

##########
File path: pkg/cmd/rebuild.go
##########
@@ -69,7 +69,7 @@ func (o *rebuildCmdOptions) rebuild(_ *cobra.Command, args 
[]string) error {
                return err
        }
 
-       fmt.Printf("%d integrations have been rebuilt\n", len(integrations))
+       fmt.Fprintf(cmd.OutOrStdout(), "%d integrations have been rebuilt\n", 
len(integrations))

Review comment:
       `Fprintln` can be used here also.

##########
File path: pkg/cmd/run.go
##########
@@ -287,10 +287,10 @@ func (o *runCmdOptions) run(cmd *cobra.Command, args 
[]string) error {
                                // Context canceled
                                return
                        }
-                       fmt.Printf("Run integration terminating\n")
+                       fmt.Fprintf(cmd.OutOrStdout(), "Run integration 
terminating\n")

Review comment:
       `Fprintln` can be used here also.

##########
File path: pkg/cmd/uninstall.go
##########
@@ -209,71 +209,71 @@ func (o *uninstallCmdOptions) 
uninstallClusterWideResources(ctx context.Context,
        if !o.SkipClusterRoleBindings || o.UninstallAll {
                if err := o.uninstallClusterRoleBindings(ctx, c); err != nil {
                        if k8serrors.IsForbidden(err) {
-                               return createActionNotAuthorizedError()
+                               return createActionNotAuthorizedError(cmd)
                        }
                        return err
                }
-               fmt.Printf("Camel K Cluster Role Bindings removed from 
cluster\n")
+               fmt.Fprintf(cmd.OutOrStdout(), "Camel K Cluster Role Bindings 
removed from cluster\n")
        }
 
        if !o.SkipClusterRoles || o.UninstallAll {
                if err := o.uninstallClusterRoles(ctx, c); err != nil {
                        if k8serrors.IsForbidden(err) {
-                               return createActionNotAuthorizedError()
+                               return createActionNotAuthorizedError(cmd)
                        }
                        return err
                }
-               fmt.Printf("Camel K Cluster Roles removed from cluster\n")
+               fmt.Fprintf(cmd.OutOrStdout(), "Camel K Cluster Roles removed 
from cluster\n")
        }
 
        return nil
 }
 
-func (o *uninstallCmdOptions) uninstallNamespaceRoles(ctx context.Context, c 
client.Client) error {
+func (o *uninstallCmdOptions) uninstallNamespaceRoles(ctx context.Context, cmd 
*cobra.Command, c client.Client) error {
        if !o.SkipRoleBindings {
                if err := o.uninstallRoleBindings(ctx, c); err != nil {
                        return err
                }
-               fmt.Printf("Camel K Role Bindings removed from namespace %s\n", 
o.Namespace)
+               fmt.Fprintln(cmd.OutOrStdout(), "Camel K Role Bindings removed 
from namespace", o.Namespace)
        }
 
        if !o.SkipRoles {
                if err := o.uninstallRoles(ctx, c); err != nil {
                        return err
                }
-               fmt.Printf("Camel K Roles removed from namespace %s\n", 
o.Namespace)
+               fmt.Fprintln(cmd.OutOrStdout(), "Camel K Roles removed from 
namespace", o.Namespace)
        }
 
        if !o.SkipServiceAccounts {
                if err := o.uninstallServiceAccounts(ctx, c); err != nil {
                        return err
                }
-               fmt.Printf("Camel K Service Accounts removed from namespace 
%s\n", o.Namespace)
+               fmt.Fprintln(cmd.OutOrStdout(), "Camel K Service Accounts 
removed from namespace", o.Namespace)
        }
 
        return nil
 }
 
-func (o *uninstallCmdOptions) uninstallNamespaceResources(ctx context.Context, 
c client.Client) error {
+func (o *uninstallCmdOptions) uninstallNamespaceResources(cmd *cobra.Command, 
ctx context.Context, c client.Client) error {

Review comment:
       The `ctx` argument should be declared in first position.

##########
File path: pkg/cmd/modeline.go
##########
@@ -71,7 +71,7 @@ func NewKamelWithModelineCommand(ctx context.Context, osArgs 
[]string) (*cobra.C
        originalFlags := osArgs[1:]
        rootCmd, flags, err := createKamelWithModelineCommand(ctx, 
originalFlags)
        if err != nil {
-               fmt.Printf("Error: %s\n", err.Error())
+               fmt.Fprintf(rootCmd.ErrOrStderr(), "Error: %s\n", err.Error())

Review comment:
       `Fprintln` can be used here also.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to