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

No commands listed when only one subcommand #1787

Closed
3 tasks done
Kyrremann opened this issue Jun 28, 2023 · 4 comments
Closed
3 tasks done

No commands listed when only one subcommand #1787

Kyrremann opened this issue Jun 28, 2023 · 4 comments
Labels
area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this

Comments

@Kyrremann
Copy link

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 Kyrremann added area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this labels Jun 28, 2023
@dearchap
Copy link
Contributor

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

@Kyrremann
Copy link
Author

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

@dearchap
Copy link
Contributor

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

@Kyrremann
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this
Projects
None yet
Development

No branches or pull requests

2 participants