urfave / cli

A simple, fast, and fun package for building command line apps in Go
https://cli.urfave.org
MIT License
21.9k stars 1.69k forks source link

Shell completion is suggesting aliases #1875

Closed bartekpacia closed 2 months ago

bartekpacia commented 3 months ago

My urfave/cli version is

v2.27.1

Checklist

Dependency Management

My project is using Go modules.

Describe the bug

My program called emu is built with this great module. Let's say emu has the following commands:

The list command also has an alias ls.

The problem is that both list and ls are shown in shell completion ("TAB completion"), which doesn't make much sense and is annoying:

https://github.com/urfave/cli/assets/40357511/ce917534-c111-4b49-a777-14f2d469e58f

To reproduce wrong behavior

  1. Create an app that has at least 1 command with 2 or more aliases
  2. Try to use shell completion for that app
  3. Notice bug

Expected behavior

Aliases are not shown in shell completion. This is how huge, popular CLI projects like gh or docker do it:

$ docker image list --help

Usage:  docker image ls [OPTIONS] [REPOSITORY[:TAG]]

List images

Aliases:
  docker image ls, docker image list, docker images

... <omitted>

https://github.com/urfave/cli/assets/40357511/632e9b65-4502-4ad6-a65f-e5b35eb79956

(in Docker's case, ls is the main command and list is an alias - so my point is still valid).

Want to fix this yourself?

Sure!

Run go version and paste its output here

go version go1.22.1 darwin/arm64

Run go env and paste its output here

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/bartek/Library/Caches/go-build'
GOENV='/Users/bartek/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/bartek/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/bartek/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.22.1/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.1/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.1'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/bartek/projects/emu/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 -ffile-prefix-map=/var/folders/r6/5z0bypqn4cb8p369zlrfhw3c0000gn/T/go-build1695057898=/tmp/go-build -gno-record-gcc-switches -fno-common'
dearchap commented 3 months ago

This is not really a bug as much as it is a desired behaviour.

bartekpacia commented 3 months ago

Can we mark it as v3 instead of v2 and not as bug but as "change/feature" requst?