getopts: replaced base functions with those from group

This commit is contained in:
Arcterus 2014-02-03 19:14:40 -08:00
parent 9752c63035
commit c09ca940e5
8 changed files with 467 additions and 509 deletions

View File

@ -20,7 +20,7 @@ use std::os;
use std::io;
use std::io::fs;
use getopts::groups::{optopt, optflag, reqopt};
use getopts::{optopt, optflag, reqopt};
use extra::test;
use common::config;
@ -49,7 +49,7 @@ pub fn main() {
pub fn parse_config(args: ~[~str]) -> config {
let groups : ~[getopts::groups::OptGroup] =
let groups : ~[getopts::OptGroup] =
~[reqopt("", "compile-lib-path", "path to host shared libraries", "PATH"),
reqopt("", "run-lib-path", "path to target shared libraries", "PATH"),
reqopt("", "rustc-path", "path to rustc to use for compiling", "PATH"),
@ -85,20 +85,20 @@ pub fn parse_config(args: ~[~str]) -> config {
let args_ = args.tail();
if args[1] == ~"-h" || args[1] == ~"--help" {
let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0);
println!("{}", getopts::groups::usage(message, groups));
println!("{}", getopts::usage(message, groups));
println!("");
fail!()
}
let matches =
&match getopts::groups::getopts(args_, groups) {
&match getopts::getopts(args_, groups) {
Ok(m) => m,
Err(f) => fail!("{}", f.to_err_msg())
};
if matches.opt_present("h") || matches.opt_present("help") {
let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0);
println!("{}", getopts::groups::usage(message, groups));
println!("{}", getopts::usage(message, groups));
println!("");
fail!()
}

View File

@ -17,7 +17,6 @@
extern mod term;
use getopts::groups;
use getopts;
use json::ToJson;
use json;
@ -209,29 +208,29 @@ pub struct TestOpts {
/// Result of parsing the options.
pub type OptRes = Result<TestOpts, ~str>;
fn optgroups() -> ~[getopts::groups::OptGroup] {
~[groups::optflag("", "ignored", "Run ignored tests"),
groups::optflag("", "test", "Run tests and not benchmarks"),
groups::optflag("", "bench", "Run benchmarks instead of tests"),
groups::optflag("h", "help", "Display this message (longer with --help)"),
groups::optopt("", "save-metrics", "Location to save bench metrics",
fn optgroups() -> ~[getopts::OptGroup] {
~[getopts::optflag("", "ignored", "Run ignored tests"),
getopts::optflag("", "test", "Run tests and not benchmarks"),
getopts::optflag("", "bench", "Run benchmarks instead of tests"),
getopts::optflag("h", "help", "Display this message (longer with --help)"),
getopts::optopt("", "save-metrics", "Location to save bench metrics",
"PATH"),
groups::optopt("", "ratchet-metrics",
getopts::optopt("", "ratchet-metrics",
"Location to load and save metrics from. The metrics \
loaded are cause benchmarks to fail if they run too \
slowly", "PATH"),
groups::optopt("", "ratchet-noise-percent",
getopts::optopt("", "ratchet-noise-percent",
"Tests within N% of the recorded metrics will be \
considered as passing", "PERCENTAGE"),
groups::optopt("", "logfile", "Write logs to the specified file instead \
getopts::optopt("", "logfile", "Write logs to the specified file instead \
of stdout", "PATH"),
groups::optopt("", "test-shard", "run shard A, of B shards, worth of the testsuite",
getopts::optopt("", "test-shard", "run shard A, of B shards, worth of the testsuite",
"A.B")]
}
fn usage(binary: &str, helpstr: &str) {
let message = format!("Usage: {} [OPTIONS] [FILTER]", binary);
println!("{}", groups::usage(message, optgroups()));
println!("{}", getopts::usage(message, optgroups()));
println!("");
if helpstr == "help" {
println!("{}", "\
@ -261,7 +260,7 @@ Test Attributes:
pub fn parse_opts(args: &[~str]) -> Option<OptRes> {
let args_ = args.tail();
let matches =
match groups::getopts(args_, optgroups()) {
match getopts::getopts(args_, optgroups()) {
Ok(m) => m,
Err(f) => return Some(Err(f.to_err_msg()))
};

File diff suppressed because it is too large Load Diff

View File

@ -34,7 +34,7 @@ use std::io::fs;
use std::io::MemReader;
use std::os;
use std::vec;
use getopts::groups::{optopt, optmulti, optflag, optflagopt};
use getopts::{optopt, optmulti, optflag, optflagopt};
use getopts;
use syntax::ast;
use syntax::abi;
@ -992,7 +992,7 @@ pub fn parse_pretty(sess: Session, name: &str) -> PpMode {
}
// rustc command line options
pub fn optgroups() -> ~[getopts::groups::OptGroup] {
pub fn optgroups() -> ~[getopts::OptGroup] {
~[
optflag("c", "", "Compile and assemble, but do not link"),
optmulti("", "cfg", "Configure the compilation
@ -1188,7 +1188,7 @@ mod test {
use driver::driver::{build_configuration, build_session};
use driver::driver::{build_session_options, optgroups};
use getopts::groups::getopts;
use getopts::getopts;
use syntax::attr;
use syntax::attr::AttrMetaMethods;
use syntax::diagnostic;

View File

@ -51,7 +51,6 @@ use std::os;
use std::str;
use std::task;
use std::vec;
use getopts::groups;
use syntax::ast;
use syntax::attr;
use syntax::diagnostic::Emitter;
@ -142,7 +141,7 @@ pub fn usage(argv0: &str) {
Additional help:
-W help Print 'lint' options and default settings
-Z help Print internal options for debugging rustc\n",
groups::usage(message, d::optgroups()));
getopts::usage(message, d::optgroups()));
}
pub fn describe_warnings() {
@ -201,7 +200,7 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
if args.is_empty() { usage(binary); return; }
let matches =
&match getopts::groups::getopts(args, d::optgroups()) {
&match getopts::getopts(args, d::optgroups()) {
Ok(m) => m,
Err(f) => {
d::early_error(demitter, f.to_err_msg());

View File

@ -24,8 +24,7 @@ use middle::ty::{FnTyBase, FnMeta, FnSig};
use util::ppaux::ty_to_str;
use extra::oldmap::HashMap;
use getopts::groups::{optopt, optmulti, optflag, optflagopt, getopts};
use getopts::groups;
use getopts::{optopt, optmulti, optflag, optflagopt, getopts};
use getopts::opt_present;
use syntax::codemap::DUMMY_SP;
use syntax::parse::parse_crate_from_source_str;

View File

@ -29,7 +29,6 @@ use std::str;
use extra::json;
use serialize::{Decodable, Encodable};
use extra::time;
use getopts::groups;
pub mod clean;
pub mod core;
@ -80,8 +79,8 @@ pub fn main() {
std::os::set_exit_status(main_args(std::os::args()));
}
pub fn opts() -> ~[groups::OptGroup] {
use getopts::groups::*;
pub fn opts() -> ~[getopts::OptGroup] {
use getopts::*;
~[
optflag("h", "help", "show this help message"),
optflag("", "version", "print rustdoc's version"),
@ -107,11 +106,11 @@ pub fn opts() -> ~[groups::OptGroup] {
}
pub fn usage(argv0: &str) {
println!("{}", groups::usage(format!("{} [options] <input>", argv0), opts()));
println!("{}", getopts::usage(format!("{} [options] <input>", argv0), opts()));
}
pub fn main_args(args: &[~str]) -> int {
let matches = match groups::getopts(args.tail(), opts()) {
let matches = match getopts::getopts(args.tail(), opts()) {
Ok(m) => m,
Err(err) => {
println!("{}", err.to_err_msg());

View File

@ -16,7 +16,7 @@ use getopts::{optopt, getopts};
pub fn main() {
let args = ~[];
let opts = ~[optopt("b")];
let opts = ~[optopt("b", "", "something", "SMTHNG")];
match getopts(args, opts) {
Ok(ref m) =>