urfave / cli

A simple, fast, and fun package for building command line apps in Go

Home Page:https://cli.urfave.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No commands listed when only one subcommand

Kyrremann opened this issue · comments

My urfave/cli version is

v2.25.7

Checklist

  • Are you running the latest v2 release? The list of releases is here.
  • Did you check the manual for your release? The v2 manual is here
  • Did you perform a search about this problem? Here's the GitHub guide about searching.

Dependency Management

  • My project is using go modules.

Describe the bug

When I make a command with only one subcommand and hide the help command my subcommand is not displayed.
My guess is that since a command and a subcommand is the "same", it always hide the command list when it's fewer than one item there, because it assumes it is the help-command.

To reproduce

package main

import (
	"log"
	"os"

	"github.com/urfave/cli/v2"
)

func main() {
	app := &cli.App{
		Name: "hello",
		Commands: []*cli.Command{
			{
				Name: "world",
				HideHelpCommand: true,
				Subcommands: []*cli.Command{
					{
						Name: "welcome",
					},	
				},
			},
		},
	}

	if err := app.Run(os.Args); err != nil {
		log.Fatal(err)
	}
}

Observed behavior

./nais p password -h
NAME:
   nais postgres password - Administrate Postgres password

USAGE:
   nais postgres password [command options] [arguments...]

OPTIONS:
   --help, -h  show help

Expected behavior

./nais p password -h
NAME:
   nais postgres password - Administrate Postgres password

USAGE:
   nais postgres password command [command options] [arguments...]

COMMANDS:
   rotate

OPTIONS:
   --help, -h  show help

Additional context

If I enable HideHelpCommand for the specific command (not the subcommand) it works.

Run go version and paste its output here

go version go1.20.5 darwin/arm64

Run go env and paste its output here

GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/user/Library/Caches/go-build"
GOENV="/Users/user/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/user/workspace/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/user/workspace/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.20.5/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.20.5/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.5"
GCCGO="gccgo"
AR="ar"
CC="cc"
CXX="c++"
CGO_ENABLED="1"
GOMOD="/Users/user/workspace/company/cli/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/1v/j4d_bg_j4bs119btmjh244lw0000gn/T/go-build274875656=/tmp/go-build -gno-record-gcc-switches -fno-common"

@Kyrremann Thanks for reporting this. Can you set HideHelpCommand at the App level and see if that works for you ?

I have already set that value to true at the App level, no change for me in my original code (did not try it in the reproduce example).

For now my solution is just to show the help-command, it's not a big deal for us.

PS: This is my code where I'm using this library, it's a big PR where I change from cobra/viper to this one: nais/cli#209

@Kyrremann Can you try the fix in the PR ? Thanks

That fixed it!

$ ./nais postgres password
NAME:
   nais postgres password - Administrate Postgres password

USAGE:
   nais postgres password command [command options] [arguments...]

COMMANDS:
   rotate  Rotate the Postgres database password

OPTIONS:
   --help, -h  show help