cl-repl: Switch from argh to argwerk

This commit is contained in:
John 2024-04-22 02:03:04 -05:00
parent a3bb1ef447
commit 2ed8481489
3 changed files with 35 additions and 21 deletions

View File

@ -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"

View File

@ -1,26 +1,40 @@
//! Handles argument parsing (currently using the [argh] crate)
use argh::FromArgs;
use std::{io::IsTerminal, path::PathBuf, str::FromStr};
argwerk::define! {
///
///The Conlang prototype debug interface
#[derive(Clone, Debug, FromArgs, PartialEq, Eq, PartialOrd, Ord)]
#[usage = "conlang [<file>] [-I <include...>] [-m <mode>] [-r <repl>]"]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Args {
/// the main source file
#[argh(positional)]
pub file: Option<PathBuf>,
pub include: Vec<PathBuf>,
pub mode: Mode,
pub repl: bool = is_terminal(),
}
///files to include
#[argh(option, short = 'I')]
pub include: Vec<PathBuf>,
["-I" | "--include", path] => {
include.push(path.into());
}
///the CLI operating mode (`f`mt | `l`ex | `r`un)
#[argh(option, short = 'm', default = "Default::default()")]
pub mode: Mode,
["-m" | "--mode", flr] => {
mode = flr.parse()?;
}
///whether to start the repl (`true` or `false`)
#[argh(option, short = 'r', default = "is_terminal()")]
pub repl: bool,
["-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

View File

@ -1,5 +1,5 @@
use cl_repl::cli::run;
use cl_repl::{args, cli::run};
fn main() -> Result<(), Box<dyn std::error::Error>> {
run(argh::from_env())
run(args::Args::args()?)
}