Skip to content

Commit

Permalink
Fix bash completion for kctrl (#889)
Browse files Browse the repository at this point in the history
- Do not print Succeeded for the help command
- Use SetOut from cobra to set output for cmd.Help()
  • Loading branch information
praveenrewar authored Sep 19, 2022
1 parent b6153d0 commit 2299295
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
5 changes: 4 additions & 1 deletion cli/cmd/kctrl/kctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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-kapp-controller/cli/pkg/kctrl/cmd"
Expand Down Expand Up @@ -41,6 +42,8 @@ func nonExitingMain() error {
return err
}

confUI.PrintLinef("Succeeded")
if !cobrautil.IsCobraInternalCommand(os.Args) {
confUI.PrintLinef("Succeeded")
}
return nil
}
2 changes: 1 addition & 1 deletion cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/vmware-tanzu/carvel-kapp-controller/cli
go 1.17

require (
github.com/cppforlife/cobrautil v0.0.0-20200514214827-bb86e6965d72
github.com/cppforlife/cobrautil v0.0.0-20220907150944-da5ee3a6ab1f
github.com/cppforlife/color v1.9.1-0.20200716202919-6706ac40b835
github.com/cppforlife/go-cli-ui v0.0.0-20220520125801-e45d9169a663
github.com/getkin/kin-openapi v0.81.0
Expand Down
3 changes: 2 additions & 1 deletion cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+
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-20220907150944-da5ee3a6ab1f h1:KkqeYFcNT2SHYUR5cGJ0YZoIZW12yFf36OBWFStufvk=
github.com/cppforlife/cobrautil v0.0.0-20220907150944-da5ee3a6ab1f/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-20200716203538-1e47f820817f/go.mod h1:L18TqO77ci8i+hFtlMC4zSFz/D3O8lf84TyVU+zFF8E=
Expand Down
2 changes: 1 addition & 1 deletion cli/pkg/kctrl/cmd/kctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func NewKctrlCmd(o *KctrlOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Comm
// TODO bash completion
}

cmd.SetOutput(uiBlockWriter{o.ui}) // setting output for cmd.Help()
cmd.SetOut(uiBlockWriter{o.ui}) // setting output for cmd.Help()

cmd.SetUsageTemplate(cobrautil.HelpSectionsUsageTemplate([]cobrautil.HelpSection{
cmdcore.PackageHelpGroup,
Expand Down
23 changes: 21 additions & 2 deletions cli/vendor/github.com/cppforlife/cobrautil/misc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ github.com/beorn7/perks/quantile
# github.com/cespare/xxhash/v2 v2.1.1
## explicit; go 1.11
github.com/cespare/xxhash/v2
# github.com/cppforlife/cobrautil v0.0.0-20200514214827-bb86e6965d72
# github.com/cppforlife/cobrautil v0.0.0-20220907150944-da5ee3a6ab1f
## explicit
github.com/cppforlife/cobrautil
# github.com/cppforlife/color v1.9.1-0.20200716202919-6706ac40b835
Expand Down

0 comments on commit 2299295

Please sign in to comment.