Skip to content

Commit

Permalink
update rpkg commands to print to correct stream on execution
Browse files Browse the repository at this point in the history
Signed-off-by: Kushal Harish Naidu <kushal.harish.naidu@ericsson.com>
  • Loading branch information
kushnaidu committed Mar 5, 2024
1 parent 29b1884 commit 1eed119
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/cli/commands/rpkg/approve/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (r *runner) runE(_ *cobra.Command, args []string) error {
messages = append(messages, err.Error())
fmt.Fprintf(r.Command.ErrOrStderr(), "%s failed (%s)\n", name, err)
} else {
fmt.Fprintf(r.Command.OutOrStderr(), "%s approved\n", name)
fmt.Fprintf(r.Command.OutOrStdout(), "%s approved\n", name)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/commands/rpkg/get/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (r *runner) runE(cmd *cobra.Command, args []string) error {
if err := w.Flush(); err != nil {
return errors.E(op, err)
}

fmt.Fprintf(cmd.OutOrStdout(), "Package revision deleted successfully\n")

This comment has been minimized.

Copy link
@liamfallon

liamfallon Mar 5, 2024

Collaborator

For the "get", I think the printout is currently returned so you probably don't need this line.

This comment has been minimized.

Copy link
@kushnaidu

kushnaidu Mar 5, 2024

Author

Yes, I made a mistake here in adding it to the get command instead of del.

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/commands/rpkg/propose/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (r *runner) runE(_ *cobra.Command, args []string) error {
messages = append(messages, err.Error())
fmt.Fprintf(r.Command.ErrOrStderr(), "%s failed (%s)\n", name, err)
} else {
fmt.Fprintf(r.Command.OutOrStderr(), "%s proposed\n", name)
fmt.Fprintf(r.Command.OutOrStdout(), "%s proposed\n", name)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/commands/rpkg/proposedelete/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (r *runner) runE(_ *cobra.Command, args []string) error {
messages = append(messages, err.Error())
fmt.Fprintf(r.Command.ErrOrStderr(), "%s failed (%s)\n", name, err)
} else {
fmt.Fprintf(r.Command.OutOrStderr(), "%s proposed for deletion\n", name)
fmt.Fprintf(r.Command.OutOrStdout(), "%s proposed for deletion\n", name)
}
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/cli/commands/rpkg/pull/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package pull

import (
"context"
"fmt"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -96,7 +97,7 @@ func (r *runner) preRunE(_ *cobra.Command, _ []string) error {
return nil
}

func (r *runner) runE(_ *cobra.Command, args []string) error {
func (r *runner) runE(cmd *cobra.Command, args []string) error {
const op errors.Op = command + ".runE"

if len(args) == 0 {
Expand Down Expand Up @@ -126,6 +127,7 @@ func (r *runner) runE(_ *cobra.Command, args []string) error {
return errors.E(op, err)
}
}
fmt.Fprintf(cmd.OutOrStdout(), "Package: %s pulled successfully\n", packageName)
return nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/cli/commands/rpkg/push/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func (r *runner) runE(cmd *cobra.Command, args []string) error {
r.printFnResult(result, printOpt)
}
}
fmt.Fprintf(cmd.OutOrStdout(), "Package: %s pushed successfully\n", packageName)
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/commands/rpkg/reject/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ func (r *runner) runE(_ *cobra.Command, args []string) error {
messages = append(messages, err.Error())
fmt.Fprintf(r.Command.ErrOrStderr(), "%s failed (%s)\n", name, err)
} else {
fmt.Fprintf(r.Command.OutOrStderr(), "%s rejected\n", name)
fmt.Fprintf(r.Command.OutOrStdout(), "%s rejected\n", name)
}
case v1alpha1.PackageRevisionLifecycleDeletionProposed:
pr.Spec.Lifecycle = v1alpha1.PackageRevisionLifecyclePublished
if err := r.porchClient.Update(r.ctx, pr); err != nil {
messages = append(messages, err.Error())
fmt.Fprintf(r.Command.ErrOrStderr(), "%s failed (%s)\n", name, err)
} else {
fmt.Fprintf(r.Command.OutOrStderr(), "%s no longer proposed for deletion\n", name)
fmt.Fprintf(r.Command.OutOrStdout(), "%s no longer proposed for deletion\n", name)
}
default:
msg := fmt.Sprintf("cannot reject %s with lifecycle '%s'", name, pr.Spec.Lifecycle)
Expand Down

1 comment on commit 1eed119

@liamfallon
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add unit tests to test these outputs?

Please sign in to comment.