Skip to content

Commit

Permalink
fix(cli): Use stderr for user messages (#527)
Browse files Browse the repository at this point in the history
Fixes #526
  • Loading branch information
epage authored Oct 11, 2021
1 parent 712aeb7 commit f6706af
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/bin/add/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn print_msg(dep: &Dependency, section: &[String], optional: bool) -> Result<()>
} else {
ColorChoice::Never
};
let mut output = StandardStream::stdout(colorchoice);
let mut output = StandardStream::stderr(colorchoice);
output.set_color(ColorSpec::new().set_fg(Some(Color::Green)).set_bold(true))?;
write!(output, "{:>12}", "Adding")?;
output.reset()?;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/rm/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn print_msg(name: &str, section: &str) -> Result<()> {
} else {
ColorChoice::Never
};
let mut output = StandardStream::stdout(colorchoice);
let mut output = StandardStream::stderr(colorchoice);
output.set_color(ColorSpec::new().set_fg(Some(Color::Green)).set_bold(true))?;
write!(output, "{:>12}", "Removing")?;
output.reset()?;
Expand Down
6 changes: 3 additions & 3 deletions src/bin/set-version/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl Manifests {
}

fn dry_run_message() -> Result<()> {
let bufwtr = BufferWriter::stdout(ColorChoice::Always);
let bufwtr = BufferWriter::stderr(ColorChoice::Always);
let mut buffer = bufwtr.buffer();
buffer
.set_color(ColorSpec::new().set_fg(Some(Color::Cyan)).set_bold(true))
Expand Down Expand Up @@ -241,7 +241,7 @@ fn deprecated_message(message: &str) -> Result<()> {
}

fn upgrade_message(name: &str, from: &semver::Version, to: &semver::Version) -> Result<()> {
let bufwtr = BufferWriter::stdout(ColorChoice::Always);
let bufwtr = BufferWriter::stderr(ColorChoice::Always);
let mut buffer = bufwtr.buffer();
buffer
.set_color(ColorSpec::new().set_fg(Some(Color::Green)).set_bold(true))
Expand All @@ -258,7 +258,7 @@ fn upgrade_message(name: &str, from: &semver::Version, to: &semver::Version) ->
}

fn upgrade_dependent_message(name: &str, old_req: &str, new_req: &str) -> Result<()> {
let bufwtr = BufferWriter::stdout(ColorChoice::Always);
let bufwtr = BufferWriter::stderr(ColorChoice::Always);
let mut buffer = bufwtr.buffer();
buffer
.set_color(ColorSpec::new().set_fg(Some(Color::Green)).set_bold(true))
Expand Down
2 changes: 1 addition & 1 deletion src/bin/upgrade/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn deprecated_message(message: &str) -> Result<()> {
}

fn dry_run_message() -> Result<()> {
let bufwtr = BufferWriter::stdout(ColorChoice::Always);
let bufwtr = BufferWriter::stderr(ColorChoice::Always);
let mut buffer = bufwtr.buffer();
buffer
.set_color(ColorSpec::new().set_fg(Some(Color::Cyan)).set_bold(true))
Expand Down
2 changes: 1 addition & 1 deletion src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub fn update_registry_index(registry: &Url, quiet: bool) -> Result<()> {
} else {
ColorChoice::Never
};
let mut output = StandardStream::stdout(colorchoice);
let mut output = StandardStream::stderr(colorchoice);

let index = crates_index::BareIndex::from_url(registry.as_str())?;
let mut index = index.open_or_clone()?;
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn print_upgrade_if_necessary(
if old_version == new_version {
return Ok(());
}
let bufwtr = BufferWriter::stdout(ColorChoice::Always);
let bufwtr = BufferWriter::stderr(ColorChoice::Always);
let mut buffer = bufwtr.buffer();
buffer
.set_color(ColorSpec::new().set_fg(Some(Color::Green)).set_bold(true))
Expand Down
12 changes: 6 additions & 6 deletions tests/cargo-add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ fn adds_dependency_normalized_name() {
&format!("--manifest-path={}", manifest),
])
.success()
.stdout(predicates::str::contains(
.stderr(predicates::str::contains(
"WARN: Added `linked-hash-map` instead of `linked_hash_map`",
));

Expand Down Expand Up @@ -1758,7 +1758,7 @@ fn add_prints_message() {
.env("CARGO_IS_TEST", "1")
.assert()
.success()
.stdout(predicates::str::contains(
.stderr(predicates::str::contains(
"Adding docopt v0.6.0 to dependencies",
));
}
Expand All @@ -1780,7 +1780,7 @@ fn add_prints_message_with_section() {
.env("CARGO_IS_TEST", "1")
.assert()
.success()
.stdout(predicates::str::contains(
.stderr(predicates::str::contains(
"Adding clap v0.1.0 to optional dependencies for target `mytarget`",
));
}
Expand All @@ -1802,7 +1802,7 @@ fn add_prints_message_for_dev_deps() {
.env("CARGO_IS_TEST", "1")
.assert()
.success()
.stdout(predicates::str::contains(
.stderr(predicates::str::contains(
"Adding docopt v0.8.0 to dev-dependencies",
));
}
Expand All @@ -1824,7 +1824,7 @@ fn add_prints_message_for_build_deps() {
.env("CARGO_IS_TEST", "1")
.assert()
.success()
.stdout(predicates::str::contains(
.stderr(predicates::str::contains(
"Adding hello-world v0.1.0 to build-dependencies",
));
}
Expand Down Expand Up @@ -1956,7 +1956,7 @@ fn add_prints_message_for_features_deps() {
.env("CARGO_IS_TEST", "1")
.assert()
.success()
.stdout(predicates::str::contains(
.stderr(predicates::str::contains(
r#"Adding hello-world v0.1.0 to dependencies with features: ["jui"]"#,
));
}
4 changes: 2 additions & 2 deletions tests/cargo-rm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ fn rm_prints_message() {
.args(&["rm", "semver", &format!("--manifest-path={}", manifest)])
.assert()
.success()
.stdout(" Removing semver from dependencies\n");
.stderr(" Removing semver from dependencies\n");
}

#[test]
Expand All @@ -261,7 +261,7 @@ fn rm_prints_messages_for_multiple() {
])
.assert()
.success()
.stdout(" Removing semver from dependencies\n Removing docopt from dependencies\n");
.stderr(" Removing semver from dependencies\n Removing docopt from dependencies\n");
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/cargo-upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,5 +550,5 @@ fn upgrade_prints_messages() {
])
.assert()
.success()
.stdout(predicates::str::contains("docopt v0.8 -> v"));
.stderr(predicates::str::contains("docopt v0.8 -> v"));
}

0 comments on commit f6706af

Please sign in to comment.