From 740d0b6dd438d68d5a305004181100ccc57d78de Mon Sep 17 00:00:00 2001 From: Ivan Bushchik Date: Wed, 31 May 2023 10:50:08 +0300 Subject: [PATCH] Update to 0.4.1 - Multiple argument handling. Signed-off-by: Ivan Bushchik --- .gitignore | 3 ++- Cargo.toml | 2 +- src/main.rs | 41 ++++++++++++++++++++--------------------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 869df07..408b8a5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -Cargo.lock \ No newline at end of file +Cargo.lock +.idea \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index be1693f..65064ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "feval" -version = "0.4.0" +version = "0.4.1" edition = "2021" description = "clt for fast evaluations" readme = "README.md" diff --git a/src/main.rs b/src/main.rs index c1b7fac..8da748a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ mod tasks; fn help() { println!( r#"feval: help -usage: provide exactly one argument (with expression) or no arguments for shell mode. +usage: provide expression as arguments or don't provide arguments for shell mode. example: feval "math::sin(30 * math::pi / 180)""# ); } @@ -37,27 +37,26 @@ fn main_loop() { fn main() { let args: Vec = args().collect(); - match args.len() { - 2 => { - let expr = all(args[1].clone()); - let result = evalexpr::eval(&expr.trim()); - match result { - Ok(succ_res) => println!("{}", succ_res), - Err(err) => { - println!("Error: {}", err); - std::process::exit(127); - } - } - } - 1 => main_loop(), - _ => { - if args.len() > 2 { - println!("Too many args."); - help(); - } else if args.len() < 1 { - println!("Too few args."); - help(); + if args.contains(&"--help".to_string()) { + help(); + std::process::exit(0); + } + if args.len() >= 2 { + let mut expr = String::new(); + for i in args[1..].to_vec() { + expr += &i; + expr += " "; + } + let expr = all(expr); + let result = evalexpr::eval(&expr.trim()); + match result { + Ok(succ_res) => println!("{}", succ_res), + Err(err) => { + println!("Error: {}", err); + std::process::exit(127); } } + } else if args.len() == 1 { + main_loop(); } }