mirror of
https://github.com/ivabus/feval
synced 2024-12-04 20:55:06 +03:00
main.rs: add formatting to shell mode and edit help message
Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
parent
aa996ec3ef
commit
96e88f02fa
1 changed files with 11 additions and 7 deletions
18
src/main.rs
18
src/main.rs
|
@ -1,10 +1,13 @@
|
|||
use evalexpr;
|
||||
use std::{env::args, io::{stdin, stdout, Write}};
|
||||
mod tasks;
|
||||
|
||||
use evalexpr;
|
||||
|
||||
use crate::tasks::tasks::all;
|
||||
|
||||
mod tasks;
|
||||
|
||||
fn help() {
|
||||
println!(r#"feval: evaluate expressions
|
||||
println!(r#"feval: help
|
||||
usage: provide exactly one argument (with expression) or no arguments for shell mode.
|
||||
example: feval "math::sin(30 * math::pi / 180)""#);
|
||||
}
|
||||
|
@ -14,7 +17,7 @@ fn main_loop() {
|
|||
stdout().flush().unwrap();
|
||||
let mut input = String::new();
|
||||
while stdin().read_line(&mut input).unwrap() != 0 {
|
||||
let result = evalexpr::eval(&input.trim());
|
||||
let result = evalexpr::eval(&all(input.trim().to_string()));
|
||||
match result {
|
||||
Ok(succ_res) => println!("{}", succ_res),
|
||||
Err(err) => println!("Error: {}", err)
|
||||
|
@ -33,7 +36,10 @@ fn main() {
|
|||
let result = evalexpr::eval(&expr.trim());
|
||||
match result {
|
||||
Ok(succ_res) => println!("{}", succ_res),
|
||||
Err(err) => println!("Error: {}", err)
|
||||
Err(err) => {
|
||||
println!("Error: {}", err);
|
||||
std::process::exit(127);
|
||||
}
|
||||
}
|
||||
},
|
||||
1 => {main_loop()},
|
||||
|
@ -41,11 +47,9 @@ fn main() {
|
|||
if args.len() > 2 {
|
||||
println!("Too many args.");
|
||||
help();
|
||||
return
|
||||
} else if args.len() < 1 {
|
||||
println!("Too few args.");
|
||||
help();
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue