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