1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-10-16 02:37:40 -05:00

feat: unoptionize command

This commit is contained in:
Natapat Samutpong 2022-01-28 07:09:31 +07:00
parent dc3d400d50
commit 8230151489
2 changed files with 13 additions and 16 deletions

View file

@ -6,7 +6,7 @@ use structopt::StructOpt;
#[structopt(name = "blspc")]
pub struct Opts {
#[structopt(subcommand)]
pub commands: Option<Args>,
pub commands: Args,
}
#[derive(StructOpt, Debug)]

View file

@ -17,20 +17,17 @@ use vm::{vm::VM, parser::parse_instr};
fn main() {
let start = Instant::now();
let args = Opts::from_args();
if let Some(commands) = args.commands {
match commands {
args::Args::Compile(args) => {
let src = read_to_string(&args.file).unwrap();
let debug = args.debug;
compile_src(src, args.output, args.file, debug, start);
},
args::Args::Run(args) => {
let src = read_to_string(&args.file).unwrap();
let debug = args.debug;
run_src(src, debug);
},
}
match args.commands {
args::Args::Compile(args) => {
let src = read_to_string(&args.file).unwrap();
let debug = args.debug;
compile_src(src, args.output, args.file, debug, start);
},
args::Args::Run(args) => {
let src = read_to_string(&args.file).unwrap();
let debug = args.debug;
run_src(src, debug);
},
}
}
@ -57,7 +54,7 @@ fn compile_src(src: String, path: Option<PathBuf>, file: PathBuf, debug: bool, s
write!(file, "{}\n", line).unwrap();
}
file.seek(std::io::SeekFrom::End(-1)).unwrap(); // Trim last newline
let elapsed = start.elapsed();
println!("Compiled in {}.{}s", elapsed.as_secs(), elapsed.subsec_millis());
},