Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to support cobra 1.6 #7

Closed
marckhouzam opened this issue Nov 9, 2022 · 0 comments · Fixed by #8
Closed

Need to support cobra 1.6 #7

marckhouzam opened this issue Nov 9, 2022 · 0 comments · Fixed by #8

Comments

@marckhouzam
Copy link
Contributor

Cobra 1.6 has modified its default help template. This breaks cobrautil which needs to manipulate the original string.
This has come up when trying to upgrade to Cobra 1.6 in Tanzu Framework where we get the error:

panic: Expected to find available commands section in spf13/cobra default usage template

The problematic code is:

const defaultTpl = `{{if .HasAvailableSubCommands}}
Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name "help"))}}
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}`
if !strings.Contains(usageTemplate, defaultTpl) {
panic("Expected to find available commands section in spf13/cobra default usage template")
}

The change to Cobra can be seen here: spf13/cobra@2169adb#diff-4d7d1923693fc5ce892add2ea2907a744e77ea0b50c1939ccc5067cb48a466a3L514
and was part of spf13/cobra#1003

I'll post a PR

marckhouzam added a commit to marckhouzam/tanzu-framework that referenced this issue Nov 10, 2022
We don't upgrade the 'package' plugin however, because it uses
github.com/vmware-tanzu/carvel-kapp-controller/cli/pkg/kctrl/cmd
which in turn uses github.com/cppforlife/cobrautil which panics when
using Cobra 1.6.  See cppforlife/cobrautil#7

Signed-off-by: Marc Khouzam <kmarc@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant