Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli/completion: Add shell completion for cli
✗ CI failure Michael Uti committed 6 months ago
commit feeeaba3258338ab783aa4d6d3dc72f4ea3dc3d3
parent 6cfed884bf37cba1e0d8e97fa8b0e94df4a04b1f
1 passed 3 failed (4 total) View logs
6 files changed +42 -1
modified Cargo.lock
@@ -478,6 +478,15 @@ dependencies = [
]

[[package]]
+
name = "clap_complete"
+
version = "4.5.60"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "8e602857739c5a4291dfa33b5a298aeac9006185229a700e5810a3ef7272d971"
+
dependencies = [
+
 "clap",
+
]
+

+
[[package]]
name = "clap_derive"
version = "4.5.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2819,6 +2828,7 @@ dependencies = [
 "anyhow",
 "chrono",
 "clap",
+
 "clap_complete",
 "dunce",
 "human-panic",
 "itertools",
modified crates/radicle-cli/Cargo.toml
@@ -17,6 +17,7 @@ path = "src/main.rs"
anyhow = "1"
chrono = { workspace = true, features = ["clock", "std"] }
clap = { version = "4.5.44", features = ["derive"] }
+
clap_complete = "4.5.60"
dunce = { workspace = true }
human-panic.workspace = true
itertools.workspace = true
modified crates/radicle-cli/src/commands.rs
@@ -4,6 +4,7 @@ pub mod checkout;
pub mod clean;
pub mod clone;
pub mod cob;
+
pub mod completion;
pub mod config;
pub mod debug;
pub mod diff;
added crates/radicle-cli/src/commands/completion.rs
@@ -0,0 +1,19 @@
+
use std::io;
+

+
use clap::Parser;
+
use clap_complete::Shell;
+

+
pub(crate) const ABOUT: &str = "Generate shell completion scripts for Radicle CLI";
+

+
#[derive(Debug, Parser)]
+
#[command(about = ABOUT, disable_version_flag = true)]
+
pub struct Args {
+
    /// Shell Type to perform completion. bash, zsh, fish.
+
    #[arg(long, short)]
+
    pub(super) shell: Shell,
+
}
+

+
pub fn run(args: Args, mut command: clap::Command) {
+
    let bin_name = command.get_name().to_string();
+
    clap_complete::generate(args.shell, &mut command, bin_name, &mut io::stdout());
+
}
modified crates/radicle-cli/src/commands/help.rs
@@ -54,6 +54,10 @@ const COMMANDS: &[CommandItem] = &[
        about: crate::commands::clone::ABOUT,
    },
    CommandItem::Clap {
+
        name: "completion",
+
        about: crate::commands::completion::ABOUT,
+
    },
+
    CommandItem::Clap {
        name: "config",
        about: crate::commands::config::ABOUT,
    },
modified crates/radicle-cli/src/main.rs
@@ -5,7 +5,7 @@ use std::{io::ErrorKind, iter, process};
use anyhow::anyhow;
use clap::builder::styling::AnsiColor;
use clap::builder::Styles;
-
use clap::{Parser, Subcommand};
+
use clap::{CommandFactory, Parser, Subcommand};

use radicle::version::Version;
use radicle_cli::commands::*;
@@ -52,6 +52,7 @@ enum Commands {
    Clone(clone::Args),
    #[command(hide = true)]
    Cob(cob::Args),
+
    Completion(completion::Args),
    Config(config::Args),
    Debug(debug::Args),

@@ -231,6 +232,11 @@ pub(crate) fn run_other(exe: &str, args: &[OsString]) -> Result<(), Option<anyho
                term::run_command_fn(cob::run, args);
            }
        }
+
        "completion" => {
+
            if let Some(Commands::Completion(args)) = CliArgs::parse().command {
+
                completion::run(args, CliArgs::command());
+
            }
+
        }
        "config" => {
            if let Some(Commands::Config(args)) = CliArgs::parse().command {
                term::run_command_fn(config::run, args);