Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
d64f18c4
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d64f18c4
编写于
6月 14, 2014
作者:
B
bors
浏览文件
操作
浏览文件
下载
差异文件
auto merge of #14884 : huonw/rust/getoptsfail, r=alexcrichton
上级
dbd29ea9
09eb95f2
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
39 addition
and
32 deletion
+39
-32
src/compiletest/compiletest.rs
src/compiletest/compiletest.rs
+1
-1
src/libgetopts/lib.rs
src/libgetopts/lib.rs
+32
-24
src/librustc/driver/config.rs
src/librustc/driver/config.rs
+2
-3
src/librustc/driver/mod.rs
src/librustc/driver/mod.rs
+1
-1
src/librustdoc/lib.rs
src/librustdoc/lib.rs
+1
-1
src/libtest/lib.rs
src/libtest/lib.rs
+1
-1
src/test/run-pass/getopts_ref.rs
src/test/run-pass/getopts_ref.rs
+1
-1
未找到文件。
src/compiletest/compiletest.rs
浏览文件 @
d64f18c4
...
...
@@ -110,7 +110,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {
let
matches
=
&
match
getopts
::
getopts
(
args_
.as_slice
(),
groups
.as_slice
())
{
Ok
(
m
)
=>
m
,
Err
(
f
)
=>
fail
!
(
"{}"
,
f
.to_err_msg
()
)
Err
(
f
)
=>
fail
!
(
"{}"
,
f
)
};
if
matches
.opt_present
(
"h"
)
||
matches
.opt_present
(
"help"
)
{
...
...
src/libgetopts/lib.rs
浏览文件 @
d64f18c4
...
...
@@ -61,7 +61,7 @@
//! ];
//! let matches = match getopts(args.tail(), opts) {
//! Ok(m) => { m }
//! Err(f) => { fail!(f.to_
err_msg
()) }
//! Err(f) => { fail!(f.to_
str
()) }
//! };
//! if matches.opt_present("h") {
//! print_usage(program.as_slice(), opts);
...
...
@@ -94,12 +94,13 @@
#[cfg(test,
not(stage0))]
#[phase(plugin,
link)]
extern
crate
log
;
use
std
::
cmp
::
PartialEq
;
use
std
::
fmt
;
use
std
::
result
::{
Err
,
Ok
};
use
std
::
result
;
use
std
::
string
::
String
;
/// Name of an option. Either a string or a single char.
#[deriving(Clone,
PartialEq)]
#[deriving(Clone,
PartialEq
,
Eq
)]
pub
enum
Name
{
/// A string representing the long name of an option.
/// For example: "help"
...
...
@@ -110,7 +111,7 @@ pub enum Name {
}
/// Describes whether an option has an argument.
#[deriving(Clone,
PartialEq)]
#[deriving(Clone,
PartialEq
,
Eq
)]
pub
enum
HasArg
{
/// The option requires an argument.
Yes
,
...
...
@@ -121,7 +122,7 @@ pub enum HasArg {
}
/// Describes how often an option may occur.
#[deriving(Clone,
PartialEq)]
#[deriving(Clone,
PartialEq
,
Eq
)]
pub
enum
Occur
{
/// The option occurs once.
Req
,
...
...
@@ -132,7 +133,7 @@ pub enum Occur {
}
/// A description of a possible option.
#[deriving(Clone,
PartialEq)]
#[deriving(Clone,
PartialEq
,
Eq
)]
pub
struct
Opt
{
/// Name of the option
pub
name
:
Name
,
...
...
@@ -141,12 +142,12 @@ pub struct Opt {
/// How often it can occur
pub
occur
:
Occur
,
/// Which options it aliases
pub
aliases
:
Vec
<
Opt
>
,
pub
aliases
:
Vec
<
Opt
>
,
}
/// One group of options, e.g., both -h and --help, along with
/// their shared description and properties.
#[deriving(Clone,
PartialEq)]
#[deriving(Clone,
PartialEq
,
Eq
)]
pub
struct
OptGroup
{
/// Short Name of the `OptGroup`
pub
short_name
:
String
,
...
...
@@ -163,7 +164,7 @@ pub struct OptGroup {
}
/// Describes whether an option is given at all or has a value.
#[deriving(Clone,
PartialEq)]
#[deriving(Clone,
PartialEq
,
Eq
)]
enum
Optval
{
Val
(
String
),
Given
,
...
...
@@ -171,20 +172,20 @@ enum Optval {
/// The result of checking command line arguments. Contains a vector
/// of matches and a vector of free strings.
#[deriving(Clone,
PartialEq)]
#[deriving(Clone,
PartialEq
,
Eq
)]
pub
struct
Matches
{
/// Options that matched
opts
:
Vec
<
Opt
>
,
opts
:
Vec
<
Opt
>
,
/// Values of the Options that matched
vals
:
Vec
<
Vec
<
Optval
>
>
,
vals
:
Vec
<
Vec
<
Optval
>
>
,
/// Free string fragments
pub
free
:
Vec
<
String
>
,
}
/// The type returned when the command line does not conform to the
/// expected format.
Call the `to_err_msg` method to retrieve the
///
error as a string
.
#[deriving(Clone,
PartialEq,
Show
)]
/// expected format.
Use the `Show` implementation to output detailed
///
information
.
#[deriving(Clone,
PartialEq,
Eq
)]
pub
enum
Fail_
{
/// The option requires an argument but none was passed.
ArgumentMissing
(
String
),
...
...
@@ -199,7 +200,7 @@ pub enum Fail_ {
}
/// The type of failure that occurred.
#[deriving(PartialEq)]
#[deriving(PartialEq
,
Eq
)]
#[allow(missing_doc)]
pub
enum
FailType
{
ArgumentMissing_
,
...
...
@@ -498,22 +499,29 @@ pub fn opt(short_name: &str,
impl
Fail_
{
/// Convert a `Fail_` enum into an error string.
#[deprecated=
"use `Show` (`{}` format specifier)"
]
pub
fn
to_err_msg
(
self
)
->
String
{
match
self
{
self
.to_str
()
}
}
impl
fmt
::
Show
for
Fail_
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
match
*
self
{
ArgumentMissing
(
ref
nm
)
=>
{
format!
(
"Argument to option '{}' missing."
,
*
nm
)
write!
(
f
,
"Argument to option '{}' missing."
,
*
nm
)
}
UnrecognizedOption
(
ref
nm
)
=>
{
format!
(
"Unrecognized option: '{}'."
,
*
nm
)
write!
(
f
,
"Unrecognized option: '{}'."
,
*
nm
)
}
OptionMissing
(
ref
nm
)
=>
{
format!
(
"Required option '{}' missing."
,
*
nm
)
write!
(
f
,
"Required option '{}' missing."
,
*
nm
)
}
OptionDuplicated
(
ref
nm
)
=>
{
format!
(
"Option '{}' given more than once."
,
*
nm
)
write!
(
f
,
"Option '{}' given more than once."
,
*
nm
)
}
UnexpectedArgument
(
ref
nm
)
=>
{
format!
(
"Option '{}' does not take an argument."
,
*
nm
)
write!
(
f
,
"Option '{}' does not take an argument."
,
*
nm
)
}
}
}
...
...
@@ -522,8 +530,9 @@ pub fn to_err_msg(self) -> String {
/// Parse command line arguments according to the provided options.
///
/// On success returns `Ok(Opt)`. Use methods such as `opt_present`
/// `opt_str`, etc. to interrogate results. Returns `Err(Fail_)` on failure.
/// Use `to_err_msg` to get an error message.
/// `opt_str`, etc. to interrogate results. Returns `Err(Fail_)` on
/// failure: use the `Show` implementation of `Fail_` to display
/// information about it.
pub
fn
getopts
(
args
:
&
[
String
],
optgrps
:
&
[
OptGroup
])
->
Result
{
let
opts
:
Vec
<
Opt
>
=
optgrps
.iter
()
.map
(|
x
|
x
.long_to_short
())
.collect
();
let
n_opts
=
opts
.len
();
...
...
@@ -1110,7 +1119,6 @@ fn test_optflag_long_arg() {
let
rs
=
getopts
(
args
.as_slice
(),
opts
.as_slice
());
match
rs
{
Err
(
f
)
=>
{
error!
(
"{:?}"
,
f
.clone
()
.to_err_msg
());
check_fail_type
(
f
,
UnexpectedArgument_
);
}
_
=>
fail
!
()
...
...
src/librustc/driver/config.rs
浏览文件 @
d64f18c4
...
...
@@ -792,7 +792,7 @@ fn test_switch_implies_cfg_test() {
let
matches
=
&
match
getopts
([
"--test"
.to_string
()],
optgroups
()
.as_slice
())
{
Ok
(
m
)
=>
m
,
Err
(
f
)
=>
fail
!
(
"test_switch_implies_cfg_test: {}"
,
f
.to_err_msg
()
)
Err
(
f
)
=>
fail
!
(
"test_switch_implies_cfg_test: {}"
,
f
)
};
let
sessopts
=
build_session_options
(
matches
);
let
sess
=
build_session
(
sessopts
,
None
);
...
...
@@ -809,8 +809,7 @@ fn test_switch_implies_cfg_test_unless_cfg_test() {
optgroups
()
.as_slice
())
{
Ok
(
m
)
=>
m
,
Err
(
f
)
=>
{
fail
!
(
"test_switch_implies_cfg_test_unless_cfg_test: {}"
,
f
.to_err_msg
());
fail
!
(
"test_switch_implies_cfg_test_unless_cfg_test: {}"
,
f
)
}
};
let
sessopts
=
build_session_options
(
matches
);
...
...
src/librustc/driver/mod.rs
浏览文件 @
d64f18c4
...
...
@@ -205,7 +205,7 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
match
getopts
::
getopts
(
args
.as_slice
(),
config
::
optgroups
()
.as_slice
())
{
Ok
(
m
)
=>
m
,
Err
(
f
)
=>
{
early_error
(
f
.to_
err_msg
()
.as_slice
());
early_error
(
f
.to_
str
()
.as_slice
());
}
};
...
...
src/librustdoc/lib.rs
浏览文件 @
d64f18c4
...
...
@@ -148,7 +148,7 @@ pub fn main_args(args: &[String]) -> int {
let
matches
=
match
getopts
::
getopts
(
args
.tail
(),
opts
()
.as_slice
())
{
Ok
(
m
)
=>
m
,
Err
(
err
)
=>
{
println!
(
"{}"
,
err
.to_err_msg
()
);
println!
(
"{}"
,
err
);
return
1
;
}
};
...
...
src/libtest/lib.rs
浏览文件 @
d64f18c4
...
...
@@ -367,7 +367,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
let
matches
=
match
getopts
::
getopts
(
args_
.as_slice
(),
optgroups
()
.as_slice
())
{
Ok
(
m
)
=>
m
,
Err
(
f
)
=>
return
Some
(
Err
(
f
.to_
err_msg
()
.to_string
()))
Err
(
f
)
=>
return
Some
(
Err
(
f
.to_
str
()))
};
if
matches
.opt_present
(
"h"
)
{
usage
(
args
[
0
]
.as_slice
());
return
None
;
}
...
...
src/test/run-pass/getopts_ref.rs
浏览文件 @
d64f18c4
...
...
@@ -20,7 +20,7 @@ pub fn main() {
match
getopts
(
args
.as_slice
(),
opts
.as_slice
())
{
Ok
(
ref
m
)
=>
assert
!
(
!
m
.opt_present
(
"b"
)),
Err
(
ref
f
)
=>
fail
!
(
"{
:?}"
,
(
*
f
)
.clone
()
.to_err_msg
()
)
Err
(
ref
f
)
=>
fail
!
(
"{
}"
,
*
f
)
};
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录