Skip to content

Commit

Permalink
Merge pull request #2 from alfiankan/dev
Browse files Browse the repository at this point in the history
fix: env read
  • Loading branch information
alfiankan authored Mar 11, 2022
2 parents b7b156c + 4de4df0 commit 79e5fcb
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions src/mjl/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::borrow::Borrow;
use std::io;
use std::io::Write;
use std::process::exit;
use std::env;


fn chained_view(prev_hash: &str, data: &str, hashed_data: &str) {
// trim every 50 chars
Expand Down Expand Up @@ -229,26 +231,36 @@ fn eval_command(mql: &str, engine: &Engine) {
}

pub fn start_cli() {
let engine = Engine::new(env!("FILE_NAME"));

let mut mql = String::new();
//read env
match env::var("MJL_DATA_STORE") {
Ok(file_name) => {

let input = io::stdin();
let mut lines = 1;
loop {
mql.clear();
println!();
print!("[{}] [mql] > ", lines.yellow());
io::stdout().flush().expect("CLI Fatal Error");
let engine = Engine::new(file_name.to_string().as_str());
let mut mql = String::new();

match input.read_line(&mut mql) {
Ok(_) => {}
Err(err) => {
println!("Error => {}", err);
continue;
let input = io::stdin();
let mut lines = 1;
loop {
mql.clear();
println!();
print!("[{}] [mql] > ", lines.yellow());
io::stdout().flush().expect("CLI Fatal Error");

match input.read_line(&mut mql) {
Ok(_) => {}
Err(err) => {
println!("Error => {}", err);
continue;
}
}
eval_command(mql.trim(), engine.borrow());
lines = lines + 1;
}
}
eval_command(mql.trim(), engine.borrow());
lines = lines + 1;
Err(_) => {
println!("env MJL_DATA_STORE ot set");
}
}

}

0 comments on commit 79e5fcb

Please sign in to comment.