mirror of
https://github.com/ivabus/feval
synced 2024-12-05 05:05:07 +03:00
0.2.0
This commit is contained in:
parent
d0a71244b2
commit
27a825b2a2
3 changed files with 33 additions and 14 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -10,7 +10,7 @@ checksum = "aacfb566035f8cd02f6ec9247c242f3f9904a0b288ea383abcf4e95df6436a34"
|
|||
|
||||
[[package]]
|
||||
name = "feval"
|
||||
version = "0.1.2"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"evalexpr",
|
||||
]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "feval"
|
||||
version = "0.1.2"
|
||||
version = "0.2.0"
|
||||
edition = "2021"
|
||||
description = "clt for fast evaluations"
|
||||
readme = "README.md"
|
||||
|
|
29
src/main.rs
29
src/main.rs
|
@ -1,25 +1,44 @@
|
|||
use evalexpr;
|
||||
use std::env::args;
|
||||
use std::{env::args, io::{stdin, stdout, Write}};
|
||||
mod tasks;
|
||||
use crate::tasks::tasks::all;
|
||||
|
||||
fn help() {
|
||||
println!(r#"feval: evaluate expressions
|
||||
usage: provide exactly one argument (with expression)
|
||||
usage: provide exactly one argument (with expression) or no arguments for shell mode.
|
||||
example: feval "math::sin(30 * math::pi / 180)""#);
|
||||
}
|
||||
|
||||
fn main_loop() {
|
||||
print!(">>> ");
|
||||
stdout().flush().unwrap();
|
||||
let mut input = String::new();
|
||||
while stdin().read_line(&mut input).unwrap() != 0 {
|
||||
println!("{}", evalexpr::eval(&input.trim()).unwrap());
|
||||
input.clear();
|
||||
print!(">>> ");
|
||||
stdout().flush().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = args().collect();
|
||||
match args.len() {
|
||||
2 => {
|
||||
let expr = all(args[1].clone());
|
||||
println!("{}", evalexpr::eval(&expr).unwrap())
|
||||
},
|
||||
1 => {main_loop()},
|
||||
_ => {
|
||||
if args.len() > 2 {
|
||||
println!("Too many args.");
|
||||
help();
|
||||
return
|
||||
} else if args.len() < 2 {
|
||||
} else if args.len() < 1 {
|
||||
println!("Too few args.");
|
||||
help();
|
||||
return
|
||||
}
|
||||
let expr = all(args[1].clone());
|
||||
println!("{}", evalexpr::eval(&expr).unwrap())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue