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

add completions for Cloud Foundry CLI #78

Open
dkoper opened this issue Feb 10, 2017 · 1 comment · May be fixed by #80
Open

add completions for Cloud Foundry CLI #78

dkoper opened this issue Feb 10, 2017 · 1 comment · May be fixed by #80
Labels
blocked Cannot continue until something is resolved

Comments

@dkoper
Copy link

dkoper commented Feb 10, 2017

Cloud Foundry is an open source, multi cloud application platform and it has a Command Line tool to interact with it.

The cf CLI supports bash completion "natively" as offered by the command line parser library it uses. Enabling it is as simple as installing the following bash completion file:

# bash completion for cf

_cf() {
    # All arguments except the first one
    args=("${COMP_WORDS[@]:1:$COMP_CWORD}")

    # Only split on newlines
    local IFS=$'\n'

    # Call completion (note that the first element of COMP_WORDS is
    # the executable itself)
    COMPREPLY=($(GO_FLAGS_COMPLETION=1 ${COMP_WORDS[0]} "${args[@]}"))
    return 0
}

complete -F _cf cf

In other words, running the cf command with environment variable GO_FLAGS_COMPLETION=1 makes it return a list of completions (subcommands and flags).

If we could have a clink completion script for that, it may be fairly easy to support completions for this command, as well as any other Goflags library based CLI.

dkoper pushed a commit to dkoper/clink-completions that referenced this issue Feb 14, 2017
dkoper pushed a commit to dkoper/clink-completions that referenced this issue Feb 25, 2017
@dkoper dkoper linked a pull request Feb 25, 2017 that will close this issue
@chrisant996
Copy link
Collaborator

I would like include this, but it has a dangerous problem:

It runs the entire command line on every completion, including other commands in the command line:
del * & cf Tab will actually run both the del * and the cf command.

This can be partially mitigated by using clink.parseline() and using only the last line_state.

But that's not sufficient, either -- for example:
>foo cf Tab will run the command and redirect output to foo.

To be able to include this, the argmatcher would need to be change to be more discriminating about what it runs. For example, it could use Responding to Arguments in Argmatchers and user_data to collect the words that are relevant to the cf command itself, and run only cf with only those arguments.

@chrisant996 chrisant996 added the blocked Cannot continue until something is resolved label Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Cannot continue until something is resolved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants