mirror of
https://github.com/uutils/coreutils
synced 2024-11-17 10:18:11 +00:00
parent
5996bc340c
commit
54eebebff8
2 changed files with 43 additions and 45 deletions
|
@ -15,7 +15,7 @@ edition = "2018"
|
||||||
path = "src/paste.rs"
|
path = "src/paste.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
getopts = "0.2.18"
|
clap = "2.33.3"
|
||||||
uucore = { version=">=0.0.7", package="uucore", path="../../uucore" }
|
uucore = { version=">=0.0.7", package="uucore", path="../../uucore" }
|
||||||
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
|
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }
|
||||||
|
|
||||||
|
|
|
@ -10,59 +10,57 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate uucore;
|
extern crate uucore;
|
||||||
|
|
||||||
|
use clap::{App, Arg};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{stdin, BufRead, BufReader, Read};
|
use std::io::{stdin, BufRead, BufReader, Read};
|
||||||
use std::iter::repeat;
|
use std::iter::repeat;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
static NAME: &str = "paste";
|
|
||||||
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
static ABOUT: &str = "Write lines consisting of the sequentially corresponding lines from each
|
||||||
|
FILE, separated by TABs, to standard output.";
|
||||||
|
|
||||||
|
mod options {
|
||||||
|
pub const DELIMITER: &str = "delimiters";
|
||||||
|
pub const SERIAL: &str = "serial";
|
||||||
|
pub const FILE: &str = "file";
|
||||||
|
}
|
||||||
|
|
||||||
pub fn uumain(args: impl uucore::Args) -> i32 {
|
pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
let args = args.collect_str();
|
let matches = App::new(executable!())
|
||||||
|
.version(VERSION)
|
||||||
|
.about(ABOUT)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name(options::SERIAL)
|
||||||
|
.long(options::SERIAL)
|
||||||
|
.short("s")
|
||||||
|
.help("paste one file at a time instead of in parallel"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name(options::DELIMITER)
|
||||||
|
.long(options::DELIMITER)
|
||||||
|
.short("d")
|
||||||
|
.help("reuse characters from LIST instead of TABs")
|
||||||
|
.value_name("LIST")
|
||||||
|
.default_value("\t")
|
||||||
|
.hide_default_value(true),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name(options::FILE)
|
||||||
|
.value_name("FILE")
|
||||||
|
.multiple(true)
|
||||||
|
.required(true),
|
||||||
|
)
|
||||||
|
.get_matches_from(args);
|
||||||
|
|
||||||
let mut opts = getopts::Options::new();
|
let serial = matches.is_present(options::SERIAL);
|
||||||
|
let delimiters = matches.value_of(options::DELIMITER).unwrap().to_owned();
|
||||||
opts.optflag(
|
let files = matches
|
||||||
"s",
|
.values_of(options::FILE)
|
||||||
"serial",
|
.unwrap()
|
||||||
"paste one file at a time instead of in parallel",
|
.map(|s| s.to_owned())
|
||||||
);
|
.collect();
|
||||||
opts.optopt(
|
paste(files, serial, delimiters);
|
||||||
"d",
|
|
||||||
"delimiters",
|
|
||||||
"reuse characters from LIST instead of TABs",
|
|
||||||
"LIST",
|
|
||||||
);
|
|
||||||
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(e) => crash!(1, "{}", e),
|
|
||||||
};
|
|
||||||
|
|
||||||
if matches.opt_present("help") {
|
|
||||||
let msg = format!(
|
|
||||||
"{0} {1}
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
{0} [OPTION]... [FILE]...
|
|
||||||
|
|
||||||
Write lines consisting of the sequentially corresponding lines from each
|
|
||||||
FILE, separated by TABs, to standard output.",
|
|
||||||
NAME, VERSION
|
|
||||||
);
|
|
||||||
print!("{}", opts.usage(&msg));
|
|
||||||
} else if matches.opt_present("version") {
|
|
||||||
println!("{} {}", NAME, VERSION);
|
|
||||||
} else {
|
|
||||||
let serial = matches.opt_present("serial");
|
|
||||||
let delimiters = matches
|
|
||||||
.opt_str("delimiters")
|
|
||||||
.unwrap_or_else(|| "\t".to_owned());
|
|
||||||
paste(matches.free, serial, delimiters);
|
|
||||||
}
|
|
||||||
|
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue