Update to 0.4.1

- Multiple argument handling.

Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
Ivan Bushchik 2023-05-31 10:50:08 +03:00
parent 053e938d32
commit 740d0b6dd4
No known key found for this signature in database
GPG key ID: 9F6DDABE11A2674D
3 changed files with 23 additions and 23 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/target
Cargo.lock
.idea

View file

@ -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"

View file

@ -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<String> = 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();
}
}