Use a method to apply RustcOptGroup
to getopts::Options
This commit is contained in:
parent
8f7f9b93b2
commit
584c8200de
@ -937,7 +937,7 @@ fn usage(verbose: bool, include_unstable_options: bool, nightly_build: bool) {
|
|||||||
let groups = if verbose { config::rustc_optgroups() } else { config::rustc_short_optgroups() };
|
let groups = if verbose { config::rustc_optgroups() } else { config::rustc_short_optgroups() };
|
||||||
let mut options = getopts::Options::new();
|
let mut options = getopts::Options::new();
|
||||||
for option in groups.iter().filter(|x| include_unstable_options || x.is_stable()) {
|
for option in groups.iter().filter(|x| include_unstable_options || x.is_stable()) {
|
||||||
(option.apply)(&mut options);
|
option.apply(&mut options);
|
||||||
}
|
}
|
||||||
let message = "Usage: rustc [OPTIONS] INPUT";
|
let message = "Usage: rustc [OPTIONS] INPUT";
|
||||||
let nightly_help = if nightly_build {
|
let nightly_help = if nightly_build {
|
||||||
@ -1219,7 +1219,7 @@ pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<geto
|
|||||||
let mut options = getopts::Options::new();
|
let mut options = getopts::Options::new();
|
||||||
let optgroups = config::rustc_optgroups();
|
let optgroups = config::rustc_optgroups();
|
||||||
for option in &optgroups {
|
for option in &optgroups {
|
||||||
(option.apply)(&mut options);
|
option.apply(&mut options);
|
||||||
}
|
}
|
||||||
let matches = options.parse(args).unwrap_or_else(|e| {
|
let matches = options.parse(args).unwrap_or_else(|e| {
|
||||||
let msg: Option<String> = match e {
|
let msg: Option<String> = match e {
|
||||||
@ -1233,7 +1233,7 @@ pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<geto
|
|||||||
optgroups.iter().find(|option| option.name == opt).map(|option| {
|
optgroups.iter().find(|option| option.name == opt).map(|option| {
|
||||||
// Print the help just for the option in question.
|
// Print the help just for the option in question.
|
||||||
let mut options = getopts::Options::new();
|
let mut options = getopts::Options::new();
|
||||||
(option.apply)(&mut options);
|
option.apply(&mut options);
|
||||||
// getopt requires us to pass a function for joining an iterator of
|
// getopt requires us to pass a function for joining an iterator of
|
||||||
// strings, even though in this case we expect exactly one string.
|
// strings, even though in this case we expect exactly one string.
|
||||||
options.usage_with_format(|it| {
|
options.usage_with_format(|it| {
|
||||||
|
@ -102,7 +102,7 @@ fn new_public_extern_entry<S, I>(locations: I) -> ExternEntry
|
|||||||
fn optgroups() -> getopts::Options {
|
fn optgroups() -> getopts::Options {
|
||||||
let mut opts = getopts::Options::new();
|
let mut opts = getopts::Options::new();
|
||||||
for group in rustc_optgroups() {
|
for group in rustc_optgroups() {
|
||||||
(group.apply)(&mut opts);
|
group.apply(&mut opts);
|
||||||
}
|
}
|
||||||
return opts;
|
return opts;
|
||||||
}
|
}
|
||||||
|
@ -1373,7 +1373,7 @@ enum OptionStability {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct RustcOptGroup {
|
pub struct RustcOptGroup {
|
||||||
pub apply: Box<dyn Fn(&mut getopts::Options) -> &mut getopts::Options>,
|
apply: Box<dyn Fn(&mut getopts::Options) -> &mut getopts::Options>,
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
stability: OptionStability,
|
stability: OptionStability,
|
||||||
}
|
}
|
||||||
@ -1383,6 +1383,10 @@ pub fn is_stable(&self) -> bool {
|
|||||||
self.stability == OptionStability::Stable
|
self.stability == OptionStability::Stable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn apply(&self, options: &mut getopts::Options) {
|
||||||
|
(self.apply)(options);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn stable<F>(name: &'static str, f: F) -> RustcOptGroup
|
pub fn stable<F>(name: &'static str, f: F) -> RustcOptGroup
|
||||||
where
|
where
|
||||||
F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static,
|
F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static,
|
||||||
|
@ -685,7 +685,7 @@ fn opts() -> Vec<RustcOptGroup> {
|
|||||||
fn usage(argv0: &str) {
|
fn usage(argv0: &str) {
|
||||||
let mut options = getopts::Options::new();
|
let mut options = getopts::Options::new();
|
||||||
for option in opts() {
|
for option in opts() {
|
||||||
(option.apply)(&mut options);
|
option.apply(&mut options);
|
||||||
}
|
}
|
||||||
println!("{}", options.usage(&format!("{argv0} [options] <input>")));
|
println!("{}", options.usage(&format!("{argv0} [options] <input>")));
|
||||||
println!(" @path Read newline separated options from `path`\n");
|
println!(" @path Read newline separated options from `path`\n");
|
||||||
@ -769,7 +769,7 @@ fn main_args(
|
|||||||
|
|
||||||
let mut options = getopts::Options::new();
|
let mut options = getopts::Options::new();
|
||||||
for option in opts() {
|
for option in opts() {
|
||||||
(option.apply)(&mut options);
|
option.apply(&mut options);
|
||||||
}
|
}
|
||||||
let matches = match options.parse(&args) {
|
let matches = match options.parse(&args) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
|
Loading…
Reference in New Issue
Block a user