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

fish completion fails with nested subcommands #685

Closed
emk opened this issue Oct 10, 2016 · 7 comments
Closed

fish completion fails with nested subcommands #685

emk opened this issue Oct 10, 2016 · 7 comments
Labels
A-completion Area: completion generator C-bug Category: Updating dependencies

Comments

@emk
Copy link

emk commented Oct 10, 2016

cage has nested subcommands:

> cage repo 
cage repo 
cage-repo 
Commands for working with git repositories

USAGE:
    cage repo [SUBCOMMAND]

FLAGS:
    -h, --help    Prints help information

SUBCOMMANDS:
    clone    Clone a git repository using its short alias and mount it
             into the containers that use it
    help     Prints this message or the help of the given subcommand(s)
    list     List all known git repository aliases and URLs

The top-level subcommands complete fine under fish:

> cage rep<TAB>
> cage repo

But second-level subcommands fail:

> cage repo l<TAB>
...lists files in current directory...

Using the generated bash completion, this works correctly:

> cage repo l<TAB>
> cage repo list

I don't have time to dig into this right now, but I hope that because it already works with one shell, it's just a simple fix for the other.

emk added a commit to faradayio/cage that referenced this issue Oct 10, 2016
Note that our completion support is incomplete pending solutions for
these two issues:

clap-rs/clap#568
clap-rs/clap#685
@kbknapp
Copy link
Member

kbknapp commented Oct 10, 2016

Thanks for fiiling this! I'll start looking into it and report back with what I find.

@kbknapp kbknapp added C-bug Category: Updating dependencies P2: need to have A-completion Area: completion generator labels Oct 10, 2016
@kbknapp
Copy link
Member

kbknapp commented Oct 10, 2016

cc @wdv4758h

@wdv4758h
Copy link
Contributor

I can try to fix it, but the progress may be slow, since I'm fulfilling my country's mandatory military service.
I don't have much time to write code until next year. :(

@wdv4758h
Copy link
Contributor

I have fixed it!

@emk here is the new result for cage's cli.yml, please try it.

function __fish_using_command
    set cmd (commandline -opc)
    if [ (count $cmd) -eq (count $argv) ]
        for i in (seq (count $argv))
            if [ $cmd[$i] != $argv[$i] ]
                return 1
            end
        end
        return 0
    end
    return 1
end

complete -c cage -n '__fish_using_command cage' -s p -l project-name -d 'The name of this project.  Defaults to the current directory name.'
complete -c cage -n '__fish_using_command cage' -l override -d 'Use overrides from the specified subdirectory of `pods/overrides`.  Defaults to `development` unless running tests.'
complete -c cage -n '__fish_using_command cage' -l default-tags -d 'A list of tagged image names, one per line, to be used as defaults for images.'
complete -c cage -n '__fish_using_command cage' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage' -f -a 'sysinfo'
complete -c cage -n '__fish_using_command cage' -f -a 'new'
complete -c cage -n '__fish_using_command cage' -f -a 'build'
complete -c cage -n '__fish_using_command cage' -f -a 'pull'
complete -c cage -n '__fish_using_command cage' -f -a 'up'
complete -c cage -n '__fish_using_command cage' -f -a 'stop'
complete -c cage -n '__fish_using_command cage' -f -a 'run'
complete -c cage -n '__fish_using_command cage' -f -a 'exec'
complete -c cage -n '__fish_using_command cage' -f -a 'shell'
complete -c cage -n '__fish_using_command cage' -f -a 'test'
complete -c cage -n '__fish_using_command cage' -f -a 'repo'
complete -c cage -n '__fish_using_command cage' -f -a 'generate'
complete -c cage -n '__fish_using_command cage' -f -a 'export'
complete -c cage -n '__fish_using_command cage' -f -a 'help'
complete -c cage -n '__fish_using_command cage sysinfo' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage sysinfo' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage new' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage new' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage build' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage build' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage pull' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage pull' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage up' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage up' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage stop' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage stop' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage run' -l user -d 'User as which to run a command'
complete -c cage -n '__fish_using_command cage run' -l entrypoint -d 'Override the entrypoint of the service'
complete -c cage -n '__fish_using_command cage run' -s e -d 'Set an environment variable in the container'
complete -c cage -n '__fish_using_command cage run' -s d -d 'Run command detached in background'
complete -c cage -n '__fish_using_command cage run' -s T -d 'Do not allocate a TTY when running a command'
complete -c cage -n '__fish_using_command cage run' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage run' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage exec' -l user -d 'User as which to run a command'
complete -c cage -n '__fish_using_command cage exec' -s d -d 'Run command detached in background'
complete -c cage -n '__fish_using_command cage exec' -s T -d 'Do not allocate a TTY when running a command'
complete -c cage -n '__fish_using_command cage exec' -l privileged -d 'Run a command with elevated privileges'
complete -c cage -n '__fish_using_command cage exec' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage exec' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage shell' -l user -d 'User as which to run a command'
complete -c cage -n '__fish_using_command cage shell' -s d -d 'Run command detached in background'
complete -c cage -n '__fish_using_command cage shell' -s T -d 'Do not allocate a TTY when running a command'
complete -c cage -n '__fish_using_command cage shell' -l privileged -d 'Run a command with elevated privileges'
complete -c cage -n '__fish_using_command cage shell' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage shell' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage test' -l user -d 'User as which to run a command'
complete -c cage -n '__fish_using_command cage test' -l entrypoint -d 'Override the entrypoint of the service'
complete -c cage -n '__fish_using_command cage test' -s e -d 'Set an environment variable in the container'
complete -c cage -n '__fish_using_command cage test' -s d -d 'Run command detached in background'
complete -c cage -n '__fish_using_command cage test' -s T -d 'Do not allocate a TTY when running a command'
complete -c cage -n '__fish_using_command cage test' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage test' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage repo' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage repo' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage repo' -f -a 'list'
complete -c cage -n '__fish_using_command cage repo' -f -a 'clone'
complete -c cage -n '__fish_using_command cage repo' -f -a 'help'
complete -c cage -n '__fish_using_command cage repo list' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage repo list' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage repo clone' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage repo clone' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage repo help' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage repo help' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage generate' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage generate' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage generate' -f -a 'completion'
complete -c cage -n '__fish_using_command cage generate' -f -a 'secrets'
complete -c cage -n '__fish_using_command cage generate' -f -a 'vault'
complete -c cage -n '__fish_using_command cage generate' -f -a 'help'
complete -c cage -n '__fish_using_command cage generate completion' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage generate completion' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage generate secrets' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage generate secrets' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage generate vault' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage generate vault' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage generate help' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage generate help' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage export' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage export' -s V -l version -d 'Prints version information'
complete -c cage -n '__fish_using_command cage help' -s h -l help -d 'Prints help information'
complete -c cage -n '__fish_using_command cage help' -s V -l version -d 'Prints version information'

homu added a commit that referenced this issue Oct 16, 2016
fix(Completions): fish completions for nested subcommands

Fix #685
homu added a commit that referenced this issue Oct 16, 2016
fix(Completions): fish completions for nested subcommands

Fix #685
@homu homu closed this as completed in #687 Oct 16, 2016
@emk
Copy link
Author

emk commented Oct 16, 2016

@wdv4758h I can confirm that this fix works great! Thank you for taking time during your military service to implement this patch.

@dpc
Copy link

dpc commented Oct 15, 2019

Has this regressed since it was implemented? I'm using structopt with nested subcommands (https://github.com/crev-dev/cargo-crev/blob/5c61181a14b947568cb33a17ab76a7e278d5eb13/cargo-crev/src/main.rs#L267) and I'm getting

trust level'
complete -c cargo -n "__fish_seen_subcommand_from issue" -l low-cost -d '[trust-graph-traversal] Cost of traversing trust graph edge of low trust level'
complete -c cargo -n "__fish_seen_subcommand_from issue" -l trust -d 'Minimum trust level of the reviewers for reviews'
complete -c cargo -n "__fish_seen_subcommand_from issue" -s u -l unrelated -d 'This crate is not neccesarily a dependency of the current cargo project'
complete -c cargo -n "__fish_seen_subcommand_from issue" -s h -l help -d 'Prints help information'
complete -c cargo -n "__fish_seen_subcommand_from issue" -s V -l version -d 'Prints version information'
complete -c cargo -n "__fish_seen_subcommand_from help" -s h -l help -d 'Prints help information'

and not what is mentioned here (`-n '__fish_using_command cage generate help')

@ModProg
Copy link
Contributor

ModProg commented Aug 18, 2021

Has this regressed since it was implemented?

yes it had, I made a new issue over here #2715

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion Area: completion generator C-bug Category: Updating dependencies
Projects
None yet
Development

No branches or pull requests

5 participants