summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRory Dudley2024-07-03 15:42:32 -0600
committerRory Dudley2024-07-03 15:42:32 -0600
commite022a7eff4b9af4df3b3a852b911d89a04fdb98b (patch)
treed4331106f43cea0923e0523d03499ad655fb12a6 /src
parentaf66f66f9d7b4a977ffd2420211704c050f23da8 (diff)
downloaddwarvish-e022a7eff4b9af4df3b3a852b911d89a04fdb98b.tar.gz
Option parsing and version
Add some basic logic for parsing commandline arguments. Also, use build.rs to embed the program version (and git commit) during the compile step. The program currently accepts the '--version' commandline argument to print the version, then quit.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index 821dde2..f87b69d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -82,6 +82,20 @@ fn repl(away: &mut Arc<Mutex<bool>>, env: &mut Environment) {
}
}
+fn options() {
+ let args: Vec<String> = env::args().collect();
+ for arg in args.iter() {
+ if arg.eq("--version") {
+ println!(
+ "dwvsh v{} ({})",
+ env!("CARGO_PKG_VERSION"),
+ env!("DWVSH_BUILD")
+ );
+ std::process::exit(0);
+ }
+ }
+}
+
/// Shell entry
///
/// Shell setup and entry
@@ -108,6 +122,9 @@ fn main() {
.unwrap();
};
+ // Parse flags and other arguments
+ options();
+
// Begin evaluating commands
repl(&mut away, &mut env);
}