mirror of
https://github.com/uutils/coreutils
synced 2024-12-14 23:32:39 +00:00
commit
8328ba2e0a
1 changed files with 38 additions and 26 deletions
|
@ -19,16 +19,16 @@ use std::collections::hashmap::HashMap;
|
|||
static NAME: &'static str = "uutils";
|
||||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
fn util_map() -> HashMap<&str, fn(Vec<String>) -> int> {
|
||||
fn util_map() -> HashMap<&'static str, fn(Vec<String>) -> int> {
|
||||
fn uutrue(_: Vec<String>) -> int { 0 }
|
||||
fn uufalse(_: Vec<String>) -> int { 1 }
|
||||
|
||||
let mut map = HashMap::<&str, fn(Vec<String>) -> int>::new();
|
||||
let mut map = HashMap::new();
|
||||
@UTIL_MAP@
|
||||
map
|
||||
}
|
||||
|
||||
fn usage(cmap: &HashMap<&str, fn(Vec<String>) -> int>) {
|
||||
fn usage(cmap: &HashMap<&'static str, fn(Vec<String>) -> int>) {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
println!("");
|
||||
println!("Usage:");
|
||||
|
@ -49,11 +49,16 @@ fn main() {
|
|||
// try binary name as util name.
|
||||
let binary = Path::new(args.get(0).as_slice());
|
||||
let binary_as_util = binary.filename_str().unwrap();
|
||||
if umap.contains_key(&binary_as_util) {
|
||||
let &uumain = umap.get(&binary_as_util);
|
||||
os::set_exit_status(uumain(args));
|
||||
return
|
||||
} else if binary_as_util.starts_with("uutils")
|
||||
|
||||
match umap.find_equiv(&binary_as_util) {
|
||||
Some(&uumain) => {
|
||||
os::set_exit_status(uumain(args));
|
||||
return
|
||||
}
|
||||
None => (),
|
||||
}
|
||||
|
||||
if binary_as_util.starts_with("uutils")
|
||||
|| binary_as_util.starts_with("busybox") {
|
||||
// uutils can be called as either "uutils", "busybox"
|
||||
// "uutils-suffix" or "busybox-suffix". Not sure
|
||||
|
@ -68,17 +73,31 @@ fn main() {
|
|||
if args.len() >= 2 {
|
||||
args.shift();
|
||||
let util = args.get(0).as_slice();
|
||||
if umap.contains_key(&util) {
|
||||
let &uumain = umap.get(&util);
|
||||
os::set_exit_status(uumain(args.clone()));
|
||||
return
|
||||
} else if args.get(0).as_slice() == "--help" {
|
||||
// see if they want help on a specific util
|
||||
if args.len() >= 2 {
|
||||
let util = args.get(1).as_slice();
|
||||
if umap.contains_key(&util) {
|
||||
let &uumain = umap.get(&util);
|
||||
os::set_exit_status(uumain(vec!["--help".to_string()]));
|
||||
|
||||
match umap.find_equiv(&util) {
|
||||
Some(&uumain) => {
|
||||
os::set_exit_status(uumain(args.clone()));
|
||||
return
|
||||
}
|
||||
None => {
|
||||
if args.get(0).as_slice() == "--help" {
|
||||
// see if they want help on a specific util
|
||||
if args.len() >= 2 {
|
||||
let util = args.get(1).as_slice();
|
||||
match umap.find_equiv(&util) {
|
||||
Some(&uumain) => {
|
||||
os::set_exit_status(uumain(vec![util.to_string(), "--help".to_string()]));
|
||||
return
|
||||
}
|
||||
None => {
|
||||
println!("{}: applet not found", util);
|
||||
os::set_exit_status(1);
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
usage(&umap);
|
||||
os::set_exit_status(0);
|
||||
return
|
||||
} else {
|
||||
println!("{}: applet not found", util);
|
||||
|
@ -86,13 +105,6 @@ fn main() {
|
|||
return
|
||||
}
|
||||
}
|
||||
usage(&umap);
|
||||
os::set_exit_status(0);
|
||||
return
|
||||
} else {
|
||||
println!("{}: applet not found", util);
|
||||
os::set_exit_status(1);
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// no arguments provided
|
||||
|
|
Loading…
Reference in a new issue