-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for tab completion #360
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ pub enum Command { | |
setting = structopt::clap::AppSettings::DontCollapseArgsInUsage | ||
)] | ||
Release(ReleaseOpt), | ||
Completions(CompletionsOpt), | ||
} | ||
|
||
#[derive(Debug, StructOpt)] | ||
|
@@ -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)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any particular reason you did case insensitive? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, no particular reason. If I had to contrive one, people might do |
||
pub shell: clap::Shell, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
|
@@ -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(), | ||
); | ||
Comment on lines
+44
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How should we document this capability, including giving the example code you had in the R? We could probably put it in the long help for the command. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, perhaps an FAQ entry? The example I included in the top comment is extremely specific to We could also do it in the "reference" docs, although those seem to cover just the |
||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come you did it at this level? I'm assuming most people will be running
cargo-release
ascargo release
and notcargo-release
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put it at the top-level since that's how
rustup
and a few other tools in the Rust packaging/toolchain ecosystem do it. My argument for that would be thatcargo release
is how people should be running it interactively, butcargo-release completions [...]
makes more sense in the context of a shell profile (to emphasize that the completions are coming from justcargo-release
and that they aren't hooked up to thecargo
completions yet).