Start using the new getopts interface

This commit is contained in:
Ben S 2015-02-04 14:51:55 +00:00
parent 0f1843f5e7
commit 8f36dbbc6f
2 changed files with 22 additions and 23 deletions

4
Cargo.lock generated
View File

@ -39,7 +39,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"bitflags 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libgit2-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "libgit2-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"url 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -143,7 +143,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "url" name = "url"
version = "0.2.17" version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -35,33 +35,32 @@ impl Options {
/// Call getopts on the given slice of command-line strings. /// Call getopts on the given slice of command-line strings.
pub fn getopts(args: &[String]) -> Result<Options, Misfire> { pub fn getopts(args: &[String]) -> Result<Options, Misfire> {
let opts = &[ let mut opts = getopts::Options::new();
getopts::optflag("1", "oneline", "display one entry per line"), opts.optflag("1", "oneline", "display one entry per line");
getopts::optflag("a", "all", "show dot-files"), opts.optflag("a", "all", "show dot-files");
getopts::optflag("b", "binary", "use binary prefixes in file sizes"), opts.optflag("b", "binary", "use binary prefixes in file sizes");
getopts::optflag("B", "bytes", "list file sizes in bytes, without prefixes"), opts.optflag("B", "bytes", "list file sizes in bytes, without prefixes");
getopts::optflag("d", "list-dirs", "list directories as regular files"), opts.optflag("d", "list-dirs", "list directories as regular files");
getopts::optflag("g", "group", "show group as well as user"), opts.optflag("g", "group", "show group as well as user");
getopts::optflag("h", "header", "show a header row at the top"), opts.optflag("h", "header", "show a header row at the top");
getopts::optflag("H", "links", "show number of hard links"), opts.optflag("H", "links", "show number of hard links");
getopts::optflag("l", "long", "display extended details and attributes"), opts.optflag("l", "long", "display extended details and attributes");
getopts::optflag("i", "inode", "show each file's inode number"), opts.optflag("i", "inode", "show each file's inode number");
getopts::optflag("r", "reverse", "reverse order of files"), opts.optflag("r", "reverse", "reverse order of files");
getopts::optflag("R", "recurse", "recurse into directories"), opts.optflag("R", "recurse", "recurse into directories");
getopts::optopt ("s", "sort", "field to sort by", "WORD"), opts.optopt ("s", "sort", "field to sort by", "WORD");
getopts::optflag("S", "blocks", "show number of file system blocks"), opts.optflag("S", "blocks", "show number of file system blocks");
getopts::optflag("T", "tree", "recurse into subdirectories in a tree view"), opts.optflag("T", "tree", "recurse into subdirectories in a tree view");
getopts::optflag("x", "across", "sort multi-column view entries across"), opts.optflag("x", "across", "sort multi-column view entries across");
getopts::optflag("?", "help", "show list of command-line options"), opts.optflag("?", "help", "show list of command-line options");
];
let matches = match getopts::getopts(args, opts) { let matches = match opts.parse(args) {
Ok(m) => m, Ok(m) => m,
Err(e) => return Err(Misfire::InvalidOptions(e)), Err(e) => return Err(Misfire::InvalidOptions(e)),
}; };
if matches.opt_present("help") { if matches.opt_present("help") {
return Err(Misfire::Help(getopts::usage("Usage:\n exa [options] [files...]", opts))); return Err(Misfire::Help(opts.usage("Usage:\n exa [options] [files...]")));
} }
let sort_field = match matches.opt_str("sort") { let sort_field = match matches.opt_str("sort") {