summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2020-02-24 03:57:40 +0300
committerOxore <oxore@protonmail.com>2020-02-24 03:57:40 +0300
commita3be84cafaec3ef7ede9c142268cedf12d9f744d (patch)
tree0c24252a8dd44f81488321a1f56a60c1ea3b7e5c /src/main.rs
parent466badee5b66cdb88c99c701e3b7279894303a38 (diff)
Use clap for CLI argument parsing
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs37
1 files changed, 30 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs
index 87dd041..1ec5174 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,5 @@
-use std::env;
+extern crate clap;
+
use std::fs;
use std::io;
use std::io::prelude::*;
@@ -45,13 +46,35 @@ fn cli_controller(asyncpair: Arc<(Mutex<bool>, Condvar)>) {
}
fn main() {
- let args: Vec<_> = env::args().collect();
- if args.len() < 2 {
- println!("Please, specify ihex file");
- return;
- }
+ let cli_args_matches = clap::App::new("x51emu")
+ .version("0.1.0")
+ .author("oxore")
+ .about("MCS51 emulator")
+ .arg(
+ clap::Arg::with_name("file")
+ .short("f")
+ .long("file")
+ .value_name("FILE")
+ .help("Sets a file with program to load")
+ .takes_value(true)
+ .required(true),
+ )
+ .arg(
+ clap::Arg::with_name("interface")
+ .short("i")
+ .long("interface")
+ .value_name("INTERFACE")
+ .help("Sets a controlling and I/O interface")
+ .takes_value(true)
+ .possible_values(&["cli", "ws"]),
+ )
+ .get_matches();
+
+ let filename = cli_args_matches
+ .value_of("file")
+ .expect("No file name provided");
let data =
- fs::read_to_string(&args[1]).unwrap_or_else(|_| panic!("Unable to read file {}", &args[1]));
+ fs::read_to_string(filename).unwrap_or_else(|_| panic!("Unable to read file {}", filename));
let asyncpair = Arc::new((Mutex::new(false), Condvar::new()));
let asyncpair2 = asyncpair.clone();