From 96e88f02fa55a65203d497f2da71a76174cf66e3 Mon Sep 17 00:00:00 2001 From: Ivan Bushchik Date: Fri, 3 Feb 2023 15:47:26 +0300 Subject: [PATCH] main.rs: add formatting to shell mode and edit help message Signed-off-by: Ivan Bushchik --- src/main.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index ac4c1ee..88ec33a 100644 --- a/src/main.rs +++ b/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 } } }