mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-22 20:15:11 +00:00
Add --help flag
This commit is contained in:
parent
0b1e94a3c8
commit
e1d3512a69
@ -31,8 +31,8 @@ fn main() {
|
|||||||
let args: Vec<String> = os::args();
|
let args: Vec<String> = os::args();
|
||||||
|
|
||||||
match Options::getopts(args) {
|
match Options::getopts(args) {
|
||||||
Err(err) => println!("Invalid options:\n{}", err),
|
Err(error_code) => os::set_exit_status(error_code),
|
||||||
Ok(opts) => exa(&opts),
|
Ok(options) => exa(&options),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,8 +42,8 @@ pub struct Options {
|
|||||||
|
|
||||||
|
|
||||||
impl Options {
|
impl Options {
|
||||||
pub fn getopts(args: Vec<String>) -> Result<Options, getopts::Fail_> {
|
pub fn getopts(args: Vec<String>) -> Result<Options, int> {
|
||||||
let opts = &[
|
let opts = [
|
||||||
getopts::optflag("1", "oneline", "display one entry per line"),
|
getopts::optflag("1", "oneline", "display one entry per line"),
|
||||||
getopts::optflag("a", "all", "show dot-files"),
|
getopts::optflag("a", "all", "show dot-files"),
|
||||||
getopts::optflag("b", "binary", "use binary prefixes in file sizes"),
|
getopts::optflag("b", "binary", "use binary prefixes in file sizes"),
|
||||||
@ -57,21 +57,32 @@ impl Options {
|
|||||||
getopts::optopt ("s", "sort", "field to sort by", "WORD"),
|
getopts::optopt ("s", "sort", "field to sort by", "WORD"),
|
||||||
getopts::optflag("S", "blocks", "show number of file system blocks"),
|
getopts::optflag("S", "blocks", "show number of file system blocks"),
|
||||||
getopts::optflag("x", "across", "sort multi-column view entries across"),
|
getopts::optflag("x", "across", "sort multi-column view entries across"),
|
||||||
|
getopts::optflag("?", "help", "show list of command-line options"),
|
||||||
];
|
];
|
||||||
|
|
||||||
match getopts::getopts(args.tail(), opts) {
|
let matches = match getopts::getopts(args.tail(), &opts) {
|
||||||
Err(f) => Err(f),
|
Ok(m) => m,
|
||||||
Ok(ref matches) => Ok(Options {
|
Err(e) => {
|
||||||
|
println!("Invalid options: {}", e);
|
||||||
|
return Err(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if matches.opt_present("help") {
|
||||||
|
println!("exa - ls with more features\n\n{}", getopts::usage("Usage:\n exa [options] [files...]", &opts))
|
||||||
|
return Err(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Options {
|
||||||
header: matches.opt_present("header"),
|
header: matches.opt_present("header"),
|
||||||
list_dirs: matches.opt_present("list-dirs"),
|
list_dirs: matches.opt_present("list-dirs"),
|
||||||
path_strs: if matches.free.is_empty() { vec![ ".".to_string() ] } else { matches.free.clone() },
|
path_strs: if matches.free.is_empty() { vec![ ".".to_string() ] } else { matches.free.clone() },
|
||||||
reverse: matches.opt_present("reverse"),
|
reverse: matches.opt_present("reverse"),
|
||||||
show_invisibles: matches.opt_present("all"),
|
show_invisibles: matches.opt_present("all"),
|
||||||
sort_field: matches.opt_str("sort").map(|word| SortField::from_word(word)).unwrap_or(SortField::Name),
|
sort_field: matches.opt_str("sort").map(|word| SortField::from_word(word)).unwrap_or(SortField::Name),
|
||||||
view: Options::view(matches),
|
view: Options::view(&matches),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn view(matches: &getopts::Matches) -> View {
|
fn view(matches: &getopts::Matches) -> View {
|
||||||
if matches.opt_present("long") {
|
if matches.opt_present("long") {
|
||||||
|
Loading…
Reference in New Issue
Block a user