Skip to content

Commit

Permalink
feat(cli): Support for tab completion
Browse files Browse the repository at this point in the history
  • Loading branch information
woodruffw committed Nov 28, 2021
1 parent 0e98c0e commit c9132c3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
7 changes: 7 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub enum Command {
setting = structopt::clap::AppSettings::DontCollapseArgsInUsage
)]
Release(ReleaseOpt),
Completions(CompletionsOpt),
}

#[derive(Debug, StructOpt)]
Expand Down Expand Up @@ -222,3 +223,9 @@ fn resolve_bool_arg(yes: bool, no: bool) -> Option<bool> {
(_, _) => unreachable!("StructOpt should make this impossible"),
}
}

#[derive(StructOpt, Debug, Clone)]
pub struct CompletionsOpt {
#[structopt(long, short = "s", possible_values = &clap::Shell::variants(), case_insensitive = true)]
pub shell: clap::Shell,
}
31 changes: 20 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::collections::HashMap;
use std::collections::HashSet;
use std::ffi::OsStr;
use std::io::Write;
use std::io::{self, Write};
use std::path::Path;
use std::process::exit;

Expand All @@ -27,16 +27,25 @@ use crate::replace::{do_file_replacements, Template};
use crate::version::VersionExt;

fn main() {
let args::Command::Release(ref release_matches) = args::Command::from_args();

let mut builder = get_logging(release_matches.logging.log_level());
builder.init();

match release_workspace(release_matches) {
Ok(code) => exit(code),
Err(e) => {
log::error!("Fatal: {}", e);
exit(128);
match args::Command::from_args() {
args::Command::Release(ref release_matches) => {
let mut builder = get_logging(release_matches.logging.log_level());
builder.init();

match release_workspace(release_matches) {
Ok(code) => exit(code),
Err(e) => {
log::error!("Fatal: {}", e);
exit(128);
}
}
}
args::Command::Completions(ref completion_matches) => {
args::Command::clap().gen_completions_to(
"cargo-release",
completion_matches.shell,
&mut io::stdout(),
);
}
}
}
Expand Down

0 comments on commit c9132c3

Please sign in to comment.