Start parsing command line arguments

This commit is contained in:
Josh Holtrop 2026-08-29 12:48:47 -04:00
parent d9dc0b7176
commit 64c5abd9b9

View File

@ -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)] #[derive(Default)]
pub struct Cli { pub struct Cli {
width: Option<usize>, width: Option<usize>,
height: Option<usize>, height: Option<usize>,
input_file: String,
} }
impl Cli { impl Cli {
@ -10,6 +36,22 @@ impl Cli {
} }
pub fn run(&mut self) -> Option<()> { 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(()) Some(())
} }
} }