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

[feature] shell completion #1

Closed
jmaupetit opened this issue Mar 18, 2015 · 8 comments
Closed

[feature] shell completion #1

jmaupetit opened this issue Mar 18, 2015 · 8 comments

Comments

@jmaupetit
Copy link
Contributor

Add completion on commands project names and tags may be useful.

@SpotlightKid
Copy link
Contributor

Here's a bash completion script. source it or put it in /etc/bash_completion.d. This completes watson commands, command options, command names for the help command and projects and tags for the start command. It doesn't complete projects or tags for the -p and -T options of log and report yet. Another nice feature would be to complete frame ids for the remove and edit commands.

This is my first bash completion script, so maybe there are better way to do this...

# Bash completion suppoort for watson

_watson_complete () {
    local cur cmd commands projects tags

    commands='cancel config edit help log projects remove report start status stop sync tags'

    cur=${COMP_WORDS[COMP_CWORD]}
    cmd=${COMP_WORDS[1]}

    case ${COMP_CWORD} in
        1)
            COMPREPLY=($(compgen -W "$commands" -- "$cur" )) ;;
        *)
            case "${cmd}" in
                config)
                    COMPREPLY=($(compgen -W "-e --edit" -- ${cur})) ;;
                help)
                    COMPREPLY=($(compgen -W "$commands" -- "$cur" )) ;;
                log|report)
                    COMPREPLY=($(compgen -W "-f -t -p -T --from --to --project --tag" -- ${cur})) ;;
                remove)
                    COMPREPLY=($(compgen -W "-f --force" -- ${cur})) ;;
                start)
                    if [[ $COMP_CWORD -eq 2 ]]; then
                        projects="$(watson projects)"
                        COMPREPLY=($(compgen -W "$projects" -- ${cur}))
                    else
                        tags="$(watson tags | sed 's/.*/+\0/')"
                        COMPREPLY=($(compgen -W "$tags" -- ${cur}))
                    fi
                    ;;
            esac
            ;;
    esac

    return 0
}

complete -F _watson_complete watson

@willdurand
Copy link
Contributor

👍

BTW, did you see this: http://click.pocoo.org/5/bashcomplete/?

@SpotlightKid
Copy link
Contributor

Ah, ok, I was wondering how that pip completion code in my ~/.bashrc works :)

Unfortunately, this is an all-or-nothing-solution, it seems. You can't customize it to support project and tag completion.

To implement frame ID completion, the following new watson command would be helpful (in the vein of watson projects and watson tags). I'm not sure, though, how helpful it would be to be presented with a list of opaque hex IDs when trying to find the frame to edit or remove.

@cli.command()
@click.pass_obj
def frames(watson):
    """
    Display the list of all frame IDs.

    \b
    Example:
    $ watson frames
    f1c4815
    9d1a989
    8801ec3
    [...]
    """
    for frame in watson.frames:
        click.echo(style('short_id', frame.id))

@willdurand
Copy link
Contributor

I'm not sure, though, how helpful it would be to be presented with a list of opaque hex IDs when trying to find the frame to edit or remove.

If it is not useful, then we can switch back to click's built-in completion feature, right?

@SpotlightKid
Copy link
Contributor

No, since that doesn't give completion of projects and tags, AFAICS.

SpotlightKid added a commit to SpotlightKid/Watson that referenced this issue Oct 19, 2015
…ommand.

The new `frames` command lists all frame IDs to support command-line
completion of frame IDs for `edit` and `remove` command.
@willdurand
Copy link
Contributor

You're right!

SpotlightKid added a commit to SpotlightKid/Watson that referenced this issue Oct 20, 2015
…ommand.

The new `frames` command lists all frame IDs to support command-line
completion of frame IDs for `edit` and `remove` command.
loonies pushed a commit to loonies/Watson that referenced this issue Feb 19, 2016
…ommand.

The new `frames` command lists all frame IDs to support command-line
completion of frame IDs for `edit` and `remove` command.
@k4nar
Copy link
Collaborator

k4nar commented Jan 27, 2017

@SpotlightKid : Did you had the chance to take a look at https://github.com/click-contrib/click-completion ?

@SpotlightKid
Copy link
Contributor

No, I haven't. I wasn't aware of that project. How does it help completing Watson specific objects like project and tags?

Anyway, as you know, patches always welcome! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants