Skip to content

Commit 85aa30d

Browse files
committed
quietly
1 parent f8179f6 commit 85aa30d

File tree

3 files changed

+51
-15
lines changed

3 files changed

+51
-15
lines changed

Diff for: src/main.rs

+31-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use runner::*;
1010
use std::env;
1111
pub use json;
1212

13+
pub static mut IS_QUIET: bool = false;
14+
1315
fn main()-> std::io::Result<()> {
1416
let args: Vec<String> = env::args().collect();
1517
let mut run_cmds = None;
@@ -47,7 +49,7 @@ fn main()-> std::io::Result<()> {
4749
- Compiled to any language
4850
- enpp-every [filename without ext]
4951
- enpp-every [filename without ext] [language json]
50-
release Zhou
52+
release Chin
5153
");
5254
}
5355
else if args.len() == 2 {
@@ -58,13 +60,35 @@ release Zhou
5860
let lang = json::parse(&std::fs::read_to_string(&args[2]).expect("Cannot found the json")).expect("Cannot parse language json");
5961
if args[2] == "run" {
6062
path = &args[1];
63+
if args.len() >= 4 {
64+
if args[3] == "quietly" {
65+
unsafe { IS_QUIET = true; }
66+
}
67+
}
68+
filesys::convert(&args[1], lang["ext"].as_str().unwrap_or("txt"), &lang)?;
6169
run_cmds = Some(lang);
6270
}
63-
else {
71+
else if args[2] == "quietly" {
72+
unsafe { IS_QUIET = true; }
6473
filesys::convert(&args[1], lang["ext"].as_str().unwrap_or("txt"), &lang)?;
65-
if args.len() == 4 {
74+
}
75+
else {
76+
if args.len() >= 4 {
6677
if args[3] == "run" {
6778
path = &args[1];
79+
if args.len() >= 5 {
80+
if args[4] == "quietly" {
81+
unsafe { IS_QUIET = true; }
82+
}
83+
}
84+
}
85+
else if args[3] == "quietly" {
86+
unsafe { IS_QUIET = true; }
87+
}
88+
}
89+
filesys::convert(&args[1], lang["ext"].as_str().unwrap_or("txt"), &lang)?;
90+
if args.len() >= 4 {
91+
if args[3] == "run" {
6892
run_cmds = Some(lang);
6993
}
7094
}
@@ -75,8 +99,10 @@ release Zhou
7599
use std::process::Stdio;
76100
for c in cmds["run"].members() {
77101
let cmd = transpile::blocks::render(c.as_str().unwrap(), &json!({"file": path})).unwrap();
78-
colour::green!("=>Running ");
79-
println!("{}", cmd);
102+
if !unsafe { IS_QUIET } {
103+
colour::green!("=>Running ");
104+
println!("{}", cmd);
105+
}
80106
if cfg!(windows) {
81107
std::process::Command::new("cmd")
82108
.args(&["/c", &cmd])

Diff for: src/runner.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
pub use super::transpile;
2+
pub use super::IS_QUIET;
3+
4+
pub fn is_quiet()->bool {
5+
unsafe { IS_QUIET }
6+
}
27

38
pub mod filesys;

Diff for: src/runner/filesys.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rand::distributions::Alphanumeric;
22
use super::transpile::*;
3+
use super::is_quiet;
34
use blocks::render;
45
use std::io::Write;
56
use std::fs::File;
@@ -19,15 +20,17 @@ pub fn convert(path :&String, ext :&str, lang :&json::JsonValue)->std::io::Resul
1920
let mut source = String::new();
2021
source_file.read_to_string(&mut source)?;
2122
let converted :String = transpile(&tree::CodeTree::treeify(&source), 0, &lang);
22-
unsafe {
23-
if IS_FIRST {
24-
colour::green!(" Transpiling ");
25-
}
26-
else {
27-
colour::green!("=>Transpiling ");
28-
}
23+
if !is_quiet() {
24+
unsafe {
25+
if IS_FIRST {
26+
colour::green!(" Transpiling ");
27+
}
28+
else {
29+
colour::green!("=>Transpiling ");
30+
}
31+
}
32+
println!("{0}.epp => {0}.{1}", path, ext);
2933
}
30-
println!("{0}.epp => {0}.{1}", path, ext);
3134
target.write_all(render(&lang["header_guards"].as_str().unwrap(), &json!({
3235
"token": rand::thread_rng().sample_iter(&Alphanumeric).take(20).collect::<String>(),
3336
"contents": converted,
@@ -37,8 +40,10 @@ pub fn convert(path :&String, ext :&str, lang :&json::JsonValue)->std::io::Resul
3740

3841
for c in lang["then"].members() {
3942
let cmd = render(c.as_str().unwrap(), &json!({"file": path})).unwrap();
40-
colour::green!("=>Executing ");
41-
println!("{}", cmd);
43+
if !is_quiet() {
44+
colour::green!("=>Executing ");
45+
println!("{}", cmd);
46+
}
4247
if cfg!(windows) {
4348
std::process::Command::new("cmd")
4449
.args(&["/c", &cmd]).output()

0 commit comments

Comments
 (0)