diff --git a/src/cli.rs b/src/cli.rs index c76ab55..8356ce3 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,7 +1,33 @@ +macro_rules! options { + ($($name:ident $sflag:literal $lflag:literal $hasarg:literal),* $(,)?) => { + enum Options { + $($name,)* + } + + const SHORT_FLAGS: &[&str] = &[ + $($sflag,)* + ]; + + const LONG_FLAGS: &[&str] = &[ + $($lflag,)* + ]; + + const HAS_ARG: &[bool] = &[ + $($hasarg,)* + ]; + }; +} + +options! { + Width "w" "width" true, + Height "h" "height" true, +} + #[derive(Default)] pub struct Cli { width: Option, height: Option, + input_file: String, } impl Cli { @@ -10,6 +36,22 @@ impl Cli { } pub fn run(&mut self) -> Option<()> { + let mut args = std::env::args(); + /* Skip program name. */ + args.next(); + loop { + if let Some(arg) = args.next() { + if arg.starts_with("--") { + let flag = &arg[2..]; + } else if arg.starts_with("-") { + let flag = &arg[1..2]; + } else { + self.input_file = arg; + } + } else { + break; + } + } Some(()) } }