#[derive(Debug, Default)]
pub struct Cli {
pub file: Option<String>,
pub argv: Vec<String>,
pub show_version: bool,
pub show_help: bool,
pub dump_tokens: bool,
pub dump_ast: bool,
pub disasm: bool,
pub tiers: bool,
pub lsp: bool,
pub dap: bool,
}
pub fn parse<I: IntoIterator<Item = String>>(args: I) -> Result<Cli, String> {
let mut cli = Cli::default();
for a in args {
match a.as_str() {
"--version" | "-version" => cli.show_version = true,
"--help" | "-h" | "-help" | "-?" => cli.show_help = true,
"--dump-tokens" => cli.dump_tokens = true,
"--dump-ast" => cli.dump_ast = true,
"--disasm" => cli.disasm = true,
"--tiers" => cli.tiers = true,
"--lsp" => cli.lsp = true,
"--dap" => cli.dap = true,
_ if a.starts_with('-') && cli.file.is_none() => {
return Err(format!("javars: unrecognized option `{a}`"))
}
_ => {
if cli.file.is_none() {
cli.file = Some(a);
} else {
cli.argv.push(a);
}
}
}
}
Ok(cli)
}
pub const USAGE: &str = "\
usage: java [options] <file.java> [args...]
options:
-version, --version print the version banner and exit
-h, --help print this help and exit
--dump-tokens FILE print the lexer token stream and exit
--dump-ast FILE print the parsed AST and exit
--disasm FILE print the lowered fusevm bytecode and exit
--tiers FILE run it, then report which fusevm tiers took it
--lsp speak the Language Server Protocol over stdio
--dap speak the Debug Adapter Protocol over stdio
";