mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
od: implement --help and --version
This commit is contained in:
parent
a900b42a1f
commit
e0b7ff1953
3 changed files with 20 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -660,6 +660,7 @@ version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
"getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"unindent 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -10,6 +10,7 @@ path = "od.rs"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
getopts = "*"
|
getopts = "*"
|
||||||
libc = "*"
|
libc = "*"
|
||||||
|
unindent = "*"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "od"
|
name = "od"
|
||||||
|
|
18
src/od/od.rs
18
src/od/od.rs
|
@ -10,6 +10,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
|
extern crate unindent;
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
@ -17,6 +18,7 @@ use std::mem;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use unindent::*;
|
||||||
|
|
||||||
//This is available in some versions of std, but not all that we target.
|
//This is available in some versions of std, but not all that we target.
|
||||||
macro_rules! hashmap {
|
macro_rules! hashmap {
|
||||||
|
@ -27,6 +29,8 @@ macro_rules! hashmap {
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static NAME: &'static str = "od";
|
||||||
|
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum Radix { Decimal, Hexadecimal, Octal, Binary }
|
enum Radix { Decimal, Hexadecimal, Octal, Binary }
|
||||||
|
@ -77,6 +81,20 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
Err(f) => panic!("Invalid options\n{}", f)
|
Err(f) => panic!("Invalid options\n{}", f)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if matches.opt_present("h") {
|
||||||
|
let msg = unindent(&format!("
|
||||||
|
Usage:
|
||||||
|
{0} [OPTION]... [FILENAME]...
|
||||||
|
|
||||||
|
Displays data in various human-readable formats.", NAME));
|
||||||
|
println!("{}", opts.usage(&msg));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if matches.opt_present("version") {
|
||||||
|
println!("{} {}", NAME, VERSION);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
let input_offset_base = match parse_radix(matches.opt_str("A")) {
|
let input_offset_base = match parse_radix(matches.opt_str("A")) {
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
Err(f) => { panic!("Invalid -A/--address-radix\n{}", f) }
|
Err(f) => { panic!("Invalid -A/--address-radix\n{}", f) }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue