changed arg parse to use pico-args

This commit is contained in:
Valerie Wolfe 2024-08-22 13:00:20 -04:00
parent d144bd9245
commit e5d358477f
2 changed files with 6 additions and 1 deletions

View file

@ -14,6 +14,7 @@ path = "src/main.rs"
[dependencies] [dependencies]
evalexpr = "11.0.0" evalexpr = "11.0.0"
pico-args = "0.5.0"
termion = "1.5.6" termion = "1.5.6"
[profile.release] [profile.release]

View file

@ -15,6 +15,7 @@ use evalexpr::{
HashMapContext, HashMapContext,
Value Value
}; };
use pico_args::Arguments;
use termion::{ use termion::{
color, color,
style style
@ -27,6 +28,8 @@ mod util;
pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub const VERSION: &str = env!("CARGO_PKG_VERSION");
fn main() { fn main() {
let args = Arguments::from_env();
// build eval context // build eval context
let mut context = context_map! { let mut context = context_map! {
// globals // globals
@ -56,9 +59,10 @@ fn main() {
}.unwrap(); }.unwrap();
// collect args and evaluate if present // collect args and evaluate if present
let expressions: Vec<String> = env::args().skip(1).collect(); let expressions = args.finish();
if expressions.len() > 0 { if expressions.len() > 0 {
for expression in expressions { for expression in expressions {
let expression: String = expression.to_string_lossy().into();
match expression.as_str() { match expression.as_str() {
"help" => help_text(), "help" => help_text(),
_ => do_eval(expression, &mut context) _ => do_eval(expression, &mut context)