Skip to content

Commit bc8a0f1

Browse files
authored
Merge pull request #435 from killercup/feature/shell-completions
Add shell completions command
2 parents 5120ef7 + 7669c8e commit bc8a0f1

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

modkit/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2021"
66
[dependencies]
77
anyhow = "1.0.68"
88
clap = { version = "4.0.29", features = ["derive", "wrap_help"] }
9+
clap_complete_command = "0.6.1"
910
indicatif = { version = "0.17.1", features = ["rayon"] }
1011
itertools = "0.12.1"
1112
log = "0.4.0"

modkit/src/commands.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ pub enum Commands {
137137
#[clap(subcommand)]
138138
#[command(name = "open-chromatin", alias = "oc")]
139139
OpenChromatin(ochm::subcommand::OpenChromatin),
140+
#[command(hide = true)]
141+
GenerateShellCompletions {
142+
/// The shell to generate the completions for
143+
#[arg(value_enum)]
144+
shell: clap_complete_command::Shell,
145+
},
140146
}
141147

142148
impl Commands {
@@ -161,6 +167,18 @@ impl Commands {
161167
Self::BedMethyl(x) => x.run(),
162168
Self::ModBam(x) => x.run(),
163169
Self::OpenChromatin(x) => x.run(),
170+
Self::GenerateShellCompletions { shell } => {
171+
use clap::{CommandFactory as _, Parser};
172+
173+
#[derive(Parser)]
174+
#[command(name = "modkit")]
175+
struct Cli {
176+
#[command(subcommand)]
177+
command: Commands,
178+
}
179+
shell.generate(&mut Cli::command(), &mut std::io::stdout());
180+
Ok(())
181+
}
164182
}
165183
}
166184
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use common::run_modkit;
2+
3+
mod common;
4+
5+
#[test]
6+
fn test_generate_bash_completions() {
7+
let _out = run_modkit(&["generate-shell-completions", "bash"]).unwrap();
8+
}
9+
10+
#[test]
11+
fn test_generate_zsh_completions() {
12+
let _out = run_modkit(&["generate-shell-completions", "zsh"]).unwrap();
13+
}
14+
15+
#[test]
16+
fn test_generate_fish_completions() {
17+
let _out = run_modkit(&["generate-shell-completions", "fish"]).unwrap();
18+
}

0 commit comments

Comments
 (0)