mirror of
https://github.com/ivabus/feval
synced 2024-12-04 20:55:06 +03:00
Update to 0.4.1
- Multiple argument handling. Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
parent
053e938d32
commit
740d0b6dd4
3 changed files with 23 additions and 23 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
/target
|
||||
Cargo.lock
|
||||
Cargo.lock
|
||||
.idea
|
|
@ -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"
|
||||
|
|
41
src/main.rs
41
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<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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue