Skip to content

Commit

Permalink
Auto merge of #11358 - hi-rustin:rustin-patch-error-msg, r=weihanglo
Browse files Browse the repository at this point in the history
Extract `two_kinds_of_msg_format_err` message to de-duplicate it

### What does this PR try to resolve?

Extract `two_kinds_of_msg_format_err` message to de-duplicate it.

I guess this would be helpful for changing this message.

### Additional information

Just found it when I read the code. So if you prefer the former code style, please feel free to close my PR.
  • Loading branch information
bors committed Nov 10, 2022
2 parents 9865dde + 9060360 commit c8b090c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,25 +469,26 @@ pub trait ArgMatchesExt {
ansi: false,
render_diagnostics: false,
};
let two_kinds_of_msg_format_err = "cannot specify two kinds of `message-format` arguments";
for fmt in self._values_of("message-format") {
for fmt in fmt.split(',') {
let fmt = fmt.to_ascii_lowercase();
match fmt.as_str() {
"json" => {
if message_format.is_some() {
bail!("cannot specify two kinds of `message-format` arguments");
bail!(two_kinds_of_msg_format_err);
}
message_format = Some(default_json);
}
"human" => {
if message_format.is_some() {
bail!("cannot specify two kinds of `message-format` arguments");
bail!(two_kinds_of_msg_format_err);
}
message_format = Some(MessageFormat::Human);
}
"short" => {
if message_format.is_some() {
bail!("cannot specify two kinds of `message-format` arguments");
bail!(two_kinds_of_msg_format_err);
}
message_format = Some(MessageFormat::Short);
}
Expand All @@ -499,7 +500,7 @@ pub trait ArgMatchesExt {
Some(MessageFormat::Json {
render_diagnostics, ..
}) => *render_diagnostics = true,
_ => bail!("cannot specify two kinds of `message-format` arguments"),
_ => bail!(two_kinds_of_msg_format_err),
}
}
"json-diagnostic-short" => {
Expand All @@ -508,7 +509,7 @@ pub trait ArgMatchesExt {
}
match &mut message_format {
Some(MessageFormat::Json { short, .. }) => *short = true,
_ => bail!("cannot specify two kinds of `message-format` arguments"),
_ => bail!(two_kinds_of_msg_format_err),
}
}
"json-diagnostic-rendered-ansi" => {
Expand All @@ -517,7 +518,7 @@ pub trait ArgMatchesExt {
}
match &mut message_format {
Some(MessageFormat::Json { ansi, .. }) => *ansi = true,
_ => bail!("cannot specify two kinds of `message-format` arguments"),
_ => bail!(two_kinds_of_msg_format_err),
}
}
s => bail!("invalid message format specifier: `{}`", s),
Expand Down

0 comments on commit c8b090c

Please sign in to comment.