@@ -10,7 +10,6 @@ use runtime::config::{Config, CONFIG, LogLevel};
1010
1111use crate :: commands:: { repl, run} ;
1212use crate :: commands:: eval;
13- use crate :: Commands :: { Eval , Repl , Run } ;
1413
1514mod commands;
1615pub mod evaluate;
@@ -19,11 +18,11 @@ pub mod evaluate;
1918#[ structopt( name = "spiderfire" , about = "JavaScript Runtime" ) ]
2019struct Cli {
2120 #[ structopt( subcommand) ]
22- commands : Option < Commands > ,
21+ command : Option < Command > ,
2322}
2423
2524#[ derive( StructOpt ) ]
26- pub enum Commands {
25+ pub enum Command {
2726 #[ structopt( about = "Evaluates a line of JavaScript" ) ]
2827 Eval {
2928 #[ structopt( required( true ) , about = "Line of JavaScript to be evaluated" ) ]
@@ -35,13 +34,13 @@ pub enum Commands {
3534
3635 #[ structopt( about = "Runs a JavaScript file" ) ]
3736 Run {
38- #[ structopt( about = "The JavaScript file to run. Default: 'main.js'" , required( false ) , default_value = "main.js" ) ]
37+ #[ structopt( about = "The JavaScript file to run, Default: 'main.js'" , required( false ) , default_value = "main.js" ) ]
3938 path : String ,
4039
41- #[ structopt( about = "Sets logging level, Default: ERROR" , short, long, required( false ) , default_value = "error " ) ]
40+ #[ structopt( about = "Sets logging level, Default: ERROR" , short, long, required( false ) , default_value = "ERROR " ) ]
4241 log_level : String ,
4342
44- #[ structopt( about = "Sets logging level to DEBUG. " , short, long) ]
43+ #[ structopt( about = "Sets logging level to DEBUG" , short, long) ]
4544 debug : bool ,
4645
4746 #[ structopt( about = "Disables ES Modules Features" , short, long) ]
@@ -52,23 +51,27 @@ pub enum Commands {
5251fn main ( ) {
5352 let args = Cli :: from_args ( ) ;
5453
55- match args. commands {
56- Some ( Eval { source } ) => {
54+ #[ cfg( windows) ]
55+ {
56+ colored:: control:: set_virtual_terminal ( true ) . unwrap ( ) ;
57+ }
58+
59+ match args. command {
60+ Some ( Command :: Eval { source } ) => {
5761 CONFIG
5862 . set ( Config :: default ( ) . log_level ( LogLevel :: Debug ) . script ( true ) )
5963 . expect ( "Config Initialisation Failed" ) ;
6064 eval:: eval_source ( & source) ;
6165 }
6266
63- Some ( Run {
67+ Some ( Command :: Run {
6468 path,
6569 log_level,
6670 debug,
6771 script,
6872 } ) => {
69-
7073 let log_lev = if debug {
71- LogLevel :: Debug
74+ LogLevel :: Debug
7275 } else {
7376 match log_level. to_uppercase ( ) . as_str ( ) {
7477 "NONE" => LogLevel :: None ,
@@ -86,7 +89,7 @@ fn main() {
8689 run:: run ( & path) ;
8790 }
8891
89- Some ( Repl ) | None => {
92+ Some ( Command :: Repl ) | None => {
9093 CONFIG
9194 . set ( Config :: default ( ) . log_level ( LogLevel :: Debug ) . script ( true ) )
9295 . expect ( "Config Initialisation Failed" ) ;
0 commit comments