mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
Replace manual formatting by show_error!()/show_warning!()
This commit is contained in:
parent
741f065a12
commit
6d346b2307
6 changed files with 20 additions and 17 deletions
|
@ -18,6 +18,7 @@ use std::fs::File;
|
||||||
use std::io::{BufRead, BufReader};
|
use std::io::{BufRead, BufReader};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use uucore::display::Quotable;
|
use uucore::display::Quotable;
|
||||||
|
use uucore::show_error;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use winapi::{
|
use winapi::{
|
||||||
shared::minwindef::WORD,
|
shared::minwindef::WORD,
|
||||||
|
@ -146,7 +147,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
|
|
||||||
let format = if let Some(form) = matches.value_of(OPT_FORMAT) {
|
let format = if let Some(form) = matches.value_of(OPT_FORMAT) {
|
||||||
if !form.starts_with('+') {
|
if !form.starts_with('+') {
|
||||||
eprintln!("date: invalid date {}", form.quote());
|
show_error!("invalid date {}", form.quote());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
let form = form[1..].to_string();
|
let form = form[1..].to_string();
|
||||||
|
@ -175,7 +176,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
let set_to = match matches.value_of(OPT_SET).map(parse_date) {
|
let set_to = match matches.value_of(OPT_SET).map(parse_date) {
|
||||||
None => None,
|
None => None,
|
||||||
Some(Err((input, _err))) => {
|
Some(Err((input, _err))) => {
|
||||||
eprintln!("date: invalid date {}", input.quote());
|
show_error!("invalid date {}", input.quote());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
Some(Ok(date)) => Some(date),
|
Some(Ok(date)) => Some(date),
|
||||||
|
@ -241,7 +242,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
println!("{}", formatted);
|
println!("{}", formatted);
|
||||||
}
|
}
|
||||||
Err((input, _err)) => {
|
Err((input, _err)) => {
|
||||||
println!("date: invalid date {}", input.quote());
|
show_error!("invalid date {}", input.quote());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -353,13 +354,13 @@ fn set_system_datetime(_date: DateTime<Utc>) -> i32 {
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
fn set_system_datetime(_date: DateTime<Utc>) -> i32 {
|
fn set_system_datetime(_date: DateTime<Utc>) -> i32 {
|
||||||
eprintln!("date: setting the date is not supported by macOS");
|
show_error!("setting the date is not supported by macOS");
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "redox")]
|
#[cfg(target_os = "redox")]
|
||||||
fn set_system_datetime(_date: DateTime<Utc>) -> i32 {
|
fn set_system_datetime(_date: DateTime<Utc>) -> i32 {
|
||||||
eprintln!("date: setting the date is not supported by Redox");
|
show_error!("setting the date is not supported by Redox");
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,7 +380,7 @@ fn set_system_datetime(date: DateTime<Utc>) -> i32 {
|
||||||
|
|
||||||
if result != 0 {
|
if result != 0 {
|
||||||
let error = std::io::Error::last_os_error();
|
let error = std::io::Error::last_os_error();
|
||||||
eprintln!("date: cannot set date: {}", error);
|
show_error!("cannot set date: {}", error);
|
||||||
error.raw_os_error().unwrap()
|
error.raw_os_error().unwrap()
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
|
@ -409,7 +410,7 @@ fn set_system_datetime(date: DateTime<Utc>) -> i32 {
|
||||||
|
|
||||||
if result == 0 {
|
if result == 0 {
|
||||||
let error = std::io::Error::last_os_error();
|
let error = std::io::Error::last_os_error();
|
||||||
eprintln!("date: cannot set date: {}", error);
|
show_error!("cannot set date: {}", error);
|
||||||
error.raw_os_error().unwrap()
|
error.raw_os_error().unwrap()
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
|
|
3
src/uu/env/src/env.rs
vendored
3
src/uu/env/src/env.rs
vendored
|
@ -22,6 +22,7 @@ use std::env;
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
use uucore::display::Quotable;
|
||||||
use uucore::error::{UResult, USimpleError};
|
use uucore::error::{UResult, USimpleError};
|
||||||
|
|
||||||
const USAGE: &str = "env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]";
|
const USAGE: &str = "env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]";
|
||||||
|
@ -93,7 +94,7 @@ fn load_config_file(opts: &mut Options) -> UResult<()> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let conf = conf.map_err(|error| {
|
let conf = conf.map_err(|error| {
|
||||||
eprintln!("env: error: \"{}\": {}", file, error);
|
show_error!("{}: {}", file.maybe_quote(), error);
|
||||||
1
|
1
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ impl<'b> MultifileReader<'b> {
|
||||||
// print an error at the time that the file is needed,
|
// print an error at the time that the file is needed,
|
||||||
// then move on the the next file.
|
// then move on the the next file.
|
||||||
// This matches the behavior of the original `od`
|
// This matches the behavior of the original `od`
|
||||||
eprintln!("{}: {}: {}", uucore::util_name(), fname.maybe_quote(), e);
|
show_error!("{}: {}", fname.maybe_quote(), e);
|
||||||
self.any_err = true
|
self.any_err = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ impl<'b> io::Read for MultifileReader<'b> {
|
||||||
Ok(0) => break,
|
Ok(0) => break,
|
||||||
Ok(n) => n,
|
Ok(n) => n,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("{}: I/O: {}", uucore::util_name(), e);
|
show_error!("I/O: {}", e);
|
||||||
self.any_err = true;
|
self.any_err = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ use itertools::put_back_n;
|
||||||
use std::iter::Peekable;
|
use std::iter::Peekable;
|
||||||
use std::slice::Iter;
|
use std::slice::Iter;
|
||||||
use uucore::display::Quotable;
|
use uucore::display::Quotable;
|
||||||
use uucore::show_error;
|
use uucore::show_warning;
|
||||||
|
|
||||||
use crate::tokenize::sub::Sub;
|
use crate::tokenize::sub::Sub;
|
||||||
use crate::tokenize::token::{Token, Tokenizer};
|
use crate::tokenize::token::{Token, Tokenizer};
|
||||||
|
@ -20,8 +20,8 @@ pub struct Memo {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn warn_excess_args(first_arg: &str) {
|
fn warn_excess_args(first_arg: &str) {
|
||||||
show_error!(
|
show_warning!(
|
||||||
"warning: ignoring excess arguments, starting with {}",
|
"ignoring excess arguments, starting with {}",
|
||||||
first_arg.quote()
|
first_arg.quote()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ use std::env;
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
|
|
||||||
use uucore::display::Quotable;
|
use uucore::display::Quotable;
|
||||||
use uucore::show_error;
|
use uucore::{show_error, show_warning};
|
||||||
|
|
||||||
use super::format_field::{FieldType, FormatField};
|
use super::format_field::{FieldType, FormatField};
|
||||||
use super::formatter::{Base, FormatPrimitive, Formatter, InitialPrefix};
|
use super::formatter::{Base, FormatPrimitive, Formatter, InitialPrefix};
|
||||||
|
@ -30,8 +30,8 @@ fn warn_char_constant_ign(remaining_bytes: Vec<u8>) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if let env::VarError::NotPresent = e {
|
if let env::VarError::NotPresent = e {
|
||||||
show_error!(
|
show_warning!(
|
||||||
"warning: {:?}: character(s) following character \
|
"{:?}: character(s) following character \
|
||||||
constant have been ignored",
|
constant have been ignored",
|
||||||
&*remaining_bytes
|
&*remaining_bytes
|
||||||
);
|
);
|
||||||
|
|
|
@ -11,6 +11,7 @@ use std::ffi::OsString;
|
||||||
use std::iter::Peekable;
|
use std::iter::Peekable;
|
||||||
|
|
||||||
use uucore::display::Quotable;
|
use uucore::display::Quotable;
|
||||||
|
use uucore::show_error;
|
||||||
|
|
||||||
/// Represents one of the binary comparison operators for strings, integers, or files
|
/// Represents one of the binary comparison operators for strings, integers, or files
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
|
@ -207,7 +208,7 @@ impl Parser {
|
||||||
|
|
||||||
// case 2: error if end of stream is `( <any_token>`
|
// case 2: error if end of stream is `( <any_token>`
|
||||||
[symbol] => {
|
[symbol] => {
|
||||||
eprintln!("test: missing argument after ‘{:?}’", symbol);
|
show_error!("missing argument after ‘{:?}’", symbol);
|
||||||
std::process::exit(2);
|
std::process::exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue