Merge pull request #1684 from thaJeztah/plugin_subcommand_detection

Show plugins as Management commands
This commit is contained in:
Silvin Lubecki 2019-02-26 14:22:18 +01:00 committed by GitHub
commit 3174ca0e69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -139,7 +139,7 @@ func hasInvalidPlugins(cmd *cobra.Command) bool {
func operationSubCommands(cmd *cobra.Command) []*cobra.Command {
cmds := []*cobra.Command{}
for _, sub := range cmd.Commands() {
if isPlugin(sub) && invalidPluginReason(sub) != "" {
if isPlugin(sub) {
continue
}
if sub.IsAvailableCommand() && !sub.HasSubCommands() {
@ -179,7 +179,10 @@ func vendorAndVersion(cmd *cobra.Command) string {
func managementSubCommands(cmd *cobra.Command) []*cobra.Command {
cmds := []*cobra.Command{}
for _, sub := range cmd.Commands() {
if isPlugin(sub) && invalidPluginReason(sub) != "" {
if isPlugin(sub) {
if invalidPluginReason(sub) == "" {
cmds = append(cmds, sub)
}
continue
}
if sub.IsAvailableCommand() && sub.HasSubCommands() {
@ -245,7 +248,7 @@ Management Commands:
Commands:
{{- range operationSubCommands . }}
{{rpad (decoratedName .) (add .NamePadding 1)}}{{.Short}}{{ if isPlugin .}} {{vendorAndVersion .}}{{ end}}
{{rpad .Name .NamePadding }} {{.Short}}
{{- end}}
{{- end}}

View File

@ -41,10 +41,10 @@ func TestGlobalHelp(t *testing.T) {
regexp.MustCompile(`^A self-sufficient runtime for containers$`),
regexp.MustCompile(`^Management Commands:$`),
regexp.MustCompile(`^ container\s+Manage containers$`),
helloworldre,
regexp.MustCompile(`^ image\s+Manage images$`),
regexp.MustCompile(`^Commands:$`),
regexp.MustCompile(`^ create\s+Create a new container$`),
helloworldre,
regexp.MustCompile(`^ ps\s+List containers$`),
regexp.MustCompile(`^Invalid Plugins:$`),
badmetare,
nil, // scan to end of input rather than stopping at badmetare