diff --git a/Cargo.lock b/Cargo.lock index 84a4dc13ebf..b71bca5b63e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,6 +69,7 @@ version = "0.14.0" dependencies = [ "boa_engine", "boa_interner", + "clap 3.1.6", "colored", "jemallocator", "phf", @@ -76,7 +77,6 @@ dependencies = [ "rustyline", "rustyline-derive", "serde_json", - "structopt", ] [[package]] @@ -252,12 +252,42 @@ dependencies = [ "ansi_term", "atty", "bitflags", - "strsim", - "textwrap", + "strsim 0.8.0", + "textwrap 0.11.0", "unicode-width", "vec_map", ] +[[package]] +name = "clap" +version = "3.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8c93436c21e4698bacadf42917db28b23017027a4deccb35dbe47a7e7840123" +dependencies = [ + "atty", + "bitflags", + "clap_derive", + "indexmap", + "lazy_static", + "os_str_bytes", + "strsim 0.10.0", + "termcolor", + "textwrap 0.15.0", +] + +[[package]] +name = "clap_derive" +version = "3.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da95d038ede1a964ce99f49cbe27a7fb538d1da595e4b4f70b8c8f338d17bf16" +dependencies = [ + "heck 0.4.0", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "clipboard-win" version = "4.4.1" @@ -288,7 +318,7 @@ checksum = "1604dafd25fba2fe2d5895a9da139f8dc9b319a5fe5354ca137cbbce4e178d10" dependencies = [ "atty", "cast", - "clap", + "clap 2.34.0", "criterion-plot", "csv", "itertools", @@ -576,6 +606,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -926,6 +962,15 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "os_str_bytes" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" +dependencies = [ + "memchr", +] + [[package]] name = "parking_lot" version = "0.11.2" @@ -1398,13 +1443,19 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "structopt" version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" dependencies = [ - "clap", + "clap 2.34.0", "lazy_static", "structopt-derive", ] @@ -1415,7 +1466,7 @@ version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" dependencies = [ - "heck", + "heck 0.3.3", "proc-macro-error", "proc-macro2", "quote", @@ -1451,6 +1502,15 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + [[package]] name = "textwrap" version = "0.11.0" @@ -1460,6 +1520,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "textwrap" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" + [[package]] name = "time" version = "0.1.44" diff --git a/boa_cli/Cargo.toml b/boa_cli/Cargo.toml index 61a4c576a39..64a09203dda 100644 --- a/boa_cli/Cargo.toml +++ b/boa_cli/Cargo.toml @@ -16,7 +16,7 @@ boa_engine = { path = "../boa_engine", features = ["deser", "console"], version boa_interner = { path = "../boa_interner", version = "0.14.0" } rustyline = "9.1.2" rustyline-derive = "0.6.0" -structopt = "0.3.26" +clap = { version = "3.1.6", features = ["derive"] } serde_json = "1.0.79" colored = "2.0.0" regex = "1.5.5" diff --git a/boa_cli/src/main.rs b/boa_cli/src/main.rs index 87bfb70c804..dc0265263cc 100644 --- a/boa_cli/src/main.rs +++ b/boa_cli/src/main.rs @@ -61,11 +61,10 @@ use boa_engine::{syntax::ast::node::StatementList, Context}; use boa_interner::Interner; +use clap::{ArgEnum, Parser}; use colored::{Color, Colorize}; use rustyline::{config::Config, error::ReadlineError, EditMode, Editor}; use std::{fs::read, io, path::PathBuf}; -use structopt::{clap::arg_enum, StructOpt}; - mod helper; #[cfg(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))] @@ -84,29 +83,23 @@ const READLINE_COLOR: Color = Color::Cyan; // is an optional argument that optionally takes a value ([--opt=[val]]). // https://docs.rs/structopt/0.3.11/structopt/#type-magic #[allow(clippy::option_option)] -#[derive(Debug, StructOpt)] -#[structopt(author, about, name = "boa")] +#[derive(Debug, Parser)] +#[clap(author, about, name = "boa")] struct Opt { /// The JavaScript file(s) to be evaluated. - #[structopt(name = "FILE", parse(from_os_str))] + #[clap(name = "FILE", parse(from_os_str))] files: Vec, /// Dump the AST to stdout with the given format. - #[structopt( - long, - short = "a", - value_name = "FORMAT", - possible_values = &DumpFormat::variants(), - case_insensitive = true - )] + #[clap(long, short = 'a', value_name = "FORMAT", ignore_case = true, arg_enum)] dump_ast: Option>, /// Dump the AST to stdout with the given format. - #[structopt(long = "trace", short = "t")] + #[clap(long = "trace", short = 't')] trace: bool, /// Use vi mode in the REPL - #[structopt(long = "vi")] + #[clap(long = "vi")] vi_mode: bool, } @@ -117,7 +110,8 @@ impl Opt { } } -arg_enum! { +#[derive(Debug, Clone, ArgEnum)] +enum DumpFormat { /// The different types of format available for dumping. /// // NOTE: This can easily support other formats just by @@ -126,17 +120,15 @@ arg_enum! { // // NOTE: The fields of this enum are not doc comments because // arg_enum! macro does not support it. - #[derive(Debug)] - enum DumpFormat { - // This is the default format that you get from std::fmt::Debug. - Debug, - // This is a minified json format. - Json, + // This is the default format that you get from std::fmt::Debug. + Debug, - // This is a pretty printed json format. - JsonPretty, - } + // This is a minified json format. + Json, + + // This is a pretty printed json format. + JsonPretty, } /// Parses the the token stream into an AST and returns it. @@ -191,7 +183,7 @@ where } pub fn main() -> Result<(), std::io::Error> { - let args = Opt::from_args(); + let args = Opt::parse(); let mut context = Context::default();