cl-repl: Switch from argh to argwerk
This commit is contained in:
parent
a3bb1ef447
commit
2ed8481489
@ -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"
|
||||||
|
@ -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 file: Option<PathBuf>,
|
pub struct Args {
|
||||||
|
pub file: Option<PathBuf>,
|
||||||
|
pub include: Vec<PathBuf>,
|
||||||
|
pub mode: Mode,
|
||||||
|
pub repl: bool = is_terminal(),
|
||||||
|
}
|
||||||
|
|
||||||
/// files to include
|
///files to include
|
||||||
#[argh(option, short = 'I')]
|
["-I" | "--include", path] => {
|
||||||
pub include: Vec<PathBuf>,
|
include.push(path.into());
|
||||||
|
}
|
||||||
/// the CLI operating mode (`f`mt | `l`ex | `r`un)
|
///the CLI operating mode (`f`mt | `l`ex | `r`un)
|
||||||
#[argh(option, short = 'm', default = "Default::default()")]
|
["-m" | "--mode", flr] => {
|
||||||
pub mode: Mode,
|
mode = flr.parse()?;
|
||||||
|
}
|
||||||
/// whether to start the repl (`true` or `false`)
|
///whether to start the repl (`true` or `false`)
|
||||||
#[argh(option, short = 'r', default = "is_terminal()")]
|
["-r" | "--repl", bool] => {
|
||||||
pub 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
|
||||||
|
@ -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()?)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user