From 8f36dbbc6f44077fed0bc78ff7fcb04ade3cc061 Mon Sep 17 00:00:00 2001 From: Ben S Date: Wed, 4 Feb 2015 14:51:55 +0000 Subject: [PATCH] Start using the new getopts interface --- Cargo.lock | 4 ++-- src/options.rs | 41 ++++++++++++++++++++--------------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 62ef9e4..9dcb7c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -39,7 +39,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "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)", - "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]] @@ -143,7 +143,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "url" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/options.rs b/src/options.rs index 282e308..43dcb96 100644 --- a/src/options.rs +++ b/src/options.rs @@ -35,33 +35,32 @@ impl Options { /// Call getopts on the given slice of command-line strings. pub fn getopts(args: &[String]) -> Result { - let opts = &[ - getopts::optflag("1", "oneline", "display one entry per line"), - getopts::optflag("a", "all", "show dot-files"), - getopts::optflag("b", "binary", "use binary prefixes in file sizes"), - getopts::optflag("B", "bytes", "list file sizes in bytes, without prefixes"), - getopts::optflag("d", "list-dirs", "list directories as regular files"), - getopts::optflag("g", "group", "show group as well as user"), - getopts::optflag("h", "header", "show a header row at the top"), - getopts::optflag("H", "links", "show number of hard links"), - getopts::optflag("l", "long", "display extended details and attributes"), - getopts::optflag("i", "inode", "show each file's inode number"), - getopts::optflag("r", "reverse", "reverse order of files"), - getopts::optflag("R", "recurse", "recurse into directories"), - getopts::optopt ("s", "sort", "field to sort by", "WORD"), - getopts::optflag("S", "blocks", "show number of file system blocks"), - getopts::optflag("T", "tree", "recurse into subdirectories in a tree view"), - getopts::optflag("x", "across", "sort multi-column view entries across"), - getopts::optflag("?", "help", "show list of command-line options"), - ]; + let mut opts = getopts::Options::new(); + opts.optflag("1", "oneline", "display one entry per line"); + opts.optflag("a", "all", "show dot-files"); + opts.optflag("b", "binary", "use binary prefixes in file sizes"); + opts.optflag("B", "bytes", "list file sizes in bytes, without prefixes"); + opts.optflag("d", "list-dirs", "list directories as regular files"); + opts.optflag("g", "group", "show group as well as user"); + opts.optflag("h", "header", "show a header row at the top"); + opts.optflag("H", "links", "show number of hard links"); + opts.optflag("l", "long", "display extended details and attributes"); + opts.optflag("i", "inode", "show each file's inode number"); + opts.optflag("r", "reverse", "reverse order of files"); + opts.optflag("R", "recurse", "recurse into directories"); + opts.optopt ("s", "sort", "field to sort by", "WORD"); + opts.optflag("S", "blocks", "show number of file system blocks"); + opts.optflag("T", "tree", "recurse into subdirectories in a tree view"); + opts.optflag("x", "across", "sort multi-column view entries across"); + 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, Err(e) => return Err(Misfire::InvalidOptions(e)), }; 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") {