diff --git a/compiler/cl-repl/Cargo.toml b/compiler/cl-repl/Cargo.toml index 7c92001..3807e5d 100644 --- a/compiler/cl-repl/Cargo.toml +++ b/compiler/cl-repl/Cargo.toml @@ -16,4 +16,4 @@ cl-token = { path = "../cl-token" } cl-parser = { path = "../cl-parser" } cl-interpret = { path = "../cl-interpret" } repline = { path = "../../repline" } -argh = "0.1.12" +argwerk = "0.20.4" diff --git a/compiler/cl-repl/src/args.rs b/compiler/cl-repl/src/args.rs index 40265ba..1ef4921 100644 --- a/compiler/cl-repl/src/args.rs +++ b/compiler/cl-repl/src/args.rs @@ -1,26 +1,40 @@ //! Handles argument parsing (currently using the [argh] crate) -use argh::FromArgs; use std::{io::IsTerminal, path::PathBuf, str::FromStr}; -/// The Conlang prototype debug interface -#[derive(Clone, Debug, FromArgs, PartialEq, Eq, PartialOrd, Ord)] -pub struct Args { - /// the main source file - #[argh(positional)] - pub file: Option, +argwerk::define! { + /// + ///The Conlang prototype debug interface + #[usage = "conlang [] [-I ] [-m ] [-r ]"] + #[derive(Clone, PartialEq, Eq, PartialOrd, Ord)] + pub struct Args { + pub file: Option, + pub include: Vec, + pub mode: Mode, + pub repl: bool = is_terminal(), + } - /// files to include - #[argh(option, short = 'I')] - pub include: Vec, - - /// the CLI operating mode (`f`mt | `l`ex | `r`un) - #[argh(option, short = 'm', default = "Default::default()")] - pub mode: Mode, - - /// whether to start the repl (`true` or `false`) - #[argh(option, short = 'r', default = "is_terminal()")] - pub repl: bool, + ///files to include + ["-I" | "--include", path] => { + include.push(path.into()); + } + ///the CLI operating mode (`f`mt | `l`ex | `r`un) + ["-m" | "--mode", flr] => { + mode = flr.parse()?; + } + ///whether to start the repl (`true` or `false`) + ["-r" | "--repl", bool] => { + repl = bool.parse()?; + } + ///display usage information + ["-h" | "--help"] => { + println!("{}", Args::help()); + if true { std::process::exit(0); } + } + ///the main source file + [#[option] path] if file.is_none() => { + file = path.map(Into::into); + } } /// gets whether stdin AND stdout are a terminal, for pipelining diff --git a/compiler/cl-repl/src/bin/conlang.rs b/compiler/cl-repl/src/bin/conlang.rs index 06ea88a..4ed9f3c 100644 --- a/compiler/cl-repl/src/bin/conlang.rs +++ b/compiler/cl-repl/src/bin/conlang.rs @@ -1,5 +1,5 @@ -use cl_repl::cli::run; +use cl_repl::{args, cli::run}; fn main() -> Result<(), Box> { - run(argh::from_env()) + run(args::Args::args()?) }