From 82301514895545bf77f69acb45a6e89aae70a922 Mon Sep 17 00:00:00 2001 From: Natapat Samutpong Date: Fri, 28 Jan 2022 07:09:31 +0700 Subject: [PATCH] feat: unoptionize command --- blspc/src/args.rs | 2 +- blspc/src/main.rs | 27 ++++++++++++--------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/blspc/src/args.rs b/blspc/src/args.rs index 95eee7f..69b67a7 100644 --- a/blspc/src/args.rs +++ b/blspc/src/args.rs @@ -6,7 +6,7 @@ use structopt::StructOpt; #[structopt(name = "blspc")] pub struct Opts { #[structopt(subcommand)] - pub commands: Option, + pub commands: Args, } #[derive(StructOpt, Debug)] diff --git a/blspc/src/main.rs b/blspc/src/main.rs index 6c6977f..70299f0 100644 --- a/blspc/src/main.rs +++ b/blspc/src/main.rs @@ -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, 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()); },