From eca8638d5719f7c0abd664a31d7416945100a051 Mon Sep 17 00:00:00 2001 From: manthanabc Date: Sat, 19 Mar 2022 16:43:28 +0530 Subject: [PATCH 1/6] migrated to clap 3 --- boa_cli/Cargo.toml | 2 +- boa_cli/src/main.rs | 32 ++++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) 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..880ef49c1bc 100644 --- a/boa_cli/src/main.rs +++ b/boa_cli/src/main.rs @@ -64,8 +64,11 @@ use boa_interner::Interner; 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}; - +// use structopt::{clap::arg_enum, StructOpt}; +#[macro_use] +use clap; +use clap::StructOpt; +use clap::ArgEnum; mod helper; #[cfg(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))] @@ -85,28 +88,28 @@ const READLINE_COLOR: Color = Color::Cyan; // https://docs.rs/structopt/0.3.11/structopt/#type-magic #[allow(clippy::option_option)] #[derive(Debug, StructOpt)] -#[structopt(author, about, name = "boa")] +#[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( + #[clap( long, - short = "a", + short = 'a', value_name = "FORMAT", - possible_values = &DumpFormat::variants(), - case_insensitive = true + case_insensitive = 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,6 +120,7 @@ impl Opt { } } +/* arg_enum! { /// The different types of format available for dumping. /// @@ -137,6 +141,14 @@ arg_enum! { // This is a pretty printed json format. JsonPretty, } +} **/ + + +#[derive(Debug, Clone, ArgEnum)] + enum DumpFormat { + Debug, + Json, + JsonPretty, } /// Parses the the token stream into an AST and returns it. From 531f8085f01e4b79c3ff20e761cda8676b622239 Mon Sep 17 00:00:00 2001 From: manthanabc Date: Sat, 19 Mar 2022 19:33:48 +0530 Subject: [PATCH 2/6] formating --- Cargo.lock | 78 +++++++++++++++++++++++++++++++++++++++++---- boa_cli/src/main.rs | 8 ++--- 2 files changed, 74 insertions(+), 12 deletions(-) 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/src/main.rs b/boa_cli/src/main.rs index 880ef49c1bc..5549d5111bc 100644 --- a/boa_cli/src/main.rs +++ b/boa_cli/src/main.rs @@ -65,10 +65,7 @@ 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}; -#[macro_use] -use clap; -use clap::StructOpt; -use clap::ArgEnum; +use clap::{ ArgEnum, StructOpt }; mod helper; #[cfg(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))] @@ -143,9 +140,8 @@ arg_enum! { } } **/ - #[derive(Debug, Clone, ArgEnum)] - enum DumpFormat { +enum DumpFormat { Debug, Json, JsonPretty, From 3613154495ed78a81a77eba99a85a270d32837b1 Mon Sep 17 00:00:00 2001 From: manthanabc Date: Sat, 19 Mar 2022 19:51:42 +0530 Subject: [PATCH 3/6] fixed --- boa_cli/src/main.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/boa_cli/src/main.rs b/boa_cli/src/main.rs index 5549d5111bc..23211e53f1c 100644 --- a/boa_cli/src/main.rs +++ b/boa_cli/src/main.rs @@ -64,8 +64,8 @@ use boa_interner::Interner; 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}; -use clap::{ ArgEnum, StructOpt }; +//use structopt::{clap::arg_enum, StructOpt}; +use clap::{ArgEnum, Parser}; mod helper; #[cfg(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))] @@ -84,7 +84,7 @@ 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)] +#[derive(Debug, Parser)] #[clap(author, about, name = "boa")] struct Opt { /// The JavaScript file(s) to be evaluated. @@ -141,6 +141,7 @@ arg_enum! { } **/ #[derive(Debug, Clone, ArgEnum)] +#[clap(name = 'a')] enum DumpFormat { Debug, Json, From f6b0b872f3c25862451f848d714a8277da0be7d0 Mon Sep 17 00:00:00 2001 From: manthanabc Date: Sat, 19 Mar 2022 20:55:28 +0530 Subject: [PATCH 4/6] removed extra code --- boa_cli/src/main.rs | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/boa_cli/src/main.rs b/boa_cli/src/main.rs index 23211e53f1c..0af3c39641d 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}; -use clap::{ArgEnum, Parser}; mod helper; #[cfg(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))] @@ -117,8 +116,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 @@ -127,24 +126,14 @@ 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 a pretty printed json format. - JsonPretty, - } -} **/ - -#[derive(Debug, Clone, ArgEnum)] -#[clap(name = 'a')] -enum DumpFormat { + // This is the default format that you get from std::fmt::Debug. Debug, + + // This is a minified json format. Json, + + // This is a pretty printed json format. JsonPretty, } From edfcb2e46b83461747bfc47078db43d08cd1c9e9 Mon Sep 17 00:00:00 2001 From: manthanabc Date: Sun, 20 Mar 2022 01:40:42 +0530 Subject: [PATCH 5/6] replaced depricated --- boa_cli/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boa_cli/src/main.rs b/boa_cli/src/main.rs index 0af3c39641d..6689404f388 100644 --- a/boa_cli/src/main.rs +++ b/boa_cli/src/main.rs @@ -95,7 +95,7 @@ struct Opt { long, short = 'a', value_name = "FORMAT", - case_insensitive = true, + ignore_case = true, arg_enum )] dump_ast: Option>, @@ -189,7 +189,7 @@ where } pub fn main() -> Result<(), std::io::Error> { - let args = Opt::from_args(); + let args = Opt::parse(); let mut context = Context::default(); From f5e20beb8b9ccebd5f3e0e6b6bac2651809726e6 Mon Sep 17 00:00:00 2001 From: manthanabc Date: Sun, 20 Mar 2022 15:50:22 +0530 Subject: [PATCH 6/6] formating --- boa_cli/src/main.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/boa_cli/src/main.rs b/boa_cli/src/main.rs index 6689404f388..dc0265263cc 100644 --- a/boa_cli/src/main.rs +++ b/boa_cli/src/main.rs @@ -91,13 +91,7 @@ struct Opt { files: Vec, /// Dump the AST to stdout with the given format. - #[clap( - long, - short = 'a', - value_name = "FORMAT", - ignore_case = true, - arg_enum - )] + #[clap(long, short = 'a', value_name = "FORMAT", ignore_case = true, arg_enum)] dump_ast: Option>, /// Dump the AST to stdout with the given format.