mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
Merge pull request #975 from nathanross/normalize-coreopts-squashed
DRYer code and more UX consistency through use of coreopts
This commit is contained in:
@@ -8,7 +8,6 @@ name = "uu_base32"
|
||||
path = "base32.rs"
|
||||
|
||||
[dependencies]
|
||||
getopts = "*"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[dependencies.clippy]
|
||||
|
||||
+19
-47
@@ -8,46 +8,38 @@
|
||||
|
||||
#![crate_name = "uu_base32"]
|
||||
|
||||
extern crate getopts;
|
||||
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
use uucore::encoding::{Data, Format, wrap_print};
|
||||
|
||||
use getopts::Options;
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader, Read, stdin, Write};
|
||||
use std::path::Path;
|
||||
|
||||
static NAME: &'static str = "base32";
|
||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
static SYNTAX: &'static str = "[OPTION]... [FILE]";
|
||||
static SUMMARY: &'static str = "Base32 encode or decode FILE, or standard input, to standard output.";
|
||||
static LONG_HELP: &'static str = "
|
||||
With no FILE, or when FILE is -, read standard input.
|
||||
|
||||
The data are encoded as described for the base32 alphabet in RFC
|
||||
4648. When decoding, the input may contain newlines in addition
|
||||
to the bytes of the formal base32 alphabet. Use --ignore-garbage
|
||||
to attempt to recover from any other non-alphabet bytes in the
|
||||
encoded stream.
|
||||
";
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> i32 {
|
||||
let mut opts = Options::new();
|
||||
opts.optflag("d", "decode", "decode data");
|
||||
opts.optflag("i",
|
||||
let matches = new_coreopts!(SYNTAX, SUMMARY, LONG_HELP)
|
||||
.optflag("d", "decode", "decode data")
|
||||
.optflag("i",
|
||||
"ignore-garbage",
|
||||
"when decoding, ignore non-alphabetic characters");
|
||||
opts.optopt("w",
|
||||
"when decoding, ignore non-alphabetic characters")
|
||||
.optopt("w",
|
||||
"wrap",
|
||||
"wrap encoded lines after COLS character (default 76, 0 to disable wrapping)",
|
||||
"COLS");
|
||||
opts.optflag("", "help", "display this help text and exit");
|
||||
opts.optflag("", "version", "output version information and exit");
|
||||
let matches = match opts.parse(&args[1..]) {
|
||||
Ok(m) => m,
|
||||
Err(e) => {
|
||||
disp_err!("{}", e);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
if matches.opt_present("help") {
|
||||
return help(&opts);
|
||||
} else if matches.opt_present("version") {
|
||||
return version();
|
||||
}
|
||||
|
||||
"COLS")
|
||||
.parse(args);
|
||||
|
||||
let line_wrap = match matches.opt_str("wrap") {
|
||||
Some(s) => {
|
||||
match s.parse() {
|
||||
@@ -88,23 +80,3 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
fn help(opts: &Options) -> i32 {
|
||||
let msg = format!("Usage: {} [OPTION]... [FILE]\n\n\
|
||||
Base32 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 base32 alphabet in RFC \
|
||||
4648.\nWhen decoding, the input may contain newlines in addition \
|
||||
to the bytes of the formal\nbase32 alphabet. Use --ignore-garbage \
|
||||
to attempt to recover from any other\nnon-alphabet bytes in the \
|
||||
encoded stream.",
|
||||
NAME);
|
||||
|
||||
print!("{}", opts.usage(&msg));
|
||||
0
|
||||
}
|
||||
|
||||
fn version() -> i32 {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
0
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ name = "uu_base64"
|
||||
path = "base64.rs"
|
||||
|
||||
[dependencies]
|
||||
getopts = "*"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[[bin]]
|
||||
|
||||
+18
-45
@@ -9,45 +9,38 @@
|
||||
// that was distributed with this source code.
|
||||
//
|
||||
|
||||
extern crate getopts;
|
||||
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
use uucore::encoding::{Data, Format, wrap_print};
|
||||
|
||||
use getopts::Options;
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader, Read, stdin, Write};
|
||||
use std::path::Path;
|
||||
|
||||
static NAME: &'static str = "base64";
|
||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
static SYNTAX: &'static str = "[OPTION]... [FILE]";
|
||||
static SUMMARY: &'static str = "Base64 encode or decode FILE, or standard input, to standard output.";
|
||||
static LONG_HELP: &'static str = "
|
||||
With no FILE, or when FILE is -, read standard input.
|
||||
|
||||
The data are encoded as described for the base64 alphabet in RFC
|
||||
3548. When decoding, the input may contain newlines in addition
|
||||
to the bytes of the formal base64 alphabet. Use --ignore-garbage
|
||||
to attempt to recover from any other non-alphabet bytes in the
|
||||
encoded stream.
|
||||
";
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> i32 {
|
||||
let mut opts = Options::new();
|
||||
opts.optflag("d", "decode", "decode data");
|
||||
opts.optflag("i",
|
||||
let matches = new_coreopts!(SYNTAX, SUMMARY, LONG_HELP)
|
||||
.optflag("d", "decode", "decode data")
|
||||
.optflag("i",
|
||||
"ignore-garbage",
|
||||
"when decoding, ignore non-alphabetic characters");
|
||||
opts.optopt("w",
|
||||
"when decoding, ignore non-alphabetic characters")
|
||||
.optopt("w",
|
||||
"wrap",
|
||||
"wrap encoded lines after COLS character (default 76, 0 to disable wrapping)",
|
||||
"COLS");
|
||||
opts.optflag("", "help", "display this help text and exit");
|
||||
opts.optflag("", "version", "output version information and exit");
|
||||
let matches = match opts.parse(&args[1..]) {
|
||||
Ok(m) => m,
|
||||
Err(e) => {
|
||||
disp_err!("{}", e);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
if matches.opt_present("help") {
|
||||
return help(&opts);
|
||||
} else if matches.opt_present("version") {
|
||||
return version();
|
||||
}
|
||||
"COLS")
|
||||
.parse(args);
|
||||
|
||||
let line_wrap = match matches.opt_str("wrap") {
|
||||
Some(s) => {
|
||||
@@ -89,23 +82,3 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
fn help(opts: &Options) -> i32 {
|
||||
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);
|
||||
|
||||
print!("{}", opts.usage(&msg));
|
||||
0
|
||||
}
|
||||
|
||||
fn version() -> i32 {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
0
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ name = "uu_basename"
|
||||
path = "basename.rs"
|
||||
|
||||
[dependencies]
|
||||
getopts = "*"
|
||||
libc = "*"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
|
||||
+12
-32
@@ -9,49 +9,29 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
extern crate getopts;
|
||||
extern crate libc;
|
||||
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
|
||||
use getopts::Options;
|
||||
use std::io::Write;
|
||||
use std::path::{is_separator, PathBuf};
|
||||
|
||||
static NAME: &'static str = "basename";
|
||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
static SYNTAX: &'static str = "NAME [SUFFIX]";
|
||||
static SUMMARY: &'static str = "Print NAME with any leading directory components removed
|
||||
If specified, also remove a trailing SUFFIX";
|
||||
static LONG_HELP: &'static str = "";
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> i32 {
|
||||
//
|
||||
// Argument parsing
|
||||
//
|
||||
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 opts.parse(&args[1..]) {
|
||||
Ok(m) => m,
|
||||
Err(f) => crash!(1, "Invalid options\n{}", f)
|
||||
};
|
||||
|
||||
if matches.opt_present("help") {
|
||||
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!("{}", opts.usage(&msg));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.opt_present("version") {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
return 0;
|
||||
}
|
||||
let matches = new_coreopts!(SYNTAX, SUMMARY, LONG_HELP)
|
||||
.parse(args);
|
||||
|
||||
// too few arguments
|
||||
if args.len() < 2 {
|
||||
if matches.free.len() < 1 {
|
||||
crash!(
|
||||
1,
|
||||
"{0}: {1}\nTry '{0} --help' for more information.",
|
||||
@@ -60,12 +40,12 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||
);
|
||||
}
|
||||
// too many arguments
|
||||
else if args.len() > 3 {
|
||||
else if matches.free.len() > 2 {
|
||||
crash!(
|
||||
1,
|
||||
"{0}: extra operand '{1}'\nTry '{0} --help' for more information.",
|
||||
NAME,
|
||||
args[3]
|
||||
matches.free[2]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -73,10 +53,10 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||
// Main Program Processing
|
||||
//
|
||||
|
||||
let mut name = strip_dir(&args[1]);
|
||||
let mut name = strip_dir(&matches.free[0]);
|
||||
|
||||
if args.len() > 2 {
|
||||
let suffix = args[2].clone();
|
||||
if matches.free.len() > 1 {
|
||||
let suffix = matches.free[1].clone();
|
||||
name = strip_suffix(name.as_ref(), suffix.as_ref());
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ name = "uu_cat"
|
||||
path = "cat.rs"
|
||||
|
||||
[dependencies]
|
||||
getopts = "*"
|
||||
libc = "*"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
|
||||
+17
-35
@@ -11,53 +11,35 @@
|
||||
|
||||
/* last synced with: cat (GNU coreutils) 8.13 */
|
||||
|
||||
extern crate getopts;
|
||||
extern crate libc;
|
||||
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
|
||||
use getopts::Options;
|
||||
use std::fs::File;
|
||||
use std::intrinsics::{copy_nonoverlapping};
|
||||
use std::io::{stdout, stdin, stderr, Write, Read, Result};
|
||||
use uucore::fs::is_stdin_interactive;
|
||||
|
||||
static NAME: &'static str = "cat";
|
||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
static SYNTAX: &'static str = "[OPTION]... [FILE]...";
|
||||
static SUMMARY: &'static str = "Concatenate FILE(s), or standard input, to standard output
|
||||
With no FILE, or when FILE is -, read standard input.";
|
||||
static LONG_HELP: &'static str = "";
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> i32 {
|
||||
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") {
|
||||
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!("{} {}", NAME, VERSION);
|
||||
return 0;
|
||||
}
|
||||
let matches = new_coreopts!(SYNTAX, SUMMARY, LONG_HELP)
|
||||
.optflag("A", "show-all", "equivalent to -vET")
|
||||
.optflag("b", "number-nonblank",
|
||||
"number nonempty output lines, overrides -n")
|
||||
.optflag("e", "", "equivalent to -vE")
|
||||
.optflag("E", "show-ends", "display $ at end of each line")
|
||||
.optflag("n", "number", "number all output lines")
|
||||
.optflag("s", "squeeze-blank", "suppress repeated empty output lines")
|
||||
.optflag("t", "", "equivalent to -vT")
|
||||
.optflag("T", "show-tabs", "display TAB characters as ^I")
|
||||
.optflag("v", "show-nonprinting",
|
||||
"use ^ and M- notation, except for LF (\\n) and TAB (\\t)")
|
||||
.parse(args);
|
||||
|
||||
let number_mode = if matches.opt_present("b") {
|
||||
NumberingMode::NumberNonEmpty
|
||||
|
||||
@@ -8,7 +8,6 @@ name = "uu_chmod"
|
||||
path = "chmod.rs"
|
||||
|
||||
[dependencies]
|
||||
getopts = "*"
|
||||
libc = "*"
|
||||
uucore = { path="../uucore" }
|
||||
walker = "*"
|
||||
|
||||
+19
-35
@@ -9,14 +9,12 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
extern crate getopts;
|
||||
extern crate libc;
|
||||
extern crate walker;
|
||||
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
|
||||
use getopts::Options;
|
||||
use std::error::Error;
|
||||
use std::ffi::CString;
|
||||
use std::io::{self, Write};
|
||||
@@ -25,19 +23,25 @@ use std::path::Path;
|
||||
use walker::Walker;
|
||||
|
||||
const NAME: &'static str = "chmod";
|
||||
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
static SUMMARY: &'static str = "Change the mode of each FILE to MODE.
|
||||
With --reference, change the mode of each FILE to that of RFILE.";
|
||||
static LONG_HELP: &'static str = "
|
||||
Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+'.
|
||||
";
|
||||
|
||||
pub fn uumain(mut args: Vec<String>) -> i32 {
|
||||
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.optopt("", "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");
|
||||
let syntax = format!("[OPTION]... MODE[,MODE]... FILE...
|
||||
{0} [OPTION]... OCTAL-MODE FILE...
|
||||
{0} [OPTION]... --reference=RFILE FILE...", NAME);
|
||||
let mut opts = new_coreopts!(&syntax, SUMMARY, LONG_HELP);
|
||||
opts.optflag("c", "changes", "like verbose but report only when a change is made (unimplemented)")
|
||||
.optflag("f", "quiet", "suppress most error messages (unimplemented)") // TODO: support --silent
|
||||
.optflag("v", "verbose", "output a diagnostic for every file processed (unimplemented)")
|
||||
.optflag("", "no-preserve-root", "do not treat '/' specially (the default)")
|
||||
.optflag("", "preserve-root", "fail to operate recursively on '/'")
|
||||
.optopt("", "reference", "use RFILE's mode instead of MODE values", "RFILE")
|
||||
.optflag("R", "recursive", "change files and directories recursively");
|
||||
|
||||
// sanitize input for - at beginning (e.g. chmod -x testfile). Remove
|
||||
// the option and save it for later, after parsing is finished.
|
||||
let mut negative_option = None;
|
||||
@@ -59,28 +63,8 @@ pub fn uumain(mut args: Vec<String>) -> i32 {
|
||||
}
|
||||
}
|
||||
|
||||
let mut matches = match opts.parse(&args[1..]) {
|
||||
Ok(m) => m,
|
||||
Err(f) => { crash!(1, "{}", f) }
|
||||
};
|
||||
if matches.opt_present("help") {
|
||||
let msg = format!("{name} {version}
|
||||
|
||||
Usage:
|
||||
{program} [OPTION]... MODE[,MODE]... FILE...
|
||||
{program} [OPTION]... OCTAL-MODE FILE...
|
||||
{program} [OPTION]... --reference=RFILE FILE...
|
||||
|
||||
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 = NAME);
|
||||
|
||||
print!("{}", opts.usage(&msg));
|
||||
return 0;
|
||||
} else if matches.opt_present("version") {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
} else if matches.free.is_empty() {
|
||||
let mut matches = opts.parse(args);
|
||||
if matches.free.is_empty() {
|
||||
show_error!("missing an argument");
|
||||
show_error!("for help, try '{} --help'", NAME);
|
||||
return 1;
|
||||
|
||||
+21
-23
@@ -42,38 +42,35 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||
let mut opts = new_coreopts!(SYNTAX, SUMMARY, "");
|
||||
opts.optflag("c",
|
||||
"changes",
|
||||
"like verbose but report only when a change is made");
|
||||
opts.optflag("f", "silent", "");
|
||||
opts.optflag("", "quiet", "suppress most error messages");
|
||||
opts.optflag("v",
|
||||
"like verbose but report only when a change is made")
|
||||
.optflag("f", "silent", "")
|
||||
.optflag("", "quiet", "suppress most error messages")
|
||||
.optflag("v",
|
||||
"verbose",
|
||||
"output a diagnostic for every file processed");
|
||||
opts.optflag("", "dereference", "affect the referent of each symbolic link (this is the default), rather than the symbolic link itself");
|
||||
opts.optflag("h", "no-dereference", "affect symbolic links instead of any referenced file (useful only on systems that can change the ownership of a symlink)");
|
||||
"output a diagnostic for every file processed")
|
||||
.optflag("", "dereference", "affect the referent of each symbolic link (this is the default), rather than the symbolic link itself")
|
||||
.optflag("h", "no-dereference", "affect symbolic links instead of any referenced file (useful only on systems that can change the ownership of a symlink)")
|
||||
|
||||
opts.optopt("", "from", "change the owner and/or group of each file only if its current owner and/or group match those specified here. Either may be omitted, in which case a match is not required for the omitted attribute", "CURRENT_OWNER:CURRENT_GROUP");
|
||||
opts.optopt("",
|
||||
.optopt("", "from", "change the owner and/or group of each file only if its current owner and/or group match those specified here. Either may be omitted, in which case a match is not required for the omitted attribute", "CURRENT_OWNER:CURRENT_GROUP")
|
||||
.optopt("",
|
||||
"reference",
|
||||
"use RFILE's owner and group rather than specifying OWNER:GROUP values",
|
||||
"RFILE");
|
||||
|
||||
opts.optflag("",
|
||||
"RFILE")
|
||||
.optflag("",
|
||||
"no-preserve-root",
|
||||
"do not treat '/' specially (the default)");
|
||||
opts.optflag("", "preserve-root", "fail to operate recursively on '/'");
|
||||
"do not treat '/' specially (the default)")
|
||||
.optflag("", "preserve-root", "fail to operate recursively on '/'")
|
||||
|
||||
opts.optflag("R",
|
||||
.optflag("R",
|
||||
"recursive",
|
||||
"operate on files and directories recursively");
|
||||
opts.optflag("H",
|
||||
"operate on files and directories recursively")
|
||||
.optflag("H",
|
||||
"",
|
||||
"if a command line argument is a symbolic link to a directory, traverse it");
|
||||
opts.optflag("L",
|
||||
"if a command line argument is a symbolic link to a directory, traverse it")
|
||||
.optflag("L",
|
||||
"",
|
||||
"traverse every symbolic link to a directory encountered");
|
||||
opts.optflag("P", "", "do not traverse any symbolic links (default)");
|
||||
|
||||
let matches = opts.parse(args.clone());
|
||||
"traverse every symbolic link to a directory encountered")
|
||||
.optflag("P", "", "do not traverse any symbolic links (default)");
|
||||
|
||||
let mut bit_flag = FTS_PHYSICAL;
|
||||
let mut preserve_root = false;
|
||||
@@ -100,6 +97,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||
}
|
||||
}
|
||||
|
||||
let matches = opts.parse(args);
|
||||
let recursive = matches.opt_present("recursive");
|
||||
if recursive {
|
||||
if bit_flag == FTS_PHYSICAL {
|
||||
|
||||
+13
-40
@@ -17,7 +17,6 @@ extern crate uucore;
|
||||
use uucore::libc::{self, setgid, setuid, chroot, setgroups};
|
||||
use uucore::entries;
|
||||
|
||||
use getopts::Options;
|
||||
use std::ffi::CString;
|
||||
use std::io::{Error, Write};
|
||||
use std::iter::FromIterator;
|
||||
@@ -25,31 +24,22 @@ use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
static NAME: &'static str = "chroot";
|
||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
static SYNTAX: &'static str = "[OPTION]... NEWROOT [COMMAND [ARG]...]";
|
||||
static SUMMARY: &'static str = "Run COMMAND with root directory set to NEWROOT.";
|
||||
static LONG_HELP: &'static str = "
|
||||
If COMMAND is not specified, it defaults to '$(SHELL) -i'.
|
||||
If $(SHELL) is not set, /bin/sh is used.
|
||||
";
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> i32 {
|
||||
let mut opts = Options::new();
|
||||
|
||||
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. \
|
||||
let matches = new_coreopts!(SYNTAX, SUMMARY, LONG_HELP)
|
||||
.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");
|
||||
opts.optflag("h", "help", "Show help");
|
||||
opts.optflag("V", "version", "Show program's version");
|
||||
|
||||
let matches = match opts.parse(&args[1..]) {
|
||||
Ok(m) => m,
|
||||
Err(f) => {
|
||||
show_error!("{}", f);
|
||||
help_menu(opts);
|
||||
return 1
|
||||
}
|
||||
};
|
||||
|
||||
if matches.opt_present("V") { version(); return 0 }
|
||||
if matches.opt_present("h") { help_menu(opts); return 0 }
|
||||
Userspec has higher preference than -u and/or -g", "USER:GROUP")
|
||||
.parse(args);
|
||||
|
||||
if matches.free.is_empty() {
|
||||
println!("Missing operand: NEWROOT");
|
||||
@@ -184,20 +174,3 @@ fn set_user(user: &str) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn version() {
|
||||
println!("{} {}", NAME, VERSION)
|
||||
}
|
||||
|
||||
fn help_menu(options: Options) {
|
||||
let msg = format!("{0} {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));
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ name = "uu_cksum"
|
||||
path = "cksum.rs"
|
||||
|
||||
[dependencies]
|
||||
getopts = "*"
|
||||
libc = "*"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
|
||||
+5
-29
@@ -9,12 +9,10 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
extern crate getopts;
|
||||
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
|
||||
use getopts::Options;
|
||||
use std::fs::File;
|
||||
use std::io::{self, stdin, Read, Write, BufReader};
|
||||
#[cfg(not(windows))]
|
||||
@@ -25,8 +23,9 @@ use crc_table::CRC_TABLE;
|
||||
|
||||
mod crc_table;
|
||||
|
||||
static NAME: &'static str = "cksum";
|
||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
static SYNTAX: &'static str = "[OPTIONS] [FILE]...";
|
||||
static SUMMARY: &'static str = "Print CRC and size for each file";
|
||||
static LONG_HELP: &'static str = "";
|
||||
|
||||
#[inline]
|
||||
fn crc_update(crc: u32, input: u8) -> u32 {
|
||||
@@ -88,31 +87,8 @@ fn cksum(fname: &str) -> io::Result<(u32, usize)> {
|
||||
}
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> i32 {
|
||||
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 opts.parse(&args[1..]) {
|
||||
Ok(m) => m,
|
||||
Err(err) => panic!("{}", err),
|
||||
};
|
||||
|
||||
if matches.opt_present("help") {
|
||||
let msg = format!("{0} {1}
|
||||
|
||||
Usage:
|
||||
{0} [OPTIONS] [FILE]...
|
||||
|
||||
Print CRC and size for each file.", NAME, VERSION);
|
||||
|
||||
print!("{}", opts.usage(&msg));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.opt_present("version") {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
return 0;
|
||||
}
|
||||
let matches = new_coreopts!(SYNTAX, SUMMARY, LONG_HELP)
|
||||
.parse(args);
|
||||
|
||||
let files = matches.free;
|
||||
|
||||
|
||||
+2
-1
@@ -8,8 +8,9 @@ name = "uu_comm"
|
||||
path = "comm.rs"
|
||||
|
||||
[dependencies]
|
||||
getopts = "*"
|
||||
libc = "*"
|
||||
getopts = "*"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[[bin]]
|
||||
name = "comm"
|
||||
|
||||
+12
-36
@@ -11,14 +11,17 @@
|
||||
|
||||
extern crate getopts;
|
||||
|
||||
use getopts::Options;
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::fs::File;
|
||||
use std::io::{self, BufRead, BufReader, stdin, Stdin};
|
||||
use std::path::Path;
|
||||
|
||||
static NAME: &'static str = "comm";
|
||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
static SYNTAX: &'static str = "[OPTIONS] FILE1 FILE2";
|
||||
static SUMMARY: &'static str = "Compare sorted files line by line";
|
||||
static LONG_HELP: &'static str = "";
|
||||
|
||||
fn mkdelim(col: usize, opts: &getopts::Matches) -> String {
|
||||
let mut s = String::new();
|
||||
@@ -122,39 +125,12 @@ fn open_file(name: &str) -> io::Result<LineReader> {
|
||||
}
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> i32 {
|
||||
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 opts.parse(&args[1..]) {
|
||||
Ok(m) => m,
|
||||
Err(err) => panic!("{}", err),
|
||||
};
|
||||
|
||||
if matches.opt_present("version") {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.opt_present("help") || matches.free.len() != 2 {
|
||||
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 matches = new_coreopts!(SYNTAX, SUMMARY, LONG_HELP)
|
||||
.optflag("1", "", "suppress column 1 (lines uniq to FILE1)")
|
||||
.optflag("2", "", "suppress column 2 (lines uniq to FILE2)")
|
||||
.optflag("3", "", "suppress column 3 (lines that appear in both files)")
|
||||
.optopt("", "output-delimiter", "separate columns with STR", "STR")
|
||||
.parse(args);
|
||||
|
||||
let mut f1 = open_file(matches.free[0].as_ref()).unwrap();
|
||||
let mut f2 = open_file(matches.free[1].as_ref()).unwrap();
|
||||
|
||||
+12
-13
@@ -291,7 +291,7 @@ fn cut_fields<R: Read>(reader: R, ranges: &[Range], opts: &FieldOptions) -> i32
|
||||
match opts.out_delimeter {
|
||||
Some(ref o_delim) => {
|
||||
return cut_fields_delimiter(reader, ranges, &opts.delimiter,
|
||||
opts.only_delimited, newline_char, o_delim);
|
||||
opts.only_delimited, newline_char, o_delim)
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
@@ -417,18 +417,17 @@ fn cut_files(mut filenames: Vec<String>, mode: Mode) -> i32 {
|
||||
}
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> i32 {
|
||||
let mut opts = new_coreopts!(SYNTAX, SUMMARY, LONG_HELP);
|
||||
opts.optopt("b", "bytes", "filter byte columns from the input source", "sequence");
|
||||
opts.optopt("c", "characters", "alias for character mode", "sequence");
|
||||
opts.optopt("d", "delimiter", "specify the delimiter character that separates fields in the input source. Defaults to Tab.", "delimiter");
|
||||
opts.optopt("f", "fields", "filter field columns from the input source", "sequence");
|
||||
opts.optflag("n", "", "legacy option - has no effect.");
|
||||
opts.optflag("", "complement", "invert the filter - instead of displaying only the filtered columns, display all but those columns");
|
||||
opts.optflag("s", "only-delimited", "in field mode, only print lines which contain the delimiter");
|
||||
opts.optflag("z", "zero-terminated", "instead of filtering columns based on line, filter columns based on \\0 (NULL character)");
|
||||
opts.optopt("", "output-delimiter", "in field mode, replace the delimiter in output lines with this option's argument", "new delimiter");
|
||||
let matches = opts.parse(args);
|
||||
|
||||
let matches = new_coreopts!(SYNTAX, SUMMARY, LONG_HELP)
|
||||
.optopt("b", "bytes", "filter byte columns from the input source", "sequence")
|
||||
.optopt("c", "characters", "alias for character mode", "sequence")
|
||||
.optopt("d", "delimiter", "specify the delimiter character that separates fields in the input source. Defaults to Tab.", "delimiter")
|
||||
.optopt("f", "fields", "filter field columns from the input source", "sequence")
|
||||
.optflag("n", "", "legacy option - has no effect.")
|
||||
.optflag("", "complement", "invert the filter - instead of displaying only the filtered columns, display all but those columns")
|
||||
.optflag("s", "only-delimited", "in field mode, only print lines which contain the delimiter")
|
||||
.optflag("z", "zero-terminated", "instead of filtering columns based on line, filter columns based on \\0 (NULL character)")
|
||||
.optopt("", "output-delimiter", "in field mode, replace the delimiter in output lines with this option's argument", "new delimiter")
|
||||
.parse(args);
|
||||
let complement = matches.opt_present("complement");
|
||||
|
||||
let mode_parse = match (matches.opt_str("bytes"),
|
||||
|
||||
@@ -8,7 +8,6 @@ name = "uu_dircolors"
|
||||
path = "dircolors.rs"
|
||||
|
||||
[dependencies]
|
||||
getopts = "*"
|
||||
glob = "*"
|
||||
libc = "*"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
+15
-46
@@ -10,20 +10,23 @@
|
||||
|
||||
extern crate libc;
|
||||
extern crate glob;
|
||||
extern crate getopts;
|
||||
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
|
||||
use getopts::Options;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader, Write};
|
||||
use std::borrow::Borrow;
|
||||
use std::env;
|
||||
|
||||
static NAME: &'static str = "dircolors";
|
||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
static SYNTAX: &'static str = "[OPTION]... [FILE]";
|
||||
static SUMMARY: &'static str = "Output commands to set the LS_COLORS environment variable.";
|
||||
static LONG_HELP: &'static str = "
|
||||
If FILE is specified, read it to determine which colors to use for which
|
||||
file types and extensions. Otherwise, a precompiled database is used.
|
||||
For details on the format of these files, run 'dircolors --print-database'
|
||||
";
|
||||
|
||||
mod colors;
|
||||
use colors::INTERNAL_DB;
|
||||
@@ -55,49 +58,15 @@ pub fn guess_syntax() -> OutputFmt {
|
||||
}
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> i32 {
|
||||
let mut opts = Options::new();
|
||||
|
||||
opts.optflag("b", "sh", "output Bourne shell code to set LS_COLORS");
|
||||
opts.optflag("",
|
||||
let matches = new_coreopts!(SYNTAX, SUMMARY, LONG_HELP)
|
||||
.optflag("b", "sh", "output Bourne shell code to set LS_COLORS")
|
||||
.optflag("",
|
||||
"bourne-shell",
|
||||
"output Bourne shell code to set LS_COLORS");
|
||||
opts.optflag("c", "csh", "output C shell code to set LS_COLORS");
|
||||
opts.optflag("", "c-shell", "output C shell code to set LS_COLORS");
|
||||
opts.optflag("p", "print-database", "print the byte counts");
|
||||
|
||||
opts.optflag("h", "help", "display this help and exit");
|
||||
opts.optflag("", "version", "output version information and exit");
|
||||
|
||||
let matches = match opts.parse(&args[1..]) {
|
||||
Ok(m) => m,
|
||||
Err(f) => {
|
||||
disp_err!("{}", f);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
if matches.opt_present("help") {
|
||||
println!("Usage: {} [OPTION]... [FILE]
|
||||
Output commands to set the LS_COLORS environment variable.
|
||||
|
||||
Determine format of output:
|
||||
-b, --sh, --bourne-shell output Bourne shell code to set LS_COLORS
|
||||
-c, --csh, --c-shell output C shell code to set LS_COLORS
|
||||
-p, --print-database output defaults
|
||||
--help display this help and exit
|
||||
--version output version information and exit
|
||||
|
||||
If FILE is specified, read it to determine which colors to use for which
|
||||
file types and extensions. Otherwise, a precompiled database is used.
|
||||
For details on the format of these files, run 'dircolors --print-database'.",
|
||||
NAME);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if matches.opt_present("version") {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
return 0;
|
||||
}
|
||||
"output Bourne shell code to set LS_COLORS")
|
||||
.optflag("c", "csh", "output C shell code to set LS_COLORS")
|
||||
.optflag("", "c-shell", "output C shell code to set LS_COLORS")
|
||||
.optflag("p", "print-database", "print the byte counts")
|
||||
.parse(args);
|
||||
|
||||
if (matches.opt_present("csh") || matches.opt_present("c-shell") ||
|
||||
matches.opt_present("sh") || matches.opt_present("bourne-shell")) &&
|
||||
|
||||
@@ -8,8 +8,8 @@ name = "uu_dirname"
|
||||
path = "dirname.rs"
|
||||
|
||||
[dependencies]
|
||||
getopts = "*"
|
||||
libc = "*"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[[bin]]
|
||||
name = "dirname"
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user