mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 04:57:45 +00:00
Merge pull request #1156 from Arcterus/cleanup
Begin switching everything from getopts to clap
This commit is contained in:
commit
fa0b7ed41b
39 changed files with 139 additions and 124 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -1882,7 +1882,7 @@ name = "whoami"
|
|||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"advapi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"getopts 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clap 2.31.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uucore 0.0.1",
|
||||
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -1928,7 +1928,7 @@ dependencies = [
|
|||
name = "yes"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"getopts 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clap 2.31.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uucore 0.0.1",
|
||||
]
|
||||
|
||||
|
|
|
@ -10,10 +10,7 @@ path = "arch.rs"
|
|||
|
||||
[dependencies]
|
||||
platform-info = { git = "https://github.com/uutils/platform-info" }
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
default-features = false
|
||||
uucore = { path = "../uucore" }
|
||||
|
||||
[[bin]]
|
||||
name = "arch"
|
||||
|
|
|
@ -8,8 +8,9 @@ build = "../../mkmain.rs"
|
|||
name = "uu_base32"
|
||||
path = "base32.rs"
|
||||
|
||||
[dependencies]
|
||||
uucore = { path="../uucore" }
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
features = ["encoding"]
|
||||
|
||||
[dependencies.clippy]
|
||||
version = "0.0.143"
|
||||
|
|
|
@ -8,8 +8,9 @@ build = "../../mkmain.rs"
|
|||
name = "uu_base64"
|
||||
path = "base64.rs"
|
||||
|
||||
[dependencies]
|
||||
uucore = { path="../uucore" }
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
features = ["encoding"]
|
||||
|
||||
[[bin]]
|
||||
name = "base64"
|
||||
|
|
|
@ -10,7 +10,10 @@ path = "cat.rs"
|
|||
|
||||
[dependencies]
|
||||
quick-error = "1.1.0"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
features = ["fs"]
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
unix_socket = "0.5.0"
|
||||
|
|
|
@ -13,7 +13,6 @@ walkdir = "1.0.7"
|
|||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
default-features = false
|
||||
features = ["entries", "fs"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -10,9 +10,12 @@ path = "chmod.rs"
|
|||
|
||||
[dependencies]
|
||||
libc = "0.2.26"
|
||||
uucore = { path="../uucore" }
|
||||
walker = "1.0.0"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
features = ["mode"]
|
||||
|
||||
[[bin]]
|
||||
name = "chmod"
|
||||
path = "../../uumain.rs"
|
||||
|
|
|
@ -14,7 +14,6 @@ walkdir = "0.1"
|
|||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
default-features = false
|
||||
features = ["entries", "fs"]
|
||||
|
||||
[dependencies.clippy]
|
||||
|
|
|
@ -13,7 +13,6 @@ getopts = "0.2.14"
|
|||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
default-features = false
|
||||
features = ["entries"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -17,9 +17,12 @@ libc = "0.2.26"
|
|||
walkdir = "1.0.7"
|
||||
clap = "2.20.0"
|
||||
quick-error = "1.1.0"
|
||||
uucore = { path="../uucore" }
|
||||
filetime = "0.1"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
features = ["fs"]
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
ioctl-sys = "0.5.2"
|
||||
|
||||
|
|
5
src/env/env.rs
vendored
5
src/env/env.rs
vendored
|
@ -9,7 +9,6 @@
|
|||
*/
|
||||
|
||||
/* last synced with: env (GNU coreutils) 8.13 */
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
|
@ -25,7 +24,7 @@ static LONG_HELP: &'static str = "
|
|||
A mere - implies -i. If no COMMAND, print the resulting environment
|
||||
";
|
||||
|
||||
struct options {
|
||||
struct Options {
|
||||
ignore_env: bool,
|
||||
null: bool,
|
||||
unsets: Vec<String>,
|
||||
|
@ -52,7 +51,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
)
|
||||
.optopt("u", "unset", "remove variable from the environment", "NAME");
|
||||
|
||||
let mut opts = Box::new(options {
|
||||
let mut opts = Box::new(Options {
|
||||
ignore_env: false,
|
||||
null: false,
|
||||
unsets: vec![],
|
||||
|
|
|
@ -10,7 +10,6 @@ path = "groups.rs"
|
|||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
default-features = false
|
||||
features = ["entries"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -10,7 +10,6 @@ path = "id.rs"
|
|||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
default-features = false
|
||||
features = ["entries", "process"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -10,7 +10,10 @@ path = "kill.rs"
|
|||
|
||||
[dependencies]
|
||||
libc = "0.2.26"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
features = ["signals"]
|
||||
|
||||
[[bin]]
|
||||
name = "kill"
|
||||
|
|
|
@ -19,7 +19,6 @@ unicode-width = "0.1.4"
|
|||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
default-features = false
|
||||
features = ["entries"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -11,7 +11,10 @@ path = "nohup.rs"
|
|||
[dependencies]
|
||||
getopts = "0.2.14"
|
||||
libc = "0.2.26"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
features = ["fs"]
|
||||
|
||||
[[bin]]
|
||||
name = "nohup"
|
||||
|
|
|
@ -10,7 +10,6 @@ path = "pinky.rs"
|
|||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
default-features = false
|
||||
features = ["utmpx", "entries"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -11,7 +11,10 @@ path = "readlink.rs"
|
|||
[dependencies]
|
||||
getopts = "0.2.14"
|
||||
libc = "0.2.26"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
features = ["fs"]
|
||||
|
||||
[[bin]]
|
||||
name = "readlink"
|
||||
|
|
|
@ -10,7 +10,10 @@ path = "realpath.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "0.2.14"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
features = ["fs"]
|
||||
|
||||
[[bin]]
|
||||
name = "realpath"
|
||||
|
|
|
@ -10,7 +10,10 @@ path = "relpath.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "0.2.14"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
features = ["fs"]
|
||||
|
||||
[[bin]]
|
||||
name = "relpath"
|
||||
|
|
|
@ -10,7 +10,10 @@ path = "sleep.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "0.2.14"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
features = ["parse_time"]
|
||||
|
||||
[[bin]]
|
||||
name = "sleep"
|
||||
|
|
|
@ -12,7 +12,10 @@ path = "sort.rs"
|
|||
getopts = "0.2.14"
|
||||
semver = "0.7.0"
|
||||
itertools = "0.6.0"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
features = ["fs"]
|
||||
|
||||
[[bin]]
|
||||
name = "sort"
|
||||
|
|
|
@ -14,7 +14,6 @@ time = "0.1.38"
|
|||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
default-features = false
|
||||
features = ["entries"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -13,7 +13,10 @@ getopts = "0.2.14"
|
|||
libc = "0.2.26"
|
||||
winapi = { version = "0.3", features = ["handleapi", "winerror"] }
|
||||
kernel32-sys = "0.2.2"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
features = ["wide"]
|
||||
|
||||
[[bin]]
|
||||
name = "sync"
|
||||
|
|
|
@ -12,7 +12,10 @@ path = "timeout.rs"
|
|||
getopts = "0.2.14"
|
||||
libc = "0.2.26"
|
||||
time = "0.1.38"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
features = ["parse_time", "process"]
|
||||
|
||||
[[bin]]
|
||||
name = "timeout"
|
||||
|
|
|
@ -15,7 +15,6 @@ time = "0.1.38"
|
|||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
default-features = false
|
||||
features = ["libc"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -12,10 +12,7 @@ path = "tr.rs"
|
|||
getopts = "0.2.14"
|
||||
bit-set = "0.4.0"
|
||||
fnv = "1.0.5"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
default-features = false
|
||||
uucore = { path = "../uucore" }
|
||||
|
||||
[[bin]]
|
||||
name = "tr"
|
||||
|
|
|
@ -11,7 +11,10 @@ path = "tty.rs"
|
|||
[dependencies]
|
||||
getopts = "0.2.14"
|
||||
libc = "0.2.26"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
features = ["fs"]
|
||||
|
||||
[[bin]]
|
||||
name = "tty"
|
||||
|
|
|
@ -11,10 +11,7 @@ path = "uname.rs"
|
|||
[dependencies]
|
||||
clap = "2.20.0"
|
||||
platform-info = { git = "https://github.com/uutils/platform-info" }
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
default-features = false
|
||||
uucore = { path = "../uucore" }
|
||||
|
||||
[[bin]]
|
||||
name = "uname"
|
||||
|
|
|
@ -11,7 +11,10 @@ path = "unexpand.rs"
|
|||
[dependencies]
|
||||
getopts = "0.2.14"
|
||||
unicode-width = "0.1.4"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
features = ["utf8"]
|
||||
|
||||
[[bin]]
|
||||
name = "unexpand"
|
||||
|
|
|
@ -10,10 +10,7 @@ path = "uniq.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "0.2.14"
|
||||
|
||||
[dependencies.uucore]
|
||||
path="../uucore"
|
||||
default-features = false
|
||||
uucore = { path = "../uucore" }
|
||||
|
||||
[[bin]]
|
||||
name = "uniq"
|
||||
|
|
|
@ -13,7 +13,6 @@ getopts = "0.2.14"
|
|||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
default-features = false
|
||||
features = ["utmpx"]
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -12,7 +12,6 @@ path = "users.rs"
|
|||
getopts = "0.2.14"
|
||||
|
||||
[dependencies.uucore]
|
||||
default-features = false
|
||||
features = ["utmpx"]
|
||||
path = "../uucore"
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ process = ["libc"]
|
|||
signals = []
|
||||
entries = ["libc"]
|
||||
wide = []
|
||||
default = ["fs", "libc", "utf8", "encoding", "parse_time", "mode", "utmpx", "process", "entries", "signals", "wide"]
|
||||
default = []
|
||||
|
||||
[lib]
|
||||
path = "lib.rs"
|
||||
|
|
|
@ -10,7 +10,6 @@ path = "who.rs"
|
|||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
default-features = false
|
||||
features = ["utmpx"]
|
||||
|
||||
[dependencies.clippy]
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
name = "whoami"
|
||||
version = "0.0.1"
|
||||
authors = []
|
||||
description = "Print effective user ID."
|
||||
build = "../../mkmain.rs"
|
||||
|
||||
[lib]
|
||||
|
@ -9,14 +10,13 @@ name = "uu_whoami"
|
|||
path = "whoami.rs"
|
||||
|
||||
[dependencies]
|
||||
getopts = "0.2.14"
|
||||
clap = "2.31"
|
||||
winapi = { version = "0.3", features = ["lmcons"] }
|
||||
advapi32-sys = "0.2.0"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
default-features = false
|
||||
features = ["entries"]
|
||||
features = ["entries", "wide"]
|
||||
|
||||
[[bin]]
|
||||
name = "whoami"
|
||||
|
|
|
@ -11,45 +11,34 @@
|
|||
|
||||
/* last synced with: whoami (GNU coreutils) 8.21 */
|
||||
|
||||
extern crate getopts;
|
||||
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
|
||||
use getopts::Options;
|
||||
|
||||
mod platform;
|
||||
|
||||
static NAME: &'static str = "whoami";
|
||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
// force a re-build whenever Cargo.toml changes
|
||||
const _CARGO_TOML: &'static str = include_str!("Cargo.toml");
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> i32 {
|
||||
let mut opts = Options::new();
|
||||
let app = app_from_crate!();
|
||||
|
||||
opts.optflag("h", "help", "display this help and exit");
|
||||
opts.optflag("V", "version", "output version information and exit");
|
||||
if let Err(err) = app.get_matches_from_safe(args) {
|
||||
if err.kind == clap::ErrorKind::HelpDisplayed
|
||||
|| err.kind == clap::ErrorKind::VersionDisplayed
|
||||
{
|
||||
println!("{}", err);
|
||||
0
|
||||
} else {
|
||||
show_error!("{}", err);
|
||||
1
|
||||
}
|
||||
} else {
|
||||
exec();
|
||||
|
||||
let matches = match opts.parse(&args[1..]) {
|
||||
Ok(m) => m,
|
||||
Err(f) => crash!(1, "{}", f),
|
||||
};
|
||||
if matches.opt_present("help") {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
println!("");
|
||||
println!("Usage:");
|
||||
println!(" {} [OPTIONS]", NAME);
|
||||
println!("");
|
||||
println!("{}", opts.usage("print effective userid"));
|
||||
return 0;
|
||||
0
|
||||
}
|
||||
if matches.opt_present("version") {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
exec();
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
pub fn exec() {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
name = "yes"
|
||||
version = "0.0.1"
|
||||
authors = []
|
||||
description = "Repeatedly output a line with all specified STRING(s), or 'y'."
|
||||
build = "../../mkmain.rs"
|
||||
|
||||
[lib]
|
||||
|
@ -9,8 +10,8 @@ name = "uu_yes"
|
|||
path = "yes.rs"
|
||||
|
||||
[dependencies]
|
||||
getopts = "0.2.14"
|
||||
uucore = { path="../uucore" }
|
||||
clap = "2.31"
|
||||
uucore = { path = "../uucore" }
|
||||
|
||||
[[bin]]
|
||||
name = "yes"
|
||||
|
|
|
@ -11,63 +11,69 @@
|
|||
|
||||
/* last synced with: yes (GNU coreutils) 8.13 */
|
||||
|
||||
extern crate getopts;
|
||||
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
|
||||
use getopts::Options;
|
||||
use clap::Arg;
|
||||
use std::borrow::Cow;
|
||||
use std::io::{self, Write};
|
||||
|
||||
static NAME: &'static str = "yes";
|
||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
// force a re-build whenever Cargo.toml changes
|
||||
const _CARGO_TOML: &'static str = include_str!("Cargo.toml");
|
||||
|
||||
const BUF_SIZE: usize = 8192;
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> i32 {
|
||||
let mut opts = Options::new();
|
||||
let app = app_from_crate!().arg(Arg::with_name("STRING").index(1).multiple(true));
|
||||
|
||||
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..]) {
|
||||
let matches = match app.get_matches_from_safe(args) {
|
||||
Ok(m) => m,
|
||||
Err(f) => crash!(1, "invalid options\n{}", f),
|
||||
Err(ref e)
|
||||
if e.kind == clap::ErrorKind::HelpDisplayed
|
||||
|| e.kind == clap::ErrorKind::VersionDisplayed =>
|
||||
{
|
||||
println!("{}", e);
|
||||
return 0;
|
||||
}
|
||||
Err(f) => {
|
||||
show_error!("{}", f);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
if matches.opt_present("help") {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
println!("");
|
||||
println!("Usage:");
|
||||
println!(" {0} [STRING]... [OPTION]...", NAME);
|
||||
println!("");
|
||||
print!(
|
||||
"{}",
|
||||
opts.usage("Repeatedly output a line with all specified STRING(s), or 'y'.")
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
if matches.opt_present("version") {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
return 0;
|
||||
}
|
||||
let string = if matches.free.is_empty() {
|
||||
"y".to_owned()
|
||||
|
||||
let string = if let Some(values) = matches.values_of("STRING") {
|
||||
let mut result = values.fold(String::new(), |res, s| res + s + " ");
|
||||
result.pop();
|
||||
result.push('\n');
|
||||
Cow::from(result)
|
||||
} else {
|
||||
matches.free.join(" ")
|
||||
Cow::from("y\n")
|
||||
};
|
||||
|
||||
let mut multistring = string.clone();
|
||||
while multistring.len() < BUF_SIZE - string.len() - 1 {
|
||||
multistring.push_str("\n");
|
||||
multistring.push_str(&string);
|
||||
}
|
||||
let mut buffer = [0; BUF_SIZE];
|
||||
let bytes = if string.len() < BUF_SIZE / 2 {
|
||||
let mut size = 0;
|
||||
while size < BUF_SIZE - string.len() {
|
||||
let (_, right) = buffer.split_at_mut(size);
|
||||
right[..string.len()].copy_from_slice(string.as_bytes());
|
||||
size += string.len();
|
||||
}
|
||||
&buffer[..size]
|
||||
} else {
|
||||
string.as_bytes()
|
||||
};
|
||||
|
||||
exec(&multistring[..]);
|
||||
exec(bytes);
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
pub fn exec(string: &str) {
|
||||
pub fn exec(bytes: &[u8]) {
|
||||
let stdout_raw = io::stdout();
|
||||
let mut stdout = stdout_raw.lock();
|
||||
loop {
|
||||
println!("{}", string)
|
||||
stdout.write_all(bytes).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue