diff options
author | Ben S <ogham@bsago.me> | 2015-02-04 14:51:55 +0000 |
---|---|---|
committer | Ben S <ogham@bsago.me> | 2015-02-04 14:51:55 +0000 |
commit | 8f36dbbc6f44077fed0bc78ff7fcb04ade3cc061 (patch) | |
tree | f81557e044207a8ff1a45541e2aab792ec16af05 /src/options.rs | |
parent | 0f1843f5e799c209af430aa77305b324d7604bb2 (diff) |
Start using the new getopts interface
Diffstat (limited to 'src/options.rs')
-rw-r--r-- | src/options.rs | 43 |
1 files changed, 21 insertions, 22 deletions
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<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") { |