diff --git a/cmd/imgpkg/imgpkg.go b/cmd/imgpkg/imgpkg.go index f54026cd6..93b88aefb 100644 --- a/cmd/imgpkg/imgpkg.go +++ b/cmd/imgpkg/imgpkg.go @@ -10,6 +10,7 @@ import ( "os" "time" + "github.com/cppforlife/cobrautil" uierrs "github.com/cppforlife/go-cli-ui/errors" "github.com/cppforlife/go-cli-ui/ui" "github.com/vmware-tanzu/carvel-imgpkg/pkg/imgpkg/cmd" @@ -40,6 +41,7 @@ func main() { confUI.ErrorLinef("imgpkg: Error: %v", uierrs.NewMultiLineError(err)) os.Exit(1) } - - confUI.PrintLinef("Succeeded") + if !cobrautil.IsCobraManagedCommand(os.Args) { + confUI.PrintLinef("Succeeded") + } } diff --git a/go.mod b/go.mod index 1346f65c3..b9f4d76cd 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/awslabs/amazon-ecr-credential-helper/ecr-login v0.0.0-20220517224237-e6f29200ae04 github.com/cheggaaa/pb/v3 v3.0.8 github.com/chrismellard/docker-credential-acr-env v0.0.0-20220327082430-c57b701bfc08 - github.com/cppforlife/cobrautil v0.0.0-20200514214827-bb86e6965d72 + github.com/cppforlife/cobrautil v0.0.0-20221021151949-d60711905d65 github.com/cppforlife/go-cli-ui v0.0.0-20220425131040-94f26b16bc14 github.com/fatih/color v1.13.0 // indirect github.com/google/go-containerregistry v0.11.0 diff --git a/go.sum b/go.sum index fa772226b..a16b6b792 100644 --- a/go.sum +++ b/go.sum @@ -175,8 +175,8 @@ github.com/coreos/go-systemd v0.0.0-20190620071333-e64a0ec8b42a/go.mod h1:F5haX7 github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cppforlife/cobrautil v0.0.0-20200514214827-bb86e6965d72 h1:rPWcUBgMb1ox2eCohCuZ8gsZVe0aB5qBbYaBpdoxfCE= -github.com/cppforlife/cobrautil v0.0.0-20200514214827-bb86e6965d72/go.mod h1:2w+qxVu2KSGW78Ex/XaIqfh/OvBgjEsmN53S4T8vEyA= +github.com/cppforlife/cobrautil v0.0.0-20221021151949-d60711905d65 h1:+3J1K6yQFRPKDEl5Py68c1q0FjaCkeMcB1nb7uzmpSw= +github.com/cppforlife/cobrautil v0.0.0-20221021151949-d60711905d65/go.mod h1:2w+qxVu2KSGW78Ex/XaIqfh/OvBgjEsmN53S4T8vEyA= github.com/cppforlife/color v1.9.1-0.20200716202919-6706ac40b835 h1:mYQweUIBD+TBRjIeQnJmXr0GSVMpI6O0takyb/aaOgo= github.com/cppforlife/color v1.9.1-0.20200716202919-6706ac40b835/go.mod h1:dYeVsKp1vvK8XjdTPR1gF+uk+9doxKeO3hqQTOCr7T4= github.com/cppforlife/go-cli-ui v0.0.0-20220425131040-94f26b16bc14 h1:MjRdR01xh0sfkeS3OOBv+MYkYsrbHuTDc4rfBnVdFaI= diff --git a/pkg/imgpkg/cmd/imgpkg.go b/pkg/imgpkg/cmd/imgpkg.go index c828f87dc..374d829ed 100644 --- a/pkg/imgpkg/cmd/imgpkg.go +++ b/pkg/imgpkg/cmd/imgpkg.go @@ -5,6 +5,7 @@ package cmd import ( "io" + "os" "github.com/cppforlife/cobrautil" "github.com/cppforlife/go-cli-ui/ui" @@ -40,7 +41,7 @@ func NewImgpkgCmd(o *ImgpkgOptions) *cobra.Command { // setting output for cmd.Help() blockWriter := uiBlockWriter{o.ui} cmd.SetOut(blockWriter) - cmd.SetErr(blockWriter) + cmd.SetErr(os.Stderr) o.UIFlags.Set(cmd) o.DebugFlags.Set(cmd) diff --git a/vendor/github.com/cppforlife/cobrautil/misc.go b/vendor/github.com/cppforlife/cobrautil/misc.go index ad1bddce9..29edce0a9 100644 --- a/vendor/github.com/cppforlife/cobrautil/misc.go +++ b/vendor/github.com/cppforlife/cobrautil/misc.go @@ -64,7 +64,7 @@ func ReconfigureCmdWithSubcmd(cmd *cobra.Command) { var strs []string for _, subcmd := range cmd.Commands() { if !subcmd.Hidden { - strs = append(strs, subcmd.Use) + strs = append(strs, subcmd.Name()) } } @@ -87,7 +87,7 @@ func ShowSubcommands(cmd *cobra.Command, args []string) error { var strs []string for _, subcmd := range cmd.Commands() { if !subcmd.Hidden { - strs = append(strs, subcmd.Use) + strs = append(strs, subcmd.Name()) } } return fmt.Errorf("Use one of available subcommands: %s", strings.Join(strs, ", ")) @@ -97,3 +97,22 @@ func ShowHelp(cmd *cobra.Command, args []string) error { cmd.Help() return fmt.Errorf("Invalid command - see available commands/subcommands above") } + +func IsCobraManagedCommand(args []string) bool { + if len(args) > 1 { + cmdPathPieces := args[1:] + + var cmdName string // first "non-flag" arguments + for _, arg := range cmdPathPieces { + if !strings.HasPrefix(arg, "-") { + cmdName = arg + break + } + } + switch cmdName { + case "help", cobra.ShellCompRequestCmd, cobra.ShellCompNoDescRequestCmd: + return true + } + } + return false +} diff --git a/vendor/modules.txt b/vendor/modules.txt index b5df18b2c..5ca2c58d1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -131,7 +131,7 @@ github.com/chrismellard/docker-credential-acr-env/pkg/token ## explicit; go 1.16 github.com/containerd/stargz-snapshotter/estargz github.com/containerd/stargz-snapshotter/estargz/errorutil -# github.com/cppforlife/cobrautil v0.0.0-20200514214827-bb86e6965d72 +# github.com/cppforlife/cobrautil v0.0.0-20221021151949-d60711905d65 ## explicit github.com/cppforlife/cobrautil # github.com/cppforlife/color v1.9.1-0.20200716202919-6706ac40b835