Skip to content

Commit

Permalink
Merge branch 'tomas/shell-complete' (#3343)
Browse files Browse the repository at this point in the history
* tomas/shell-complete:
  update Cargo.lock
  changelog: add #3343
  cli: add shell completions generator
  • Loading branch information
brentstone committed Jun 6, 2024
2 parents 575cb0e + 75a2fdc commit dcdc548
Show file tree
Hide file tree
Showing 10 changed files with 279 additions and 43 deletions.
11 changes: 11 additions & 0 deletions .changelog/unreleased/improvements/3343-shell-complete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- Added a `namada complete` command to generate shell completions. This command
requires `--shell` with one of:
- bash
- elvish
- fish
- powershell
- zsh
- nushell

To use in e.g. bash, run `namada complete --shell bash > /usr/share/bash-completion/completions/namada.bash`.
([\#3343](https://github.com/anoma/namada/pull/3343))
63 changes: 42 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ borsh = {version = "1.2.0", features = ["unstable__schema", "derive"]}
borsh-ext = { git = "https://github.com/heliaxdev/borsh-ext", tag = "v1.2.0" }
chrono = {version = "0.4.22", default-features = false, features = ["clock", "std"]}
circular-queue = "0.2.6"
clap = "4.3.4"
clap = "4.5"
clap_complete = "4.5"
clap_complete_nushell = "4.5"
clru = {git = "https://github.com/marmeladema/clru-rs.git", rev = "71ca566"}
color-eyre = "0.6.2"
concat-idents = "1.1.2"
Expand Down
2 changes: 2 additions & 0 deletions crates/apps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ namada = {path = "../namada"}
namada_apps_lib = {path = "../apps_lib"}
namada_node = {path = "../node"}

clap_complete.workspace = true
clap_complete_nushell.workspace = true
color-eyre.workspace = true
eyre.workspace = true
tokio = {workspace = true, features = ["full"]}
Expand Down
41 changes: 41 additions & 0 deletions crates/apps/src/bin/namada/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,47 @@ fn handle_command(cmd: cli::cmds::Namada, raw_sub_cmd: String) -> Result<()> {
cli::cmds::Namada::Relayer(_) | cli::cmds::Namada::EthBridgePool(_) => {
handle_subcommand("namadar", sub_args)
}
cli::cmds::Namada::Complete(cli::cmds::Complete(
cli::args::Complete { shell },
)) => {
use std::io::stdout;

use clap_complete::{generate, shells};
use clap_complete_nushell::Nushell;

for (mut app, name) in [
(cli::namada_app(), "namada"),
(cli::namada_node_app(), "namadan"),
(cli::namada_client_app(), "namadac"),
(cli::namada_wallet_app(), "namadaw"),
(cli::namada_relayer_app(), "namadar"),
] {
match shell {
cli::args::Shell::Bash => {
generate(shells::Bash, &mut app, name, &mut stdout())
}
cli::args::Shell::Elvish => {
generate(shells::Elvish, &mut app, name, &mut stdout())
}
cli::args::Shell::Fish => {
generate(shells::Fish, &mut app, name, &mut stdout())
}
cli::args::Shell::PowerShell => generate(
shells::PowerShell,
&mut app,
name,
&mut stdout(),
),
cli::args::Shell::Zsh => {
generate(shells::Zsh, &mut app, name, &mut stdout())
}
cli::args::Shell::Nushell => {
generate(Nushell, &mut app, name, &mut stdout())
}
};
}
Ok(())
}
}
}

Expand Down
Loading

0 comments on commit dcdc548

Please sign in to comment.