Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

cli: bash auto-completion for solana cli #14005

Open
sotcsa opened this issue Dec 7, 2020 · 5 comments
Open

cli: bash auto-completion for solana cli #14005

sotcsa opened this issue Dec 7, 2020 · 5 comments
Milestone

Comments

@sotcsa
Copy link
Contributor

sotcsa commented Dec 7, 2020

Problem

Linux based solana command-line tool has no bash-autocomplete script, it would be perfect and easy to use on Linux (even on Mac)

Proposed Solution

Implement solana-completion.bash, add to README how to set it up.
source ./solana-completion.bash

Examples:
Docker: https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker
docker-compose: https://docs.docker.com/compose/completion/

Article on how to implement (with other useful links):
https://iridakos.com/programming/2018/03/01/bash-programmable-completion-tutorial

I am volunteering if nobody else is interestid

@mvines
Copy link
Contributor

mvines commented Dec 8, 2020

Yes please! I've wanted this for a while. I even naturally press TAB sometimes while typing solana ... and make myself sad.

@t-nelson
Copy link
Contributor

t-nelson commented Dec 8, 2020

Add another +1! The clap crate can allegedly do this for us, but I don't think anyone has been bothered enough to check it out. https://docs.rs/clap/2.33.3/clap/struct.App.html#method.gen_completions

@mvines mvines added this to the The Future! milestone May 10, 2021
theonekeyg added a commit to theonekeyg/solana that referenced this issue Jul 27, 2021
…and solana-labs#14005)

Implement `completion` SubCommand for solana-cli, which outputs
completion script to stdout and exits the process. The script generation
handled completely by clap.

In order to implement the generation, one minor design change was
necessary regarding the creation of clap `App`.

Previously: One part of App initialization was in the `app` function,
and some other arguments and subcommands were added later directly in
the `main` function.

Now: The whole construction of App was moved to `get_clap_app` function.

P.S. I wasn't sure if constructing App separately had visual importance,
so both constructing parts are still separate in `base_clap_app` and
`final_clap_app` functions. But they sure could be in one single
function.
CriesofCarrots pushed a commit that referenced this issue Jul 28, 2021
… (#18931)

* Auto-generate shell completions for solana-cli (issue #8879 and #14005)

Implement `completion` SubCommand for solana-cli, which outputs
completion script to stdout and exits the process. The script generation
handled completely by clap.

In order to implement the generation, one minor design change was
necessary regarding the creation of clap `App`.

Previously: One part of App initialization was in the `app` function,
and some other arguments and subcommands were added later directly in
the `main` function.

Now: The whole construction of App was moved to `get_clap_app` function.

P.S. I wasn't sure if constructing App separately had visual importance,
so both constructing parts are still separate in `base_clap_app` and
`final_clap_app` functions. But they sure could be in one single
function.

* Dereplicode match expr, fix clippy warning.

* Move clap App construction into separate module

Also join two parts of the construction into a single function

* Fix tests

* Apply rustfmt lints
mergify bot pushed a commit that referenced this issue Jul 28, 2021
… (#18931)

* Auto-generate shell completions for solana-cli (issue #8879 and #14005)

Implement `completion` SubCommand for solana-cli, which outputs
completion script to stdout and exits the process. The script generation
handled completely by clap.

In order to implement the generation, one minor design change was
necessary regarding the creation of clap `App`.

Previously: One part of App initialization was in the `app` function,
and some other arguments and subcommands were added later directly in
the `main` function.

Now: The whole construction of App was moved to `get_clap_app` function.

P.S. I wasn't sure if constructing App separately had visual importance,
so both constructing parts are still separate in `base_clap_app` and
`final_clap_app` functions. But they sure could be in one single
function.

* Dereplicode match expr, fix clippy warning.

* Move clap App construction into separate module

Also join two parts of the construction into a single function

* Fix tests

* Apply rustfmt lints

(cherry picked from commit 9d0a937)
mergify bot added a commit that referenced this issue Jul 28, 2021
… (#18931) (#18945)

* Auto-generate shell completions for solana-cli (issue #8879 and #14005)

Implement `completion` SubCommand for solana-cli, which outputs
completion script to stdout and exits the process. The script generation
handled completely by clap.

In order to implement the generation, one minor design change was
necessary regarding the creation of clap `App`.

Previously: One part of App initialization was in the `app` function,
and some other arguments and subcommands were added later directly in
the `main` function.

Now: The whole construction of App was moved to `get_clap_app` function.

P.S. I wasn't sure if constructing App separately had visual importance,
so both constructing parts are still separate in `base_clap_app` and
`final_clap_app` functions. But they sure could be in one single
function.

* Dereplicode match expr, fix clippy warning.

* Move clap App construction into separate module

Also join two parts of the construction into a single function

* Fix tests

* Apply rustfmt lints

(cherry picked from commit 9d0a937)

Co-authored-by: theonekeyg <34949189+theonekeyg@users.noreply.github.com>
@CriesofCarrots
Copy link
Contributor

solana-cli can now generate a shell completion script, but I've left this issue open because we still lack docs about how to enable. Maybe something like this? https://github.com/rust-lang/rustup/blob/master/doc/src/installation/index.md#enable-tab-completion-for-bash-fish-zsh-or-powershell

@sotcsa
Copy link
Contributor Author

sotcsa commented Aug 28, 2022

Great job!

Could you add to the docs how to use it?
E.g.

solana completion > bin/solana_completion.sh
source bin/solana_completion.sh

@hongquan
Copy link

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

No branches or pull requests

5 participants