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

How to get autocomplete to not show global flags for subcommand? #1184

Closed
4 tasks done
schollz opened this issue Sep 13, 2020 · 2 comments · Fixed by #1186 or #1360
Closed
4 tasks done

How to get autocomplete to not show global flags for subcommand? #1184

schollz opened this issue Sep 13, 2020 · 2 comments · Fixed by #1186 or #1360
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
Milestone

Comments

@schollz
Copy link
Contributor

schollz commented Sep 13, 2020

my urfave/cli version is

v2.2.0

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

I am using this wonderful library for croc. This utility has global flags and also flags for subcommands. Autocompletion works great, except that if I use a subcommand and autocomplete a flag, it shows the global flags and the flags for the subcommand, even though only the subcommand flags can be used.

To reproduce

Describe the steps or code required to reproduce the behavior:

> git clone --depth 1 https://github.com/schollz/croc
> cd croc 
> go build
> ./croc send --<tab>
# shows subcommand flags + global flags that can't be used

Observed behavior

Subcommand shows global flags:

> # shows global flags + subcommand
> ./croc send --<tab>
--ask          --no-compress  --pass         --remember     --yes        
--code         --no-local     --ports        --stdout                    
--debug        --no-multi     --relay        --text                      
--help         --out          --relay6       --version

Global flags (for reference):

> # global flags
> ./croc --<tab>
--ask          --no-compress  --relay        --stdout                    
--debug        --out          --relay6       --version                   
--help         --pass         --remember     --yes

Expected behavior

I expected that autocompletion on subcommands only autocompletes flags that can be used on that subcommand. E.g. If you select a global flag from a subcommand flag autocompletion (e.g. croc send --yes README.md) it results in a flag provided but not defined error.

Additional context

Repo: https://github.com/schollz/croc

go version go1.15.1 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/zns/.cache/go-build"
GOENV="/home/zns/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/zns/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/zns/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"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/croc/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build711943122=/tmp/go-build -gno-record-gcc-switches"
@schollz schollz 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 Sep 13, 2020
@stale
Copy link

stale bot commented Dec 12, 2020

This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.

@stale stale bot added the status/stale stale due to the age of it's last update label Dec 12, 2020
@stale
Copy link

stale bot commented Jan 12, 2021

Closing this as it has become stale.

@stale stale bot closed this as completed Jan 12, 2021
@meatballhat meatballhat reopened this Apr 22, 2022
@meatballhat meatballhat changed the title q: How to get autocomplete to not show global flags for subcommand? How to get autocomplete to not show global flags for subcommand? Apr 22, 2022
@meatballhat meatballhat added this to the Release 2.4.x milestone Apr 22, 2022
@meatballhat meatballhat removed the status/stale stale due to the age of it's last update label Apr 22, 2022
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
2 participants