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:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user