1
0
Эх сурвалжийг харах

Start using the new getopts interface

Ben S 11 жил өмнө
parent
commit
8f36dbbc6f
2 өөрчлөгдсөн 23 нэмэгдсэн , 24 устгасан
  1. 2 2
      Cargo.lock
  2. 21 22
      src/options.rs

+ 2 - 2
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)",

+ 21 - 22
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<Options, Misfire> {
-        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 matches = match getopts::getopts(args, opts) {
+        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 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") {