main: add -v/--version flag

Added a new dependency to take care of pulling in the version from git
at build time.

Args handling is minimalistic, but there wasn't any before, so I figured
this might do for now. (Eventually, some proper `--help` and usage
output might come in handy?)

Signed-off-by: Stephan Renatus <srenatus@chef.io>
This commit is contained in:
Stephan Renatus
2020-03-27 19:59:48 +01:00
parent 7de39611f3
commit 896f2aeb74
3 changed files with 73 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
extern crate crossterm;
#[macro_use]
extern crate downcast;
extern crate git_version;
extern crate indexmap;
#[macro_use]
extern crate lazy_static;
@@ -11,6 +12,7 @@ extern crate prolog_parser;
#[macro_use]
extern crate ref_thread_local;
use git_version::git_version;
use nix::sys::signal;
mod prolog;
@@ -19,6 +21,7 @@ use crate::prolog::machine::*;
use crate::prolog::machine::streams::*;
use crate::prolog::read::*;
use std::env;
use std::sync::atomic::Ordering;
extern fn handle_sigint(signal: libc::c_int) {
@@ -32,6 +35,11 @@ fn main() {
let handler = signal::SigHandler::Handler(handle_sigint);
unsafe { signal::signal(signal::Signal::SIGINT, handler) }.unwrap();
if env::args().any(|a| a == "-v" || a == "--version") {
println!("{:}", git_version!());
return;
}
let mut wam = Machine::new(readline::input_stream(), Stream::stdout());
wam.run_top_level();
}