Skip to content

Commit a58f6bb

Browse files
committed
Rename message-format flag to json
1 parent ef94f46 commit a58f6bb

File tree

10 files changed

+34
-69
lines changed

10 files changed

+34
-69
lines changed

src/bin/bench.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use cargo::core::Workspace;
2-
use cargo::ops;
2+
use cargo::ops::{self, MessageFormat};
33
use cargo::util::{CliResult, CliError, Human, Config, human};
44
use cargo::util::important_paths::{find_root_manifest_for_wd};
55

@@ -16,7 +16,7 @@ pub struct Options {
1616
flag_verbose: u32,
1717
flag_quiet: Option<bool>,
1818
flag_color: Option<String>,
19-
flag_message_format: Option<String>,
19+
flag_message_format: MessageFormat,
2020
flag_lib: bool,
2121
flag_bin: Vec<String>,
2222
flag_example: Vec<String>,
@@ -51,7 +51,7 @@ Options:
5151
-v, --verbose ... Use verbose output
5252
-q, --quiet No output printed to stdout
5353
--color WHEN Coloring: auto, always, never
54-
--message-format FMT Error format: human, json-v1
54+
--message-format FMT Error format: human, json [default: human]
5555
--frozen Require Cargo.lock and cache are up to date
5656
--locked Require Cargo.lock is up to date
5757
@@ -77,9 +77,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
7777
&options.flag_color,
7878
options.flag_frozen,
7979
options.flag_locked));
80-
let message_format = try!(ops::MessageFormat::from_option(
81-
&options.flag_message_format
82-
));
8380
let ops = ops::TestOptions {
8481
no_run: options.flag_no_run,
8582
no_fail_fast: false,
@@ -100,7 +97,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
10097
&options.flag_test,
10198
&options.flag_example,
10299
&options.flag_bench),
103-
message_format: message_format,
100+
message_format: options.flag_message_format,
104101
target_rustdoc_args: None,
105102
target_rustc_args: None,
106103
},

src/bin/build.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use std::env;
22

33
use cargo::core::Workspace;
4-
use cargo::ops::CompileOptions;
5-
use cargo::ops;
4+
use cargo::ops::{self, CompileOptions, MessageFormat};
65
use cargo::util::important_paths::{find_root_manifest_for_wd};
76
use cargo::util::{CliResult, Config};
87

@@ -18,7 +17,7 @@ pub struct Options {
1817
flag_verbose: u32,
1918
flag_quiet: Option<bool>,
2019
flag_color: Option<String>,
21-
flag_message_format: Option<String>,
20+
flag_message_format: MessageFormat,
2221
flag_release: bool,
2322
flag_lib: bool,
2423
flag_bin: Vec<String>,
@@ -53,7 +52,7 @@ Options:
5352
-v, --verbose ... Use verbose output
5453
-q, --quiet No output printed to stdout
5554
--color WHEN Coloring: auto, always, never
56-
--message-format FMT Error format: human, json-v1
55+
--message-format FMT Error format: human, json [default: human]
5756
--frozen Require Cargo.lock and cache are up to date
5857
--locked Require Cargo.lock is up to date
5958
@@ -75,9 +74,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
7574
&options.flag_color,
7675
options.flag_frozen,
7776
options.flag_locked));
78-
let message_format = try!(ops::MessageFormat::from_option(
79-
&options.flag_message_format
80-
));
8177

8278
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
8379

@@ -97,7 +93,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
9793
&options.flag_test,
9894
&options.flag_example,
9995
&options.flag_bench),
100-
message_format: message_format,
96+
message_format: options.flag_message_format,
10197
target_rustdoc_args: None,
10298
target_rustc_args: None,
10399
};

src/bin/doc.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use cargo::core::Workspace;
2-
use cargo::ops;
2+
use cargo::ops::{self, MessageFormat};
33
use cargo::util::{CliResult, Config};
44
use cargo::util::important_paths::{find_root_manifest_for_wd};
55

@@ -17,7 +17,7 @@ pub struct Options {
1717
flag_verbose: u32,
1818
flag_quiet: Option<bool>,
1919
flag_color: Option<String>,
20-
flag_message_format: Option<String>,
20+
flag_message_format: MessageFormat,
2121
flag_package: Vec<String>,
2222
flag_lib: bool,
2323
flag_bin: Vec<String>,
@@ -48,7 +48,7 @@ Options:
4848
-v, --verbose ... Use verbose output
4949
-q, --quiet No output printed to stdout
5050
--color WHEN Coloring: auto, always, never
51-
--message-format FMT Error format: human, json-v1
51+
--message-format FMT Error format: human, json [default: human]
5252
--frozen Require Cargo.lock and cache are up to date
5353
--locked Require Cargo.lock is up to date
5454
@@ -67,9 +67,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
6767
&options.flag_color,
6868
options.flag_frozen,
6969
options.flag_locked));
70-
let message_format = try!(ops::MessageFormat::from_option(
71-
&options.flag_message_format
72-
));
7370

7471
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
7572

@@ -90,7 +87,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
9087
&empty,
9188
&empty,
9289
&empty),
93-
message_format: message_format,
90+
message_format: options.flag_message_format,
9491
release: options.flag_release,
9592
mode: ops::CompileMode::Doc {
9693
deps: !options.flag_no_deps,

src/bin/run.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use cargo::core::Workspace;
2-
use cargo::ops;
2+
use cargo::ops::{self, MessageFormat};
33
use cargo::util::{CliResult, CliError, Config, Human};
44
use cargo::util::important_paths::{find_root_manifest_for_wd};
55

@@ -16,7 +16,7 @@ pub struct Options {
1616
flag_verbose: u32,
1717
flag_quiet: Option<bool>,
1818
flag_color: Option<String>,
19-
flag_message_format: Option<String>,
19+
flag_message_format: MessageFormat,
2020
flag_release: bool,
2121
flag_frozen: bool,
2222
flag_locked: bool,
@@ -43,7 +43,7 @@ Options:
4343
-v, --verbose ... Use verbose output
4444
-q, --quiet No output printed to stdout
4545
--color WHEN Coloring: auto, always, never
46-
--message-format FMT Error format: human, json-v1
46+
--message-format FMT Error format: human, json [default: human]
4747
--frozen Require Cargo.lock and cache are up to date
4848
--locked Require Cargo.lock is up to date
4949
@@ -63,9 +63,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
6363
&options.flag_color,
6464
options.flag_frozen,
6565
options.flag_locked));
66-
let message_format = try!(ops::MessageFormat::from_option(
67-
&options.flag_message_format
68-
));
6966

7067
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
7168

@@ -96,7 +93,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
9693
bins: &bins, examples: &examples,
9794
}
9895
},
99-
message_format: message_format,
96+
message_format: options.flag_message_format,
10097
target_rustdoc_args: None,
10198
target_rustc_args: None,
10299
};

src/bin/rustc.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use std::env;
22

33
use cargo::core::Workspace;
4-
use cargo::ops::{CompileOptions, CompileMode};
5-
use cargo::ops;
4+
use cargo::ops::{self, CompileOptions, CompileMode, MessageFormat};
65
use cargo::util::important_paths::{find_root_manifest_for_wd};
76
use cargo::util::{CliResult, CliError, Config, human};
87

@@ -19,7 +18,7 @@ pub struct Options {
1918
flag_verbose: u32,
2019
flag_quiet: Option<bool>,
2120
flag_color: Option<String>,
22-
flag_message_format: Option<String>,
21+
flag_message_format: MessageFormat,
2322
flag_release: bool,
2423
flag_lib: bool,
2524
flag_bin: Vec<String>,
@@ -56,7 +55,7 @@ Options:
5655
-v, --verbose ... Use verbose output
5756
-q, --quiet No output printed to stdout
5857
--color WHEN Coloring: auto, always, never
59-
--message-format FMT Error format: human, json-v1
58+
--message-format FMT Error format: human, json [default: human]
6059
--frozen Require Cargo.lock and cache are up to date
6160
--locked Require Cargo.lock is up to date
6261
@@ -82,9 +81,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
8281
&options.flag_color,
8382
options.flag_frozen,
8483
options.flag_locked));
85-
let message_format = try!(ops::MessageFormat::from_option(
86-
&options.flag_message_format
87-
));
8884

8985
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path,
9086
config.cwd()));
@@ -115,7 +111,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
115111
&options.flag_test,
116112
&options.flag_example,
117113
&options.flag_bench),
118-
message_format: message_format,
114+
message_format: options.flag_message_format,
119115
target_rustdoc_args: None,
120116
target_rustc_args: options.arg_opts.as_ref().map(|a| &a[..]),
121117
};

src/bin/rustdoc.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use cargo::core::Workspace;
2-
use cargo::ops;
2+
use cargo::ops::{self, MessageFormat};
33
use cargo::util::{CliResult, Config};
44
use cargo::util::important_paths::{find_root_manifest_for_wd};
55

@@ -17,7 +17,7 @@ pub struct Options {
1717
flag_release: bool,
1818
flag_quiet: Option<bool>,
1919
flag_color: Option<String>,
20-
flag_message_format: Option<String>,
20+
flag_message_format: MessageFormat,
2121
flag_package: Option<String>,
2222
flag_lib: bool,
2323
flag_bin: Vec<String>,
@@ -53,7 +53,7 @@ Options:
5353
-v, --verbose ... Use verbose output
5454
-q, --quiet No output printed to stdout
5555
--color WHEN Coloring: auto, always, never
56-
--message-format FMT Error format: human, json-v1
56+
--message-format FMT Error format: human, json [default: human]
5757
--frozen Require Cargo.lock and cache are up to date
5858
--locked Require Cargo.lock is up to date
5959
@@ -76,9 +76,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
7676
&options.flag_color,
7777
options.flag_frozen,
7878
options.flag_locked));
79-
let message_format = try!(ops::MessageFormat::from_option(
80-
&options.flag_message_format
81-
));
8279

8380
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path,
8481
config.cwd()));
@@ -100,7 +97,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
10097
&options.flag_test,
10198
&options.flag_example,
10299
&options.flag_bench),
103-
message_format: message_format,
100+
message_format: options.flag_message_format,
104101
mode: ops::CompileMode::Doc { deps: false },
105102
target_rustdoc_args: Some(&options.arg_opts),
106103
target_rustc_args: None,

src/bin/test.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use cargo::core::Workspace;
2-
use cargo::ops;
2+
use cargo::ops::{self, MessageFormat};
33
use cargo::util::{CliResult, CliError, Human, human, Config};
44
use cargo::util::important_paths::{find_root_manifest_for_wd};
55

@@ -23,7 +23,7 @@ pub struct Options {
2323
flag_verbose: u32,
2424
flag_quiet: Option<bool>,
2525
flag_color: Option<String>,
26-
flag_message_format: Option<String>,
26+
flag_message_format: MessageFormat,
2727
flag_release: bool,
2828
flag_no_fail_fast: bool,
2929
flag_frozen: bool,
@@ -56,7 +56,7 @@ Options:
5656
-v, --verbose ... Use verbose output
5757
-q, --quiet No output printed to stdout
5858
--color WHEN Coloring: auto, always, never
59-
--message-format FMT Error format: human, json-v1
59+
--message-format FMT Error format: human, json [default: human]
6060
--no-fail-fast Run all tests regardless of failure
6161
--frozen Require Cargo.lock and cache are up to date
6262
--locked Require Cargo.lock is up to date
@@ -94,9 +94,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
9494
&options.flag_color,
9595
options.flag_frozen,
9696
options.flag_locked));
97-
let message_format = try!(ops::MessageFormat::from_option(
98-
&options.flag_message_format
99-
));
10097

10198
let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
10299

@@ -130,7 +127,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
130127
release: options.flag_release,
131128
mode: mode,
132129
filter: filter,
133-
message_format: message_format,
130+
message_format: options.flag_message_format,
134131
target_rustdoc_args: None,
135132
target_rustc_args: None,
136133
},

src/cargo/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ pub fn version() -> String {
211211
})
212212
}
213213

214-
fn flags_from_args<T>(usage: &str, args: &[String],
215-
options_first: bool) -> CliResult<T>
214+
fn flags_from_args<T>(usage: &str, args: &[String], options_first: bool) -> CliResult<T>
216215
where T: Decodable
217216
{
218217
let docopt = Docopt::new(usage).unwrap()

src/cargo/ops/cargo_compile.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,12 @@ pub enum CompileMode {
7676
Doc { deps: bool },
7777
}
7878

79-
#[derive(Clone, Copy, PartialEq, Eq)]
79+
#[derive(Clone, Copy, PartialEq, Eq, RustcDecodable)]
8080
pub enum MessageFormat {
8181
Human,
8282
Json
8383
}
8484

85-
impl MessageFormat {
86-
pub fn from_option(opt: &Option<String>) -> CargoResult<MessageFormat> {
87-
match opt.as_ref().map(|s| s.as_ref()) {
88-
None | Some("human") => Ok(MessageFormat::Human),
89-
Some("json-v1") => Ok(MessageFormat::Json),
90-
Some(other) => bail!("argument for --message-format must be human or json-v1, \
91-
but found `{}`", other)
92-
}
93-
}
94-
}
95-
9685
pub enum CompileFilter<'a> {
9786
Everything,
9887
Only {

tests/build.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,7 +2302,7 @@ fn compiler_json_error_format() {
23022302
.file("bar/src/lib.rs", r#"fn dead() {}"#);
23032303

23042304
assert_that(p.cargo_process("build").arg("-v")
2305-
.arg("--message-format").arg("json-v1"),
2305+
.arg("--message-format").arg("json"),
23062306
execs().with_json(r#"
23072307
{
23082308
"reason":"compiler-message",
@@ -2346,9 +2346,9 @@ fn wrong_message_format_option() {
23462346
p.build();
23472347

23482348
assert_that(p.cargo_process("build").arg("--message-format").arg("XML"),
2349-
execs().with_status(101)
2350-
.with_stderr_contains("\
2351-
[ERROR] argument for --message-format must be human or json-v1, but found `XML`"));
2349+
execs().with_status(1)
2350+
.with_stderr_contains(
2351+
r#"[ERROR] Could not match 'xml' with any of the allowed variants: ["Human", "Json"]"#));
23522352
}
23532353

23542354
#[test]

0 commit comments

Comments
 (0)