Skip to content
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

getopts #1289 + cleanup after the std/core split #1312

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/comp/driver/rustc.rs
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ import syntax::print::{pp, pprust};
import util::{ppaux, filesearch};
import back::link;
import core::{option, str, vec, int, result};
import result::{ok, err};
import std::{fs, io, getopts};
import option::{some, none};
import getopts::{optopt, optmulti, optflag, optflagopt, opt_present};
@@ -623,8 +624,8 @@ fn main(args: [str]) {
let args = args, binary = vec::shift(args);
let match =
alt getopts::getopts(args, opts()) {
getopts::success(m) { m }
getopts::failure(f) {
ok(m) { m }
err(f) {
early_error(getopts::fail_str(f))
}
};
@@ -673,7 +674,7 @@ mod test {
fn test_switch_implies_cfg_test() {
let match =
alt getopts::getopts(["--test"], opts()) {
getopts::success(m) { m }
ok(m) { m }
};
let sessopts = build_session_options(match);
let sess = build_session(sessopts);
@@ -687,7 +688,7 @@ mod test {
fn test_switch_implies_cfg_test_unless_cfg_test() {
let match =
alt getopts::getopts(["--test", "--cfg=test"], opts()) {
getopts::success(m) { m }
ok(m) { m }
};
let sessopts = build_session_options(match);
let sess = build_session(sessopts);
7 changes: 5 additions & 2 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
@@ -9,6 +9,9 @@ import str;
import vec;
import task;

import core::result;
import result::{ok, err};

import comm::port;
import comm::chan;
import comm::send;
@@ -42,8 +45,8 @@ fn parse_config(args: [str]) -> config {
let args_ = vec::tail(args);
let match =
alt getopts::getopts(args_, opts) {
getopts::success(m) { m }
getopts::failure(f) { fail getopts::fail_str(f) }
ok(m) { m }
err(f) { fail getopts::fail_str(f) }
};

ret {compile_lib_path: getopts::opt_str(match, "compile-lib-path"),
71 changes: 0 additions & 71 deletions src/libstd/cmath.rs

This file was deleted.

146 changes: 0 additions & 146 deletions src/libstd/ctypes.rs

This file was deleted.

36 changes: 18 additions & 18 deletions src/libstd/getopts.rs
Original file line number Diff line number Diff line change
@@ -26,8 +26,8 @@ name following -o, and accepts both -h and --help as optional flags.
> optflag("help")
> ];
> let match = alt getopts(vec::shift(args), opts) {
> success(m) { m }
> failure(f) { fail fail_str(f) }
> ok(m) { m }
> err(f) { fail fail_str(f) }
> };
> if opt_present(match, "h") || opt_present(match, "help") {
> print_usage();
@@ -45,18 +45,17 @@ name following -o, and accepts both -h and --help as optional flags.

*/

import core::result;
import core::result::{err, ok};
import core::option;
import option::{some, none};
import core::option::{some, none};
export opt;
export reqopt;
export optopt;
export optflag;
export optflagopt;
export optmulti;
export getopts;
export result;
export success;
export failure;
export match;
export fail_;
export fail_str;
@@ -193,13 +192,14 @@ fn fail_str(f: fail_) -> str {
Type: result

The result of parsing a command line with a set of options
(result::t<match, fail_>)

Variants:

success(match) - Returned from getopts on success
failure(fail_) - Returned from getopts on failure
ok(match) - Returned from getopts on success
err(fail_) - Returned from getopts on failure
*/
tag result { success(match); failure(fail_); }
type result = result::t<match, fail_>;

/*
Function: getopts
@@ -208,9 +208,9 @@ Parse command line arguments according to the provided options

Returns:

success(match) - On success. Use functions such as <opt_present>
<opt_str>, etc. to interrogate results.
failure(fail_) - On failure. Use <fail_str> to get an error message.
ok(match) - On success. Use functions such as <opt_present>
<opt_str>, etc. to interrogate results.
err(fail_) - On failure. Use <fail_str> to get an error message.
*/
fn getopts(args: [str], opts: [opt]) -> result {
let n_opts = vec::len::<opt>(opts);
@@ -258,12 +258,12 @@ fn getopts(args: [str], opts: [opt]) -> result {
let optid;
alt find_opt(opts, nm) {
some(id) { optid = id; }
none. { ret failure(unrecognized_option(name_str(nm))); }
none. { ret err(unrecognized_option(name_str(nm))); }
}
alt opts[optid].hasarg {
no. {
if !option::is_none::<str>(i_arg) {
ret failure(unexpected_argument(name_str(nm)));
ret err(unexpected_argument(name_str(nm)));
}
vals[optid] += [given];
}
@@ -279,7 +279,7 @@ fn getopts(args: [str], opts: [opt]) -> result {
if !option::is_none::<str>(i_arg) {
vals[optid] += [val(option::get::<str>(i_arg))];
} else if i + 1u == l {
ret failure(argument_missing(name_str(nm)));
ret err(argument_missing(name_str(nm)));
} else { i += 1u; vals[optid] += [val(args[i])]; }
}
}
@@ -293,17 +293,17 @@ fn getopts(args: [str], opts: [opt]) -> result {
let occ = opts[i].occur;
if occ == req {
if n == 0u {
ret failure(option_missing(name_str(opts[i].name)));
ret err(option_missing(name_str(opts[i].name)));
}
}
if occ != multi {
if n > 1u {
ret failure(option_duplicated(name_str(opts[i].name)));
ret err(option_duplicated(name_str(opts[i].name)));
}
}
i += 1u;
}
ret success({opts: opts, vals: vals, free: free});
ret ok({opts: opts, vals: vals, free: free});
}

fn opt_vals(m: match, nm: str) -> [optval] {
Loading