This commit is contained in:
jc 2017-05-11 18:59:32 +02:00
parent 1c586f9b9a
commit 79d96df948

View File

@ -8,18 +8,26 @@ use std::env;
use std::io::{self, Write};
use std::process;
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
fn main() {
main1().unwrap();
}
fn main1() -> io::Result<()> {
let mut stderr = std::io::stderr();
let mut stdout = std::io::stdout();
let args: Args =
Docopt::new(USAGE)
.and_then(|d| d.argv(env::args()).decode())
.unwrap_or_else(|e| e.exit());
if args.flag_version {
try!(writeln!(stdout, "{}", VERSION));
process::exit(0);
}
let mut config = Configuration::new();
match args.flag_level.unwrap_or(LevelFlag::Info) {
@ -67,8 +75,10 @@ fn main1() -> io::Result<()> {
const USAGE: &'static str = "
Usage: lalrpop [options] <inputs>...
lalrpop --help
lalrpop (-V | --version)
Options:
-V, --version Print version.
-l, --level LEVEL Set the debug level. (Default: info)
Valid values: quiet, info, verbose, debug.
-f, --force Force execution, even if the .lalrpop file is older than the .rs file.
@ -84,7 +94,8 @@ struct Args {
flag_force: bool,
flag_color: bool,
flag_comments: bool,
flag_report: bool
flag_report: bool,
flag_version: bool,
}
#[derive(Debug, RustcDecodable)]
@ -106,6 +117,14 @@ mod test {
.unwrap();
}
#[test]
fn test_usage_version() {
let argv = || vec!["lalrpop", "--version"];
let _: Args = Docopt::new(USAGE)
.and_then(|d| d.argv(argv().into_iter()).decode())
.unwrap();
}
#[test]
fn test_usage_single_input() {
let argv = || vec!["lalrpop", "file.lalrpop"];