Skip to content

Commit

Permalink
Add shell completion subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
ede1998 committed Nov 1, 2024
1 parent 555cde0 commit b4c5b4b
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 23 deletions.
134 changes: 112 additions & 22 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions fclones/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ bytesize = "1.1"
byte-unit = "4.0"
chrono = { version = "0.4", default-features = false, features = ["serde", "clock", "std"] }
clap = { version = "4.4", features = ["derive", "cargo", "wrap_help"] }
clap_complete = { version = "4.5.36" }
console = "0.15"
crossbeam-channel = "0.5"
crossbeam-utils = "0.8"
Expand Down
6 changes: 6 additions & 0 deletions fclones/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,12 @@ pub enum Command {
#[arg()]
target: PathBuf,
},

/// Print shell completion script to stdout.
Complete {
/// Shell for which the completion script is generated.
shell: clap_complete::aot::Shell,
},
}

impl Command {
Expand Down
13 changes: 12 additions & 1 deletion fclones/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::process::exit;
use std::sync::Arc;
use std::{fs, io};

use clap::Parser;
use clap::{CommandFactory, Parser};
use console::style;
use fallible_iterator::FallibleIterator;
use itertools::Itertools;
Expand Down Expand Up @@ -283,6 +283,17 @@ fn main() {
let target = Arc::new(fclones::Path::from(cwd)).resolve(target);
run_dedupe(DedupeOp::Move(Arc::new(target)), config, &log)
}
Command::Complete { shell } => {
clap_complete::generate(
shell,
&mut Config::command(),
std::env::args()
.next()
.unwrap_or_else(|| "fclones".to_owned()),
&mut std::io::stdout(),
);
Ok(())
}
};

if let Err(e) = result {
Expand Down

0 comments on commit b4c5b4b

Please sign in to comment.