Retire warn! in favor of eprintln! (#218)

This commit is contained in:
Casey Rodarmor 2017-08-18 14:15:43 -07:00 committed by GitHub
parent 35748f191f
commit 1fd1c05653
2 changed files with 9 additions and 33 deletions

View File

@ -8,18 +8,10 @@ use std::collections::BTreeMap;
use self::clap::{App, Arg, ArgGroup, AppSettings}; use self::clap::{App, Arg, ArgGroup, AppSettings};
use super::{Slurp, RunOptions, compile, DEFAULT_SHELL, maybe_s}; use super::{Slurp, RunOptions, compile, DEFAULT_SHELL, maybe_s};
macro_rules! warn {
($($arg:tt)*) => {{
extern crate std;
use std::io::prelude::*;
let _ = writeln!(&mut std::io::stderr(), $($arg)*);
}};
}
macro_rules! die { macro_rules! die {
($($arg:tt)*) => {{ ($($arg:tt)*) => {{
extern crate std; extern crate std;
warn!($($arg)*); eprintln!($($arg)*);
process::exit(EXIT_FAILURE) process::exit(EXIT_FAILURE)
}}; }};
} }
@ -235,7 +227,7 @@ pub fn app() {
if matches.is_present("SUMMARY") { if matches.is_present("SUMMARY") {
if justfile.count() == 0 { if justfile.count() == 0 {
warn!("Justfile contains no recipes."); eprintln!("Justfile contains no recipes.");
} else { } else {
println!("{}", justfile.recipes.keys().cloned().collect::<Vec<_>>().join(" ")); println!("{}", justfile.recipes.keys().cloned().collect::<Vec<_>>().join(" "));
} }
@ -274,9 +266,9 @@ pub fn app() {
process::exit(EXIT_SUCCESS); process::exit(EXIT_SUCCESS);
} }
None => { None => {
warn!("Justfile does not contain recipe `{}`.", name); eprintln!("Justfile does not contain recipe `{}`.", name);
if let Some(suggestion) = justfile.suggest(name) { if let Some(suggestion) = justfile.suggest(name) {
warn!("Did you mean `{}`?", suggestion); eprintln!("Did you mean `{}`?", suggestion);
} }
process::exit(EXIT_FAILURE) process::exit(EXIT_FAILURE)
} }
@ -310,9 +302,9 @@ pub fn app() {
if let Err(run_error) = justfile.run(&arguments, &options) { if let Err(run_error) = justfile.run(&arguments, &options) {
if !options.quiet { if !options.quiet {
if color.stderr().active() { if color.stderr().active() {
warn!("{:#}", run_error); eprintln!("{:#}", run_error);
} else { } else {
warn!("{}", run_error); eprintln!("{}", run_error);
} }
} }

View File

@ -51,22 +51,6 @@ use std::collections::{BTreeMap as Map, BTreeSet as Set};
use std::fmt::Display; use std::fmt::Display;
use std::ops::Range; use std::ops::Range;
macro_rules! warn {
($($arg:tt)*) => {{
extern crate std;
use std::io::prelude::*;
let _ = writeln!(&mut std::io::stderr(), $($arg)*);
}};
}
macro_rules! die {
($($arg:tt)*) => {{
extern crate std;
warn!($($arg)*);
process::exit(EXIT_FAILURE)
}};
}
const DEFAULT_SHELL: &'static str = "sh"; const DEFAULT_SHELL: &'static str = "sh";
trait Slurp { trait Slurp {
@ -290,7 +274,7 @@ impl<'a> Recipe<'a> {
) -> Result<(), RunError<'a>> { ) -> Result<(), RunError<'a>> {
if options.verbose { if options.verbose {
let color = options.color.stderr().banner(); let color = options.color.stderr().banner();
warn!("{}===> Running recipe `{}`...{}", color.prefix(), self.name, color.suffix()); eprintln!("{}===> Running recipe `{}`...{}", color.prefix(), self.name, color.suffix());
} }
let mut argument_map = Map::new(); let mut argument_map = Map::new();
@ -333,7 +317,7 @@ impl<'a> Recipe<'a> {
if options.dry_run || self.quiet { if options.dry_run || self.quiet {
for line in &evaluated_lines { for line in &evaluated_lines {
warn!("{}", line); eprintln!("{}", line);
} }
} }
@ -440,7 +424,7 @@ impl<'a> Recipe<'a> {
} else { } else {
options.color options.color
}; };
warn!("{}", color.stderr().paint(command)); eprintln!("{}", color.stderr().paint(command));
} }
if options.dry_run { if options.dry_run {