diff --git a/Cargo.lock b/Cargo.lock index db334658a..f7fb30ba2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", ] diff --git a/src/arch/Cargo.toml b/src/arch/Cargo.toml index 052233759..5d8703f80 100644 --- a/src/arch/Cargo.toml +++ b/src/arch/Cargo.toml @@ -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" diff --git a/src/base32/Cargo.toml b/src/base32/Cargo.toml index 683f3f350..4ac1b296b 100644 --- a/src/base32/Cargo.toml +++ b/src/base32/Cargo.toml @@ -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" diff --git a/src/base64/Cargo.toml b/src/base64/Cargo.toml index 1c6e88171..dc25dea95 100644 --- a/src/base64/Cargo.toml +++ b/src/base64/Cargo.toml @@ -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" diff --git a/src/cat/Cargo.toml b/src/cat/Cargo.toml index f0d52e9a0..135b8ddea 100644 --- a/src/cat/Cargo.toml +++ b/src/cat/Cargo.toml @@ -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" diff --git a/src/chgrp/Cargo.toml b/src/chgrp/Cargo.toml index 6f338234e..08be38d9f 100644 --- a/src/chgrp/Cargo.toml +++ b/src/chgrp/Cargo.toml @@ -13,7 +13,6 @@ walkdir = "1.0.7" [dependencies.uucore] path = "../uucore" -default-features = false features = ["entries", "fs"] [[bin]] diff --git a/src/chmod/Cargo.toml b/src/chmod/Cargo.toml index f4b89c8ad..85760b5a2 100644 --- a/src/chmod/Cargo.toml +++ b/src/chmod/Cargo.toml @@ -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" diff --git a/src/chown/Cargo.toml b/src/chown/Cargo.toml index ceff8e315..7e94ada42 100644 --- a/src/chown/Cargo.toml +++ b/src/chown/Cargo.toml @@ -14,7 +14,6 @@ walkdir = "0.1" [dependencies.uucore] path = "../uucore" -default-features = false features = ["entries", "fs"] [dependencies.clippy] diff --git a/src/chroot/Cargo.toml b/src/chroot/Cargo.toml index 450d9e897..d5bcba708 100644 --- a/src/chroot/Cargo.toml +++ b/src/chroot/Cargo.toml @@ -13,7 +13,6 @@ getopts = "0.2.14" [dependencies.uucore] path = "../uucore" -default-features = false features = ["entries"] [[bin]] diff --git a/src/cp/Cargo.toml b/src/cp/Cargo.toml index 022843562..b529c40b7 100644 --- a/src/cp/Cargo.toml +++ b/src/cp/Cargo.toml @@ -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" diff --git a/src/env/env.rs b/src/env/env.rs index 1aa8520ff..8b7af61bf 100644 --- a/src/env/env.rs +++ b/src/env/env.rs @@ -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, @@ -52,7 +51,7 @@ pub fn uumain(args: Vec) -> 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![], diff --git a/src/groups/Cargo.toml b/src/groups/Cargo.toml index 0d0ff38f8..71cf5ac52 100644 --- a/src/groups/Cargo.toml +++ b/src/groups/Cargo.toml @@ -10,7 +10,6 @@ path = "groups.rs" [dependencies.uucore] path = "../uucore" -default-features = false features = ["entries"] [[bin]] diff --git a/src/id/Cargo.toml b/src/id/Cargo.toml index 1e2f863b7..784cbfa35 100644 --- a/src/id/Cargo.toml +++ b/src/id/Cargo.toml @@ -10,7 +10,6 @@ path = "id.rs" [dependencies.uucore] path = "../uucore" -default-features = false features = ["entries", "process"] [[bin]] diff --git a/src/kill/Cargo.toml b/src/kill/Cargo.toml index 41d91294f..8a530c685 100644 --- a/src/kill/Cargo.toml +++ b/src/kill/Cargo.toml @@ -10,7 +10,10 @@ path = "kill.rs" [dependencies] libc = "0.2.26" -uucore = { path="../uucore" } + +[dependencies.uucore] +path = "../uucore" +features = ["signals"] [[bin]] name = "kill" diff --git a/src/ls/Cargo.toml b/src/ls/Cargo.toml index fa6ecec1d..05fa01611 100644 --- a/src/ls/Cargo.toml +++ b/src/ls/Cargo.toml @@ -19,7 +19,6 @@ unicode-width = "0.1.4" [dependencies.uucore] path = "../uucore" -default-features = false features = ["entries"] [[bin]] diff --git a/src/nohup/Cargo.toml b/src/nohup/Cargo.toml index 6be2c707c..0fecd736d 100644 --- a/src/nohup/Cargo.toml +++ b/src/nohup/Cargo.toml @@ -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" diff --git a/src/pinky/Cargo.toml b/src/pinky/Cargo.toml index 7bd38dc77..2bac97232 100644 --- a/src/pinky/Cargo.toml +++ b/src/pinky/Cargo.toml @@ -10,7 +10,6 @@ path = "pinky.rs" [dependencies.uucore] path = "../uucore" -default-features = false features = ["utmpx", "entries"] [[bin]] diff --git a/src/readlink/Cargo.toml b/src/readlink/Cargo.toml index 42649257f..1e52942a0 100644 --- a/src/readlink/Cargo.toml +++ b/src/readlink/Cargo.toml @@ -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" diff --git a/src/realpath/Cargo.toml b/src/realpath/Cargo.toml index affac2f83..1d7b30130 100644 --- a/src/realpath/Cargo.toml +++ b/src/realpath/Cargo.toml @@ -10,7 +10,10 @@ path = "realpath.rs" [dependencies] getopts = "0.2.14" -uucore = { path="../uucore" } + +[dependencies.uucore] +path = "../uucore" +features = ["fs"] [[bin]] name = "realpath" diff --git a/src/relpath/Cargo.toml b/src/relpath/Cargo.toml index 402ac5888..69936f396 100644 --- a/src/relpath/Cargo.toml +++ b/src/relpath/Cargo.toml @@ -10,7 +10,10 @@ path = "relpath.rs" [dependencies] getopts = "0.2.14" -uucore = { path="../uucore" } + +[dependencies.uucore] +path = "../uucore" +features = ["fs"] [[bin]] name = "relpath" diff --git a/src/sleep/Cargo.toml b/src/sleep/Cargo.toml index ad196cf7c..e4a7b014c 100644 --- a/src/sleep/Cargo.toml +++ b/src/sleep/Cargo.toml @@ -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" diff --git a/src/sort/Cargo.toml b/src/sort/Cargo.toml index cb5985b76..fbf6870fc 100644 --- a/src/sort/Cargo.toml +++ b/src/sort/Cargo.toml @@ -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" diff --git a/src/stat/Cargo.toml b/src/stat/Cargo.toml index 49c0cb641..bf66d2779 100644 --- a/src/stat/Cargo.toml +++ b/src/stat/Cargo.toml @@ -14,7 +14,6 @@ time = "0.1.38" [dependencies.uucore] path = "../uucore" -default-features = false features = ["entries"] [[bin]] diff --git a/src/sync/Cargo.toml b/src/sync/Cargo.toml index 22fcc2f82..b82b55999 100644 --- a/src/sync/Cargo.toml +++ b/src/sync/Cargo.toml @@ -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" diff --git a/src/timeout/Cargo.toml b/src/timeout/Cargo.toml index ae28ccc59..75ce9a289 100644 --- a/src/timeout/Cargo.toml +++ b/src/timeout/Cargo.toml @@ -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" diff --git a/src/touch/Cargo.toml b/src/touch/Cargo.toml index c7b8e4a26..90dcae2b3 100644 --- a/src/touch/Cargo.toml +++ b/src/touch/Cargo.toml @@ -15,7 +15,6 @@ time = "0.1.38" [dependencies.uucore] path = "../uucore" -default-features = false features = ["libc"] [[bin]] diff --git a/src/tr/Cargo.toml b/src/tr/Cargo.toml index 054fece62..2027fab87 100644 --- a/src/tr/Cargo.toml +++ b/src/tr/Cargo.toml @@ -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" diff --git a/src/tty/Cargo.toml b/src/tty/Cargo.toml index 6fd2abd24..be18d0488 100644 --- a/src/tty/Cargo.toml +++ b/src/tty/Cargo.toml @@ -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" diff --git a/src/uname/Cargo.toml b/src/uname/Cargo.toml index c9cef3767..6498ad7bf 100644 --- a/src/uname/Cargo.toml +++ b/src/uname/Cargo.toml @@ -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" diff --git a/src/unexpand/Cargo.toml b/src/unexpand/Cargo.toml index 49bca8ba3..85d7d15b9 100644 --- a/src/unexpand/Cargo.toml +++ b/src/unexpand/Cargo.toml @@ -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" diff --git a/src/uniq/Cargo.toml b/src/uniq/Cargo.toml index 0ef73fc66..27ba4b672 100644 --- a/src/uniq/Cargo.toml +++ b/src/uniq/Cargo.toml @@ -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" diff --git a/src/uptime/Cargo.toml b/src/uptime/Cargo.toml index 275050bbc..cb01f2b31 100644 --- a/src/uptime/Cargo.toml +++ b/src/uptime/Cargo.toml @@ -13,7 +13,6 @@ getopts = "0.2.14" [dependencies.uucore] path = "../uucore" -default-features = false features = ["utmpx"] [[bin]] diff --git a/src/users/Cargo.toml b/src/users/Cargo.toml index 007d23973..9513035c8 100644 --- a/src/users/Cargo.toml +++ b/src/users/Cargo.toml @@ -12,7 +12,6 @@ path = "users.rs" getopts = "0.2.14" [dependencies.uucore] -default-features = false features = ["utmpx"] path = "../uucore" diff --git a/src/uucore/Cargo.toml b/src/uucore/Cargo.toml index e1e56fed3..d18f834b3 100644 --- a/src/uucore/Cargo.toml +++ b/src/uucore/Cargo.toml @@ -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" diff --git a/src/who/Cargo.toml b/src/who/Cargo.toml index 2275d67e2..51781a29f 100644 --- a/src/who/Cargo.toml +++ b/src/who/Cargo.toml @@ -10,7 +10,6 @@ path = "who.rs" [dependencies.uucore] path = "../uucore" -default-features = false features = ["utmpx"] [dependencies.clippy] diff --git a/src/whoami/Cargo.toml b/src/whoami/Cargo.toml index 932df68ba..835e8569b 100644 --- a/src/whoami/Cargo.toml +++ b/src/whoami/Cargo.toml @@ -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" diff --git a/src/whoami/whoami.rs b/src/whoami/whoami.rs index 13bcc586a..097812706 100644 --- a/src/whoami/whoami.rs +++ b/src/whoami/whoami.rs @@ -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) -> 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() { diff --git a/src/yes/Cargo.toml b/src/yes/Cargo.toml index ae5bf20f6..5c98a3e65 100644 --- a/src/yes/Cargo.toml +++ b/src/yes/Cargo.toml @@ -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" diff --git a/src/yes/yes.rs b/src/yes/yes.rs index 99b4efb81..35398ffa8 100644 --- a/src/yes/yes.rs +++ b/src/yes/yes.rs @@ -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) -> 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(); } }