Clap: fish completion fails with nested subcommands

Created on 10 Oct 2016  路  6Comments  路  Source: clap-rs/clap

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.

generator need to have bug 2.x

Most helpful comment

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'

All 6 comments

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

cc @wdv4758h

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. :(

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'

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

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')

Was this page helpful?
0 / 5 - 0 ratings

Related issues

neysofu picture neysofu  路  41Comments

jojva picture jojva  路  18Comments

casey picture casey  路  25Comments

kbknapp picture kbknapp  路  18Comments

kbknapp picture kbknapp  路  30Comments