mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
use crash! macro in echo
This commit is contained in:
parent
f6c46024e8
commit
d8896a18d1
1 changed files with 13 additions and 7 deletions
20
echo/echo.rs
20
echo/echo.rs
|
@ -1,3 +1,4 @@
|
||||||
|
#[feature(macro_rules)];
|
||||||
#[crate_id(name="echo", vers="1.0.0", author="Derek Chiang")];
|
#[crate_id(name="echo", vers="1.0.0", author="Derek Chiang")];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -12,12 +13,22 @@
|
||||||
extern mod extra;
|
extern mod extra;
|
||||||
|
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::io::{print, println, stderr};
|
use std::io::{print, println};
|
||||||
use std::uint;
|
use std::uint;
|
||||||
use extra::getopts::groups;
|
use extra::getopts::groups;
|
||||||
|
|
||||||
static VERSION: &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! crash(
|
||||||
|
($exitcode:expr, $($args:expr),+) => (
|
||||||
|
{ ::std::os::set_exit_status($exitcode);
|
||||||
|
let _unused = write!(&mut ::std::io::stderr(), $($args),+);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
fn print_char(c: char) {
|
fn print_char(c: char) {
|
||||||
print!("{}", c);
|
print!("{}", c);
|
||||||
}
|
}
|
||||||
|
@ -77,12 +88,7 @@ fn main() {
|
||||||
|
|
||||||
let matches = match groups::getopts(args.tail(), opts) {
|
let matches = match groups::getopts(args.tail(), opts) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => {
|
Err(f) => crash!(1, "Invalid options\n{}", f.to_err_msg())
|
||||||
writeln!(&mut stderr() as &mut Writer,
|
|
||||||
"Invalid options\n{}", f.to_err_msg());
|
|
||||||
os::set_exit_status(1);
|
|
||||||
return
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches.opt_present("help") {
|
if matches.opt_present("help") {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue