Switch to external getopts cargo (part 1).

I switched over to the getopts crate on crates.io, instead of Rust's
private implementation. This will allow coreutils to build for Rust 1.0.

I'm splitting the updates into several commits for better reviewing.
This commit is contained in:
Joseph Crail
2015-05-20 22:47:30 -04:00
parent d6837c8709
commit b4b08de42c
33 changed files with 611 additions and 698 deletions
+2 -1
View File
@@ -196,7 +196,8 @@ define DEP_INCLUDE
-include $(SRCDIR)/$(1)/deps.mk
endef
# we always depend on libc because common/util does
DEPLIBS := libc
# we also depend on getopts since all utilities support command-line arguments
DEPLIBS := libc getopts
DEPPLUGS :=
# now, add in deps in src/utilname/deps.mk
# if we're testing, only consider the TESTS variable,
+1
View File
@@ -7,6 +7,7 @@ name = "null"
[dependencies]
libc = "0.1.7"
getopts = "0.2.11"
num_cpus = "*"
rand = "0.3.8"
regex = "0.1.30"
+30 -47
View File
@@ -1,5 +1,4 @@
#![crate_name = "base64"]
#![feature(rustc_private)]
/*
* This file is part of the uutils coreutils package.
@@ -13,50 +12,43 @@
extern crate rustc_serialize as serialize;
extern crate getopts;
extern crate libc;
#[macro_use] extern crate log;
use getopts::Options;
use serialize::base64::{self, FromBase64, ToBase64};
use std::ascii::AsciiExt;
use std::error::Error;
use std::fs::File;
use std::io::{BufReader, Read, stdin, stdout, Write};
use std::path::Path;
use getopts::{
getopts,
optflag,
optopt,
usage
};
use serialize::base64;
use serialize::base64::{FromBase64, ToBase64};
#[path = "../common/util.rs"]
#[macro_use]
mod util;
enum Mode {
Decode,
Encode,
Help,
Version
}
static NAME: &'static str = "base64";
static VERSION: &'static str = "1.0.0";
pub type FileOrStdReader = BufReader<Box<Read+'static>>;
pub fn uumain(args: Vec<String>) -> i32 {
let opts = [
optflag("d", "decode", "decode data"),
optflag("i", "ignore-garbage", "when decoding, ignore non-alphabetic characters"),
optopt("w", "wrap",
"wrap encoded lines after COLS character (default 76, 0 to disable wrapping)", "COLS"
),
optflag("h", "help", "display this help text and exit"),
optflag("V", "version", "output version information and exit")
];
let matches = match getopts(&args[1..], &opts) {
let mut opts = Options::new();
opts.optflag("d", "decode", "decode data");
opts.optflag("i", "ignore-garbage", "when decoding, ignore non-alphabetic characters");
opts.optopt("w", "wrap", "wrap encoded lines after COLS character (default 76, 0 to disable wrapping)", "COLS");
opts.optflag("h", "help", "display this help text and exit");
opts.optflag("V", "version", "output version information and exit");
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(e) => {
crash!(1, "error: {}", e);
}
Err(e) => { crash!(1, "error: {}", e) }
};
let progname = args[0].clone();
let usage = usage("Base64 encode or decode FILE, or standard input, to standard output.", &opts);
let mode = if matches.opt_present("help") {
Mode::Help
} else if matches.opt_present("version") {
@@ -90,7 +82,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
match mode {
Mode::Decode => decode(&mut input, ignore_garbage),
Mode::Encode => encode(&mut input, line_wrap),
Mode::Help => help(&progname[..], &usage[..]),
Mode::Help => help(opts),
Mode::Version => version()
}
@@ -152,28 +144,19 @@ fn encode(input: &mut FileOrStdReader, line_wrap: usize) {
println!("{}", &encoded[..]);
}
fn help(progname: &str, usage: &str) {
println!("Usage: {} [OPTION]... [FILE]", progname);
println!("");
println!("{}", usage);
fn help(opts: Options) {
let msg = format!("Usage: {} [OPTION]... [FILE]\n\n\
Base64 encode or decode FILE, or standard input, to standard output.\n\
With no FILE, or when FILE is -, read standard input.\n\n\
The data are encoded as described for the base64 alphabet in RFC \
3548. When\ndecoding, the input may contain newlines in addition \
to the bytes of the formal\nbase64 alphabet. Use --ignore-garbage \
to attempt to recover from any other\nnon-alphabet bytes in the \
encoded stream.", NAME);
let msg = "With no FILE, or when FILE is -, read standard input.\n\n\
The data are encoded as described for the base64 alphabet in RFC \
3548. When\ndecoding, the input may contain newlines in addition \
to the bytes of the formal\nbase64 alphabet. Use --ignore-garbage \
to attempt to recover from any other\nnon-alphabet bytes in the \
encoded stream.";
println!("{}", msg);
print!("{}", opts.usage(&msg));
}
fn version() {
println!("base64 1.0.0");
}
enum Mode {
Decode,
Encode,
Help,
Version
println!("{} {}", NAME, VERSION);
}
+14 -18
View File
@@ -1,5 +1,4 @@
#![crate_name = "basename"]
#![feature(rustc_private)]
/*
* This file is part of the uutils coreutils package.
@@ -13,6 +12,7 @@
extern crate getopts;
extern crate libc;
use getopts::Options;
use std::io::Write;
use std::path::{is_separator, PathBuf};
@@ -24,47 +24,43 @@ static NAME: &'static str = "basename";
static VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> i32 {
let program = strip_dir(&args[0]);
//
// Argument parsing
//
let opts = [
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit"),
];
let mut opts = Options::new();
opts.optflag("h", "help", "display this help and exit");
opts.optflag("V", "version", "output version information and exit");
let matches = match getopts::getopts(&args[1..], &opts) {
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(f) => crash!(1, "Invalid options\n{}", f)
};
if matches.opt_present("help") {
println!("Usage: {0} NAME [SUFFIX]", program);
println!(" or: {0} OPTION", program);
println!("Print NAME with any leading directory components removed.");
println!("If specified, also remove a trailing SUFFIX.");
let msg = format!("Usage: {0} NAME [SUFFIX]\n or: {0} OPTION\n\n\
Print NAME with any leading directory components removed.\n\
If specified, also remove a trailing SUFFIX.", NAME);
print!("{}", getopts::usage("", &opts));
print!("{}", opts.usage(&msg));
return 0;
}
if matches.opt_present("version") {
println!("{} {}", program, VERSION);
println!("{} {}", NAME, VERSION);
return 0;
}
// too few arguments
if args.len() < 2 {
println!("{}: {}", program, "missing operand");
println!("Try '{} --help' for more information.", program);
println!("{}: {}", NAME, "missing operand");
println!("Try '{} --help' for more information.", NAME);
return 1;
}
// too many arguments
else if args.len() > 3 {
println!("{}: extra operand '{}'", program, args[3]);
println!("Try '{} --help' for more information.", program);
println!("{}: extra operand '{}'", NAME, args[3]);
println!("Try '{} --help' for more information.", NAME);
return 1;
}
+27 -30
View File
@@ -1,5 +1,4 @@
#![crate_name = "cat"]
#![feature(rustc_private)]
/*
* This file is part of the uutils coreutils package.
@@ -15,49 +14,47 @@
extern crate getopts;
extern crate libc;
use getopts::Options;
use std::fs::File;
use std::io::{stdout, stdin, stderr, Write, Read};
use std::io::Result;
use std::intrinsics::{copy_nonoverlapping};
use std::io::{stdout, stdin, stderr, Write, Read, Result};
use libc::consts::os::posix88::STDIN_FILENO;
use libc::funcs::posix88::unistd::isatty;
use libc::types::os::arch::c95::c_int;
static NAME: &'static str = "cat";
static VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> i32 {
let program = &args[0];
let opts = [
getopts::optflag("A", "show-all", "equivalent to -vET"),
getopts::optflag("b", "number-nonblank",
"number nonempty output lines, overrides -n"),
getopts::optflag("e", "", "equivalent to -vE"),
getopts::optflag("E", "show-ends", "display $ at end of each line"),
getopts::optflag("n", "number", "number all output lines"),
getopts::optflag("s", "squeeze-blank", "suppress repeated empty output lines"),
getopts::optflag("t", "", "equivalent to -vT"),
getopts::optflag("T", "show-tabs", "display TAB characters as ^I"),
getopts::optflag("v", "show-nonprinting",
"use ^ and M- notation, except for LF (\\n) and TAB (\\t)"),
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(&args[1..], &opts) {
let mut opts = Options::new();
opts.optflag("A", "show-all", "equivalent to -vET");
opts.optflag("b", "number-nonblank",
"number nonempty output lines, overrides -n");
opts.optflag("e", "", "equivalent to -vE");
opts.optflag("E", "show-ends", "display $ at end of each line");
opts.optflag("n", "number", "number all output lines");
opts.optflag("s", "squeeze-blank", "suppress repeated empty output lines");
opts.optflag("t", "", "equivalent to -vT");
opts.optflag("T", "show-tabs", "display TAB characters as ^I");
opts.optflag("v", "show-nonprinting",
"use ^ and M- notation, except for LF (\\n) and TAB (\\t)");
opts.optflag("h", "help", "display this help and exit");
opts.optflag("V", "version", "output version information and exit");
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(f) => panic!("Invalid options\n{}", f)
};
if matches.opt_present("help") {
println!("cat 1.0.0");
println!("");
println!("Usage:");
println!(" {0} [OPTION]... [FILE]...", program);
println!("");
print!("{}", &getopts::usage("Concatenate FILE(s), or standard input, to \
standard output.", &opts)[..]);
println!("");
println!("With no FILE, or when FILE is -, read standard input.");
let msg = format!("{} {}\n\n\
Usage:\n {0} [OPTION]... [FILE]...\n\n\
Concatenate FILE(s), or standard input, to standard output.\n\n\
With no FILE, or when FILE is -, read standard input.", NAME, VERSION);
print!("{}", opts.usage(&msg));
return 0;
}
if matches.opt_present("version") {
println!("cat 1.0.0");
println!("{} {}", NAME, VERSION);
return 0;
}
+24 -27
View File
@@ -1,5 +1,5 @@
#![crate_name = "chmod"]
#![feature(fs_walk, path_ext, rustc_private)]
#![feature(fs_walk, path_ext)]
/*
* This file is part of the uutils coreutils package.
@@ -16,12 +16,13 @@ extern crate getopts;
extern crate libc;
extern crate regex;
use getopts::Options;
use regex::Regex;
use std::ffi::CString;
use std::fs::{self, PathExt};
use std::path::Path;
use std::io::{Error, Write};
use std::mem;
use regex::Regex;
use std::path::Path;
#[path = "../common/util.rs"]
#[macro_use]
@@ -31,45 +32,41 @@ const NAME: &'static str = "chmod";
const VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> i32 {
let program = args[0].clone();
let opts = [
getopts::optflag("c", "changes", "like verbose but report only when a change is made (unimplemented)"),
getopts::optflag("f", "quiet", "suppress most error messages (unimplemented)"), // TODO: support --silent
getopts::optflag("v", "verbose", "output a diagnostic for every file processed (unimplemented)"),
getopts::optflag("", "no-preserve-root", "do not treat '/' specially (the default)"),
getopts::optflag("", "preserve-root", "fail to operate recursively on '/'"),
getopts::optflagopt("", "reference", "use RFILE's mode instead of MODE values", "RFILE"),
getopts::optflag("R", "recursive", "change files and directories recursively"),
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit")
];
let mut opts = Options::new();
opts.optflag("c", "changes", "like verbose but report only when a change is made (unimplemented)");
opts.optflag("f", "quiet", "suppress most error messages (unimplemented)"); // TODO: support --silent
opts.optflag("v", "verbose", "output a diagnostic for every file processed (unimplemented)");
opts.optflag("", "no-preserve-root", "do not treat '/' specially (the default)");
opts.optflag("", "preserve-root", "fail to operate recursively on '/'");
opts.optflagopt("", "reference", "use RFILE's mode instead of MODE values", "RFILE");
opts.optflag("R", "recursive", "change files and directories recursively");
opts.optflag("h", "help", "display this help and exit");
opts.optflag("V", "version", "output version information and exit");
// TODO: sanitize input for - at beginning (e.g. chmod -x testfile). Solution is to add a to -x, making a-x
let mut matches = match getopts::getopts(&args[1..], &opts) {
let mut matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(f) => {
crash!(1, "{}", f)
}
Err(f) => { crash!(1, "{}", f) }
};
if matches.opt_present("help") {
println!("{name} v{version}
let msg = format!("{name} v{version}
Usage:
{program} [OPTION]... MODE[,MODE]... FILE...
{program} [OPTION]... OCTAL-MODE FILE...
{program} [OPTION]... --reference=RFILE FILE...
{usage}
Change the mode of each FILE to MODE.
With --reference, change the mode of each FILE to that of RFILE.
Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+'.",
name = NAME, version = VERSION, program = program,
usage = getopts::usage("Change the mode of each FILE to MODE. \
\nWith --reference, change the mode of \
each FILE to that of RFILE.", &opts));
name = NAME, version = VERSION, program = NAME);
print!("{}", opts.usage(&msg));
return 0;
} else if matches.opt_present("version") {
println!("{} v{}", NAME, VERSION);
} else if matches.free.is_empty() && matches.opt_present("reference") || matches.free.len() < 2 {
show_error!("missing an argument");
show_error!("for help, try '{} --help'", program);
show_error!("for help, try '{} --help'", NAME);
return 1;
} else {
let changes = matches.opt_present("changes");
+33 -33
View File
@@ -1,5 +1,5 @@
#![crate_name = "chroot"]
#![feature(rustc_private, path_ext)]
#![feature(path_ext)]
/*
* This file is part of the uutils coreutils package.
@@ -13,10 +13,10 @@
extern crate getopts;
extern crate libc;
use getopts::{optflag, optopt, getopts, usage};
use c_types::{get_pw_from_args, get_group};
use getopts::Options;
use libc::funcs::posix88::unistd::{setgid, setuid};
use std::ffi::{CString};
use std::ffi::CString;
use std::fs::PathExt;
use std::io::{Error, Write};
use std::iter::FromIterator;
@@ -44,34 +44,32 @@ static NAME: &'static str = "chroot";
static VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> i32 {
let program = &args[0];
let mut opts = Options::new();
let options = [
optopt("u", "user", "User (ID or name) to switch before running the program", "USER"),
optopt("g", "group", "Group (ID or name) to switch to", "GROUP"),
optopt("G", "groups", "Comma-separated list of groups to switch to", "GROUP1,GROUP2…"),
optopt("", "userspec", "Colon-separated user and group to switch to. \
Same as -u USER -g GROUP. \
Userspec has higher preference than -u and/or -g", "USER:GROUP"),
optflag("h", "help", "Show help"),
optflag("V", "version", "Show program's version")
];
opts.optopt("u", "user", "User (ID or name) to switch before running the program", "USER");
opts.optopt("g", "group", "Group (ID or name) to switch to", "GROUP");
opts.optopt("G", "groups", "Comma-separated list of groups to switch to", "GROUP1,GROUP2…");
opts.optopt("", "userspec", "Colon-separated user and group to switch to. \
Same as -u USER -g GROUP. \
Userspec has higher preference than -u and/or -g", "USER:GROUP");
opts.optflag("h", "help", "Show help");
opts.optflag("V", "version", "Show program's version");
let opts = match getopts(&args[1..], &options) {
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(f) => {
show_error!("{}", f);
help_menu(program, &options);
help_menu(opts);
return 1
}
};
if opts.opt_present("V") { version(); return 0 }
if opts.opt_present("h") { help_menu(program, &options); return 0 }
if matches.opt_present("V") { version(); return 0 }
if matches.opt_present("h") { help_menu(opts); return 0 }
if opts.free.len() == 0 {
if matches.free.len() == 0 {
println!("Missing operand: NEWROOT");
println!("Try `{} --help` for more information.", program);
println!("Try `{} --help` for more information.", NAME);
return 1
}
@@ -79,12 +77,12 @@ pub fn uumain(args: Vec<String>) -> i32 {
let default_option: &'static str = "-i";
let user_shell = std::env::var("SHELL");
let newroot = Path::new(&opts.free[0][..]);
let newroot = Path::new(&matches.free[0][..]);
if !newroot.is_dir() {
crash!(1, "cannot change root directory to `{}`: no such directory", newroot.display());
}
let command: Vec<&str> = match opts.free.len() {
let command: Vec<&str> = match matches.free.len() {
1 => {
let shell: &str = match user_shell {
Err(_) => default_shell,
@@ -92,10 +90,10 @@ pub fn uumain(args: Vec<String>) -> i32 {
};
vec!(shell, default_option)
},
_ => opts.free[1..].iter().map(|x| &x[..]).collect()
_ => matches.free[1..].iter().map(|x| &x[..]).collect()
};
set_context(&newroot, &opts);
set_context(&newroot, &matches);
let pstatus = Command::new(command[0])
.args(&command[1..])
@@ -207,13 +205,15 @@ fn version() {
println!("{} v{}", NAME, VERSION)
}
fn help_menu(program: &str, options: &[getopts::OptGroup]) {
version();
println!("Usage:");
println!(" {} [OPTION]… NEWROOT [COMMAND [ARG]…]", program);
println!("");
print!("{}", usage(
"Run COMMAND with root directory set to NEWROOT.\n\
If COMMAND is not specified, it defaults to '${SHELL} -i'. \
If ${SHELL} is not set, /bin/sh is used.", options))
fn help_menu(options: Options) {
let msg = format!("{0} v{1}
Usage:
{0} [OPTION]… NEWROOT [COMMAND [ARG]…]
Run COMMAND with root directory set to NEWROOT.
If COMMAND is not specified, it defaults to '$(SHELL) -i'.
If $(SHELL) is not set, /bin/sh is used.", NAME, VERSION);
print!("{}", options.usage(&msg));
}
+15 -14
View File
@@ -1,5 +1,4 @@
#![crate_name = "cksum"]
#![feature(rustc_private)]
/*
* This file is part of the uutils coreutils package.
@@ -12,10 +11,11 @@
extern crate getopts;
use std::io::{self, stdin, Read, Write, BufReader};
use std::path::Path;
use getopts::Options;
use std::fs::File;
use std::io::{self, stdin, Read, Write, BufReader};
use std::mem;
use std::path::Path;
use crc_table::CRC_TABLE;
@@ -77,23 +77,24 @@ fn cksum(fname: &str) -> io::Result<(u32, usize)> {
}
pub fn uumain(args: Vec<String>) -> i32 {
let opts = [
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit"),
];
let mut opts = Options::new();
opts.optflag("h", "help", "display this help and exit");
opts.optflag("V", "version", "output version information and exit");
let matches = match getopts::getopts(&args[1..], &opts) {
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(err) => panic!("{}", err),
};
if matches.opt_present("help") {
println!("{} {}", NAME, VERSION);
println!("");
println!("Usage:");
println!(" {} [OPTIONS] [FILE]...", NAME);
println!("");
println!("{}", getopts::usage("Print CRC and size for each file.", opts.as_ref()));
let msg = format!("{0} {1}
Usage:
{0} [OPTIONS] [FILE]...
Print CRC and size for each file.", NAME, VERSION);
print!("{}", opts.usage(&msg));
return 0;
}
+21 -20
View File
@@ -1,5 +1,4 @@
#![crate_name = "comm"]
#![feature(rustc_private)]
/*
* This file is part of the uutils coreutils package.
@@ -12,13 +11,14 @@
extern crate getopts;
use getopts::Options;
use std::cmp::Ordering;
use std::io::{self, stdin, Stdin, BufReader, BufRead, Read};
use std::fs::File;
use std::io::{self, BufRead, BufReader, Read, stdin, Stdin};
use std::path::Path;
static NAME : &'static str = "comm";
static VERSION : &'static str = "1.0.0";
static NAME: &'static str = "comm";
static VERSION: &'static str = "1.0.0";
fn mkdelim(col: usize, opts: &getopts::Matches) -> String {
let mut s = String::new();
@@ -117,16 +117,15 @@ fn open_file(name: &str) -> io::Result<LineReader> {
}
pub fn uumain(args: Vec<String>) -> i32 {
let opts = [
getopts::optflag("1", "", "suppress column 1 (lines uniq to FILE1)"),
getopts::optflag("2", "", "suppress column 2 (lines uniq to FILE2)"),
getopts::optflag("3", "", "suppress column 3 (lines that appear in both files)"),
getopts::optopt("", "output-delimiter", "separate columns with STR", "STR"),
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit"),
];
let mut opts = Options::new();
opts.optflag("1", "", "suppress column 1 (lines uniq to FILE1)");
opts.optflag("2", "", "suppress column 2 (lines uniq to FILE2)");
opts.optflag("3", "", "suppress column 3 (lines that appear in both files)");
opts.optopt("", "output-delimiter", "separate columns with STR", "STR");
opts.optflag("h", "help", "display this help and exit");
opts.optflag("V", "version", "output version information and exit");
let matches = match getopts::getopts(&args[1..], &opts) {
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(err) => panic!("{}", err),
};
@@ -137,19 +136,21 @@ pub fn uumain(args: Vec<String>) -> i32 {
}
if matches.opt_present("help") || matches.free.len() != 2 {
println!("{} {}", NAME, VERSION);
println!("");
println!("Usage:");
println!(" {} [OPTIONS] FILE1 FILE2", NAME);
println!("");
print!("{}", getopts::usage("Compare sorted files line by line.", opts.as_ref()));
let msg = format!("{0} {1}
Usage:
{0} [OPTIONS] FILE1 FILE2
Compare sorted files line by line.", NAME, VERSION);
print!("{}", opts.usage(&msg));
if matches.free.len() != 2 {
return 1;
}
return 0;
}
let mut f1 = open_file(matches.free[0].as_ref()).unwrap();
let mut f2 = open_file(matches.free[1].as_ref()).unwrap();
+18 -18
View File
@@ -1,5 +1,4 @@
#![crate_name = "dirname"]
#![feature(rustc_private)]
/*
* This file is part of the uutils coreutils package.
@@ -14,35 +13,36 @@ extern crate getopts;
use std::path::Path;
static NAME: &'static str = "dirname";
static VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> i32 {
let program = args[0].clone();
let opts = [
getopts::optflag("z", "zero", "separate output with NUL rather than newline"),
getopts::optflag("", "help", "display this help and exit"),
getopts::optflag("", "version", "output version information and exit"),
];
let mut opts = getopts::Options::new();
opts.optflag("z", "zero", "separate output with NUL rather than newline");
opts.optflag("", "help", "display this help and exit");
opts.optflag("", "version", "output version information and exit");
let matches = match getopts::getopts(&args[1..], &opts) {
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(f) => panic!("Invalid options\n{}", f)
};
if matches.opt_present("help") {
println!("dirname {} - strip last component from file name", VERSION);
println!("");
println!("Usage:");
println!(" {0} [OPTION] NAME...", program);
println!("");
print!("{}", getopts::usage("Output each NAME with its last non-slash component and trailing slashes
let msg = format!("{0} {1} - strip last component from file name
Usage:
{0} [OPTION] NAME...
Output each NAME with its last non-slash component and trailing slashes
removed; if NAME contains no /'s, output '.' (meaning the current
directory).", &opts));
directory).", NAME, VERSION);
print!("{}", opts.usage(&msg));
return 0;
}
if matches.opt_present("version") {
println!("dirname version: {}", VERSION);
println!("{} {}", NAME, VERSION);
return 0;
}
@@ -61,8 +61,8 @@ directory).", &opts));
print!("{}", separator);
}
} else {
println!("{0}: missing operand", program);
println!("Try '{0} --help' for more information.", program);
println!("{0}: missing operand", NAME);
println!("Try '{0} --help' for more information.", NAME);
return 1;
}
+22 -22
View File
@@ -1,5 +1,4 @@
#![crate_name = "echo"]
#![feature(rustc_private)]
/*
* This file is part of the uutils coreutils package.
@@ -79,11 +78,10 @@ fn convert_str(string: &[u8], index: usize, base: u32) -> (char, usize) {
fn parse_options(args: Vec<String>, options: &mut EchoOptions) -> Option<Vec<String>> {
let mut echo_args = vec!();
let program = args[0].clone();
'argloop: for arg in args.into_iter().skip(1) {
match arg.as_ref() {
"--help" | "-h" => {
print_help(&program);
print_help();
return None;
}
"--version" | "-V" => {
@@ -99,7 +97,7 @@ fn parse_options(args: Vec<String>, options: &mut EchoOptions) -> Option<Vec<Str
for ch in arg.chars().skip(1) {
match ch {
'h' => {
print_help(&program);
print_help();
return None;
}
'V' => {
@@ -125,22 +123,22 @@ fn parse_options(args: Vec<String>, options: &mut EchoOptions) -> Option<Vec<Str
Some(echo_args)
}
fn print_help(program: &String) {
let opts = [
getopts::optflag("n", "", "do not output the trailing newline"),
getopts::optflag("e", "", "enable interpretation of backslash escapes"),
getopts::optflag("E", "", "disable interpretation of backslash escapes (default)"),
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit"),
];
println!("echo {} - display a line of text", VERSION);
println!("");
println!("Usage:");
println!(" {0} [SHORT-OPTION]... [STRING]...", *program);
println!(" {0} LONG-OPTION", *program);
println!("");
println!("{}", getopts::usage("Echo the STRING(s) to standard output.", &opts));
println!("{}", "If -e is in effect, the following sequences are recognized:
fn print_help() {
let mut opts = getopts::Options::new();
opts.optflag("n", "", "do not output the trailing newline");
opts.optflag("e", "", "enable interpretation of backslash escapes");
opts.optflag("E", "", "disable interpretation of backslash escapes (default)");
opts.optflag("h", "help", "display this help and exit");
opts.optflag("V", "version", "output version information and exit");
let msg = format!("{0} {1} - display a line of text
Usage:
{0} [SHORT-OPTION]... [STRING]...
{0} LONG-OPTION
Echo the STRING(s) to standard output.
If -e is in effect, the following sequences are recognized:
\\\\ backslash
\\a alert (BEL)
@@ -153,11 +151,13 @@ fn print_help(program: &String) {
\\t horizontal tab
\\v vertical tab
\\0NNN byte with octal value NNN (1 to 3 digits)
\\xHH byte with hexadecimal value HH (1 to 2 digits)");
\\xHH byte with hexadecimal value HH (1 to 2 digits)", NAME, VERSION);
print!("{}", opts.usage(&msg));
}
fn print_version() {
println!("echo version: {}", VERSION);
println!("{} {}", NAME, VERSION);
}
pub fn uumain(args: Vec<String>) -> i32 {
+18 -21
View File
@@ -1,5 +1,4 @@
#![crate_name = "factor"]
#![feature(rustc_private)]
/*
* This file is part of the uutils coreutils package.
@@ -20,12 +19,12 @@ extern crate rand;
use numeric::*;
use prime_table::P_INVS_U64;
use rand::weak_rng;
use rand::distributions::{Range, IndependentSample};
use std::cmp::{max, min};
use std::io::{stdin, BufRead, BufReader, Write};
use std::num::Wrapping;
use std::mem::swap;
use rand::weak_rng;
use rand::distributions::{Range, IndependentSample};
#[path="../common/util.rs"]
#[macro_use]
@@ -33,8 +32,8 @@ mod util;
mod numeric;
mod prime_table;
static VERSION: &'static str = "1.0.0";
static NAME: &'static str = "factor";
static VERSION: &'static str = "1.0.0";
fn rho_pollard_pseudorandom_function(x: u64, a: u64, b: u64, num: u64) -> u64 {
if num < 1 << 63 {
@@ -157,33 +156,31 @@ fn print_factors_str(num_str: &str) {
}
pub fn uumain(args: Vec<String>) -> i32 {
let opts = [
getopts::optflag("h", "help", "show this help message"),
getopts::optflag("v", "version", "print the version and exit"),
];
let mut opts = getopts::Options::new();
opts.optflag("h", "help", "show this help message");
opts.optflag("v", "version", "print the version and exit");
let matches = match getopts::getopts(&args[1..], &opts) {
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(f) => crash!(1, "Invalid options\n{}", f)
};
if matches.opt_present("help") {
print!("{program} {version}\n\
\n\
Usage:\n\
\t{program} [NUMBER]...\n\
\t{program} [OPTION]\n\
\n\
{usage}",
program = &args[0][..],
version = VERSION,
usage = getopts::usage("Print the prime factors of the given number(s). \
If none are specified, read from standard input.", &opts));
let msg = format!("{0} {1}
Usage:
\t{0} [NUMBER]...
\t{0} [OPTION]
Print the prime factors of the given number(s). If none are specified,
read from standard input.", NAME, VERSION);
print!("{}", opts.usage(&msg));
return 1;
}
if matches.opt_present("version") {
println!("{} {}", &args[0][..], VERSION);
println!("{} {}", NAME, VERSION);
return 0;
}
+12 -13
View File
@@ -1,5 +1,4 @@
#![crate_name = "groups"]
#![feature(rustc_private)]
/*
* This file is part of the uutils coreutils package.
@@ -13,7 +12,6 @@
extern crate getopts;
use c_types::{get_pw_from_args, group};
use getopts::{getopts, optflag, usage};
use std::io::Write;
#[path = "../common/util.rs"] #[macro_use] mod util;
@@ -23,14 +21,11 @@ static NAME: &'static str = "groups";
static VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> i32 {
let program = args[0].clone();
let mut opts = getopts::Options::new();
opts.optflag("h", "help", "display this help menu and exit");
opts.optflag("V", "version", "display version information and exit");
let options = [
optflag("h", "help", "display this help menu and exit"),
optflag("V", "version", "display version information and exit")
];
let matches = match getopts(&args[1..], &options) {
let matches = match opts.parse(&args[1..]) {
Ok(m) => { m },
Err(f) => {
show_error!("{}", f);
@@ -41,10 +36,14 @@ pub fn uumain(args: Vec<String>) -> i32 {
if matches.opt_present("version") {
println!("{} v{}", NAME, VERSION);
} else if matches.opt_present("help") {
print!("{} v{}\n\n\
Usage:\n \
{} [OPTION]... [USER]...\n\n\
{}", NAME, VERSION, program, usage("Prints the groups a user is in to standard output.", &options));
let msg = format!("{0} v{1}
Usage:
{0} [OPTION]... [USER]...
Prints the groups a user is in to standard output.", NAME, VERSION);
print!("{}", opts.usage(&msg));
} else {
group(get_pw_from_args(&matches.free), true);
}
+35 -42
View File
@@ -1,5 +1,4 @@
#![crate_name = "hashsum"]
#![feature(rustc_private)]
/*
* This file is part of the uutils coreutils package.
@@ -12,10 +11,9 @@
* file that was distributed with this source code.
*/
extern crate regex;
extern crate crypto;
extern crate getopts;
extern crate regex;
use crypto::digest::Digest;
use crypto::md5::Md5;
@@ -43,21 +41,6 @@ fn is_custom_binary(program: &str) -> bool {
}
}
fn get_algo_opts(program: &str) -> Vec<getopts::OptGroup> {
if is_custom_binary(program) {
Vec::new()
} else {
vec!(
getopts::optflag("", "md5", "work with MD5"),
getopts::optflag("", "sha1", "work with SHA1"),
getopts::optflag("", "sha224", "work with SHA224"),
getopts::optflag("", "sha256", "work with SHA256"),
getopts::optflag("", "sha384", "work with SHA384"),
getopts::optflag("", "sha512", "work with SHA512")
)
}
}
fn detect_algo(program: &str, matches: &getopts::Matches) -> (&'static str, Box<Digest+'static>) {
let mut alg: Option<Box<Digest>> = None;
let mut name: &'static str = "";
@@ -95,22 +78,28 @@ pub fn uumain(args: Vec<String>) -> i32 {
// Default binary in Windows, text mode otherwise
let binary_flag_default = cfg!(windows);
let mut opts: Vec<getopts::OptGroup> = vec!(
getopts::optflag("b", "binary", &format!("read in binary mode{}", if binary_flag_default { " (default)" } else { "" })),
getopts::optflag("c", "check", "read hashsums from the FILEs and check them"),
getopts::optflag("", "tag", "create a BSD-style checksum"),
getopts::optflag("t", "text", &format!("read in text mode{}", if binary_flag_default { "" } else { " (default)" })),
getopts::optflag("q", "quiet", "don't print OK for each successfully verified file"),
getopts::optflag("s", "status", "don't output anything, status code shows success"),
getopts::optflag("", "strict", "exit non-zero for improperly formatted checksum lines"),
getopts::optflag("w", "warn", "warn about improperly formatted checksum lines"),
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit"),
);
let mut opts = getopts::Options::new();
opts.optflag("b", "binary", &format!("read in binary mode{}", if binary_flag_default { " (default)" } else { "" }));
opts.optflag("c", "check", "read hashsums from the FILEs and check them");
opts.optflag("", "tag", "create a BSD-style checksum");
opts.optflag("t", "text", &format!("read in text mode{}", if binary_flag_default { "" } else { " (default)" }));
opts.optflag("q", "quiet", "don't print OK for each successfully verified file");
opts.optflag("s", "status", "don't output anything, status code shows success");
opts.optflag("", "strict", "exit non-zero for improperly formatted checksum lines");
opts.optflag("w", "warn", "warn about improperly formatted checksum lines");
opts.optflag("h", "help", "display this help and exit");
opts.optflag("V", "version", "output version information and exit");
opts.extend(get_algo_opts(binary_name).into_iter());
if !is_custom_binary(program) {
opts.optflag("", "md5", "work with MD5");
opts.optflag("", "sha1", "work with SHA1");
opts.optflag("", "sha224", "work with SHA224");
opts.optflag("", "sha256", "work with SHA256");
opts.optflag("", "sha384", "work with SHA384");
opts.optflag("", "sha512", "work with SHA512");
}
let matches = match getopts::getopts(&args[1..], &opts) {
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(f) => crash!(1, "{}", f)
};
@@ -152,17 +141,21 @@ fn version() {
pipe_println!("{} v{}", NAME, VERSION);
}
fn usage(program: &str, binary_name: &str, opts: &[getopts::OptGroup]) {
version();
pipe_println!("");
pipe_println!("Usage:");
if is_custom_binary(binary_name) {
pipe_println!(" {} [OPTION]... [FILE]...", program);
fn usage(program: &str, binary_name: &str, opts: &getopts::Options) {
let spec = if is_custom_binary(binary_name) {
format!(" {} [OPTION]... [FILE]...", program)
} else {
pipe_println!(" {} {{--md5|--sha1|--sha224|--sha256|--sha384|--sha512}} [OPTION]... [FILE]...", program);
}
pipe_println!("");
pipe_print!("{}", getopts::usage("Compute and check message digests.", opts));
format!(" {} {{--md5|--sha1|--sha224|--sha256|--sha384|--sha512}} [OPTION]... [FILE]...", program)
};
let msg = format!("{} v{}
Usage:
{}
Compute and check message digests.", NAME, VERSION, spec);
pipe_print!("{}", opts.usage(&msg));
}
fn hashsum<'a>(algoname: &str, mut digest: Box<Digest+'a>, files: Vec<String>, binary: bool, check: bool, tag: bool, status: bool, quiet: bool, strict: bool, warn: bool) -> Result<(), i32> {
+14 -25
View File
@@ -1,5 +1,4 @@
#![crate_name = "hostid"]
#![feature(rustc_private)]
/*
* This file is part of the uutils coreutils package.
@@ -11,20 +10,16 @@
*/
extern crate getopts;
extern crate serialize;
extern crate libc;
#[macro_use] extern crate log;
use getopts::{getopts, optflag, usage};
use libc::{c_long};
use std::io::Write;
use libc::c_long;
#[path = "../common/util.rs"]
#[macro_use]
mod util;
static NAME: &'static str = "hostid";
static VERSION: &'static str = "0.0.1";
static NAME: &'static str = "hostid";
static VERSION: &'static str = "0.0.1";
static EXIT_ERR: i32 = 1;
@@ -34,23 +29,20 @@ pub enum Mode {
Version,
}
//currently rust libc interface doesn't include gethostid
// currently rust libc interface doesn't include gethostid
extern {
pub fn gethostid() -> c_long;
}
pub fn uumain(args: Vec<String>) -> i32 {
let opts = [
optflag("", "help", "display this help and exit"),
optflag("", "version", "output version information and exit"),
];
let mut opts = getopts::Options::new();
opts.optflag("", "help", "display this help and exit");
opts.optflag("", "version", "output version information and exit");
let usage = usage("[options]", &opts);
let matches = match getopts(&args[1..], &opts) {
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(e) => {
show_error!("{}\n{}", e, get_help_text(NAME, usage.as_ref()));
Err(_) => {
help(&opts);
return EXIT_ERR;
},
};
@@ -65,7 +57,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
match mode {
Mode::HostId => hostid(),
Mode::Help => help(NAME, usage.as_ref()),
Mode::Help => help(&opts),
Mode::Version => version(),
}
@@ -76,12 +68,9 @@ fn version() {
println!("{} {}", NAME, VERSION);
}
fn get_help_text(progname: &str, usage: &str) -> String {
format!("Usage: \n {0} {1}", progname, usage)
}
fn help(progname: &str, usage: &str) {
println!("{}", get_help_text(progname, usage));
fn help(opts: &getopts::Options) {
let msg = format!("Usage:\n {} [options]", NAME);
print!("{}", opts.usage(&msg));
}
fn hostid() {
+18 -31
View File
@@ -1,5 +1,4 @@
#![crate_name = "id"]
#![feature(rustc_private)]
/*
* This file is part of the uutils coreutils package.
@@ -18,16 +17,11 @@
extern crate getopts;
extern crate libc;
use std::io::Write;
use std::ffi::CStr;
use std::ptr::read;
use libc::{
uid_t,
getgid,
getuid
};
use libc::{getgid, getuid, uid_t};
use libc::funcs::posix88::unistd::{getegid, geteuid, getlogin};
use getopts::{getopts, optflag, usage};
use std::ffi::CStr;
use std::io::Write;
use std::ptr::read;
use c_types::{
c_passwd,
c_group,
@@ -87,30 +81,27 @@ extern {
static NAME: &'static str = "id";
pub fn uumain(args: Vec<String>) -> i32 {
let args_t = &args[1..];
let mut opts = getopts::Options::new();
opts.optflag("h", "", "Show help");
opts.optflag("A", "", "Display the process audit (not available on Linux)");
opts.optflag("G", "", "Display the different group IDs");
opts.optflag("g", "", "Display the effective group ID as a number");
opts.optflag("n", "", "Display the name of the user or group ID for the -G, -g and -u options");
opts.optflag("P", "", "Display the id as a password file entry");
opts.optflag("p", "", "Make the output human-readable");
opts.optflag("r", "", "Display the real ID for the -g and -u options");
opts.optflag("u", "", "Display the effective user ID as a number");
let options = [
optflag("h", "", "Show help"),
optflag("A", "", "Display the process audit (not available on Linux)"),
optflag("G", "", "Display the different group IDs"),
optflag("g", "", "Display the effective group ID as a number"),
optflag("n", "", "Display the name of the user or group ID for the -G, -g and -u options"),
optflag("P", "", "Display the id as a password file entry"),
optflag("p", "", "Make the output human-readable"),
optflag("r", "", "Display the real ID for the -g and -u options"),
optflag("u", "", "Display the effective user ID as a number")
];
let matches = match getopts(args_t, &options) {
let matches = match opts.parse(&args[1..]) {
Ok(m) => { m },
Err(_) => {
println!("{}", usage(NAME, &options));
println!("{}", opts.usage(NAME));
return 1;
}
};
if matches.opt_present("h") {
println!("{}", usage(NAME, &options));
println!("{}", opts.usage(NAME));
return 0;
}
@@ -119,7 +110,6 @@ pub fn uumain(args: Vec<String>) -> i32 {
return 0;
}
let possible_pw = get_pw_from_args(&matches.free);
let nflag = matches.opt_present("n");
@@ -325,10 +315,7 @@ fn auditid() {
println!("asid={}", auditinfo.ai_asid);
}
fn id_print(possible_pw: Option<c_passwd>,
p_euid: bool,
p_egid: bool) {
fn id_print(possible_pw: Option<c_passwd>, p_euid: bool, p_egid: bool) {
let uid;
let gid;
+17 -23
View File
@@ -1,5 +1,4 @@
#![crate_name = "kill"]
#![feature(rustc_private)]
/*
* This file is part of the uutils coreutils package.
@@ -12,11 +11,7 @@
extern crate getopts;
extern crate libc;
extern crate serialize;
#[macro_use] extern crate log;
use getopts::{getopts, optflag, optflagopt, optopt, usage};
use libc::{c_int, pid_t};
use signals::ALL_SIGNALS;
use std::io::{Error, Write};
@@ -47,22 +42,20 @@ pub enum Mode {
}
pub fn uumain(args: Vec<String>) -> i32 {
let opts = [
optflag("h", "help", "display this help and exit"),
optflag("V", "version", "output version information and exit"),
optopt("s", "signal", "specify the <signal> to be sent", "SIGNAL"),
optflagopt("l", "list", "list all signal names, or convert one to a name", "LIST"),
optflag("L", "table", "list all signal names in a nice table"),
];
let mut opts = getopts::Options::new();
let usage = usage("[options] <pid> [...]", &opts);
opts.optflag("h", "help", "display this help and exit");
opts.optflag("V", "version", "output version information and exit");
opts.optopt("s", "signal", "specify the <signal> to be sent", "SIGNAL");
opts.optflagopt("l", "list", "list all signal names, or convert one to a name", "LIST");
opts.optflag("L", "table", "list all signal names in a nice table");
let (args, obs_signal) = handle_obsolete(args);
let matches = match getopts(&args[1..], &opts) {
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(e) => {
show_error!("{}\n{}", e, get_help_text(NAME, &usage));
Err(_) => {
help(&opts);
return EXIT_ERR;
},
};
@@ -83,7 +76,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
Mode::Kill => return kill(&matches.opt_str("signal").unwrap_or(obs_signal.unwrap_or("9".to_string())), matches.free),
Mode::Table => table(),
Mode::List => list(matches.opt_str("list")),
Mode::Help => help(NAME, &usage),
Mode::Help => help(&opts),
Mode::Version => version(),
}
@@ -98,7 +91,7 @@ fn handle_obsolete(mut args: Vec<String>) -> (Vec<String>, Option<String>) {
let mut i = 0;
while i < args.len() {
// this is safe because slice is valid when it is referenced
let slice = &args[i].clone();//unsafe { std::mem::transmute(args[i]) };
let slice = &args[i].clone();
if slice.chars().next().unwrap() == '-' && slice.len() > 1 && slice.chars().nth(1).unwrap().is_digit(10) {
let val = &slice[1..];
match val.parse() {
@@ -170,12 +163,13 @@ fn list(arg: Option<String>) {
};
}
fn get_help_text(progname: &str, usage: &str) -> String {
format!("Usage: \n {0} {1}", progname, usage)
}
fn help(opts: &getopts::Options) {
let msg = format!("{0} {1}
fn help(progname: &str, usage: &str) {
println!("{}", get_help_text(progname, usage));
Usage:
{0} [options] <pid> [...]", NAME, VERSION);
println!("{}", opts.usage(&msg));
}
fn kill(signalname: &str, pids: std::vec::Vec<String>) -> i32 {
+16 -15
View File
@@ -1,5 +1,4 @@
#![crate_name = "link"]
#![feature(rustc_private)]
/*
* This file is part of the uutils coreutils package.
@@ -12,24 +11,24 @@
extern crate getopts;
use std::io::Write;
use std::fs::hard_link;
use std::io::Write;
use std::path::Path;
#[path="../common/util.rs"]
#[macro_use]
mod util;
static NAME : &'static str = "link";
static VERSION : &'static str = "1.0.0";
static NAME: &'static str = "link";
static VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> i32 {
let opts = [
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit"),
];
let mut opts = getopts::Options::new();
let matches = match getopts::getopts(&args[1..], &opts) {
opts.optflag("h", "help", "display this help and exit");
opts.optflag("V", "version", "output version information and exit");
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(err) => panic!("{}", err),
};
@@ -40,12 +39,14 @@ pub fn uumain(args: Vec<String>) -> i32 {
}
if matches.opt_present("help") || matches.free.len() != 2 {
println!("{} {}", NAME, VERSION);
println!("");
println!("Usage:");
println!(" {} [OPTIONS] FILE1 FILE2", NAME);
println!("");
print!("{}", getopts::usage("Create a link named FILE2 to FILE1.", &opts));
let msg = format!("{0} {1}
Usage:
{0} [OPTIONS] FILE1 FILE2
Create a link named FILE2 to FILE1.", NAME, VERSION);
println!("{}", opts.usage(&msg));
if matches.free.len() != 2 {
return 1;
}
+14 -19
View File
@@ -1,5 +1,4 @@
#![crate_name = "logname"]
#![feature(rustc_private)]
/*
* This file is part of the uutils coreutils package.
@@ -39,37 +38,33 @@ fn get_userlogin() -> Option<String> {
static NAME: &'static str = "logname";
static VERSION: &'static str = "1.0.0";
fn version() {
println!("{} {}", NAME, VERSION);
}
pub fn uumain(args: Vec<String>) -> i32 {
let program = args[0].clone();
//
// Argument parsing
//
let opts = [
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit"),
];
let mut opts = getopts::Options::new();
let matches = match getopts::getopts(&args[1..], &opts) {
opts.optflag("h", "help", "display this help and exit");
opts.optflag("V", "version", "output version information and exit");
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(f) => crash!(1, "Invalid options\n{}", f)
};
if matches.opt_present("help") {
version();
println!("");
println!("Usage:");
println!(" {}", program);
println!("");
print!("{}", getopts::usage("print user's login name", &opts));
let msg = format!("{0} {1}
Usage:
{0}
Print user's login name.", NAME, VERSION);
print!("{}", opts.usage(&msg));
return 0;
}
if matches.opt_present("version") {
version();
println!("{} {}", NAME, VERSION);
return 0;
}
+17 -16
View File
@@ -1,5 +1,4 @@
#![crate_name = "mkfifo"]
#![feature(rustc_private)]
/*
* This file is part of the uutils coreutils package.
@@ -13,25 +12,25 @@
extern crate getopts;
extern crate libc;
use libc::funcs::posix88::stat_::mkfifo;
use std::ffi::CString;
use std::io::{Error, Write};
use libc::funcs::posix88::stat_::mkfifo;
#[path = "../common/util.rs"]
#[macro_use]
mod util;
static NAME : &'static str = "mkfifo";
static VERSION : &'static str = "1.0.0";
static NAME: &'static str = "mkfifo";
static VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> i32 {
let opts = [
getopts::optopt("m", "mode", "file permissions for the fifo", "(default 0666)"),
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit"),
];
let mut opts = getopts::Options::new();
let matches = match getopts::getopts(&args[1..], &opts) {
opts.optopt("m", "mode", "file permissions for the fifo", "(default 0666)");
opts.optflag("h", "help", "display this help and exit");
opts.optflag("V", "version", "output version information and exit");
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(err) => panic!("{}", err),
};
@@ -42,12 +41,14 @@ pub fn uumain(args: Vec<String>) -> i32 {
}
if matches.opt_present("help") || matches.free.is_empty() {
println!("{} {}", NAME, VERSION);
println!("");
println!("Usage:");
println!(" {} [OPTIONS] NAME...", NAME);
println!("");
print!("{}", getopts::usage("Create a FIFO with the given name.", &opts));
let msg = format!("{0} {1}
Usage:
{0} [OPTIONS] NAME...
Create a FIFO with the given name.", NAME, VERSION);
print!("{}", opts.usage(&msg));
if matches.free.is_empty() {
return 1;
}

Some files were not shown because too many files have changed in this diff Show More