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]
evalexpr = "11.0.0"
pico-args = "0.5.0"
termion = "1.5.6"
[profile.release]

View file

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