From fe58addcc2a854b6a6f76d9ba798bb396c5eb76d Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 7 Jun 2023 15:21:48 -0700 Subject: [PATCH] Added command-line argument parsing --- src/entry/unix/unix.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/entry/unix/unix.rs b/src/entry/unix/unix.rs index b8987ce..c66ad7e 100644 --- a/src/entry/unix/unix.rs +++ b/src/entry/unix/unix.rs @@ -1,6 +1,7 @@ use std::io::Write; use std::io::stdout; use std::io::stdin; +use std::env; use termion::{ event::Key, @@ -120,6 +121,18 @@ fn do_expression( pub fn main() -> Result<(), std::io::Error> { let mut stdout = stdout().into_raw_mode().unwrap(); + let args: Vec = env::args().collect(); + + // Handle command-line arguments + if args.iter().any(|s| s == "--help") { + command::do_command(&mut stdout, &String::from("help"))?; + return Ok(()); + } else if args.iter().any(|s| s == "--version") { + write!(stdout, "Daisy v{}\r\n", env!("CARGO_PKG_VERSION"))?; + return Ok(()); + } + + //let size = termion::terminal_size().unwrap(); //write!(stdout, "{:?}", size).unwrap();