-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
area/v2relates to / is being considered for v2relates to / is being considered for v2kind/bugdescribes or fixes a bugdescribes or fixes a bugstatus/triagemaintainers still need to look into thismaintainers still need to look into this
Description
My urfave/cli version is
v2.25.3
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
Newer versions of urfave seem to remove categories from subcommands. This feature was at least in urfave version v2.16.3 but when upgrading to newest version (v2.25.3 as of this time) then categores for subcommands are not displayed anymore in the --help output.
To reproduce
Consider the following code which assigns categories to subcommands:
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/urfave/cli/v2"
)
func WithCategory(cat string, cmd *cli.Command) *cli.Command {
cmd.Category = strings.ToUpper(cat)
return cmd
}
func main() {
var printUserInfo = &cli.Command{
Name: "user-info",
Usage: "prints user info",
Action: func(cctx *cli.Context) error {
fmt.Println("Prints some userinfo")
return nil
},
}
var printFullUserInfo = &cli.Command{
Name: "full-user-info",
Usage: "prints full user info",
Action: func(cctx *cli.Context) error {
fmt.Println("Prints full userinfo")
return nil
},
}
var printHostInfo = &cli.Command{
Name: "host-info",
Usage: "prints host info",
Action: func(cctx *cli.Context) error {
fmt.Println("Prints host userinfo")
return nil
},
}
app := &cli.App{
Name: "urfavehelp",
Usage: "this test app shows that subcommand categories are not displayed in help",
Commands: []*cli.Command{
{
Name: "print",
Category: "INFO",
Usage: "Prints all information",
Subcommands: []*cli.Command{
WithCategory("USER", printUserInfo),
WithCategory("USER", printFullUserInfo),
WithCategory("HOST", printHostInfo),
},
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}Observed behavior
When running go run urfavehelp.go print it displays:
NAME:
urfavehelp print - Prints all information
USAGE:
urfavehelp print command [command options] [arguments...]
COMMANDS:
user-info prints user info
full-user-info prints full user info
host-info prints host info
help, h Shows a list of commands or help for one command
OPTIONS:
--help, -h show help
Expected behavior
I would expect the help output to show the categories like this (this is how it looks like in v2.16.3):
NAME:
urfavehelp print - Prints all information
USAGE:
urfavehelp print command [command options] [arguments...]
COMMANDS:
help, h Shows a list of commands or help for one command
USER:
user-info prints user info
full-user-info prints full user info
HOST:
host-info prints host info
OPTIONS:
--help, -h show help
Additional context
I tried looking if there is some flag or option which includes the categories for subcommands but I didn't find any so far.
Run go version and paste its output here
go version go1.20.3 linux/amd64
Run go env and paste its output here
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/fridrik/.cache/go-build"
GOENV="/home/fridrik/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/fridrik/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/fridrik/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/fridrik/workspace/urfavehelp/go.mod"
GOWORK=""
CGO_CFLAGS="-D__BLST_PORTABLE__"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3841760188=/tmp/go-build -gno-record-gcc-switches"
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area/v2relates to / is being considered for v2relates to / is being considered for v2kind/bugdescribes or fixes a bugdescribes or fixes a bugstatus/triagemaintainers still need to look into thismaintainers still need to look into this