Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - migrated to clap 3 #1957

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 72 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion boa_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
42 changes: 17 additions & 25 deletions boa_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand All @@ -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<PathBuf>,

/// 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<Option<DumpFormat>>,

/// 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,
}

Expand All @@ -117,7 +110,8 @@ impl Opt {
}
}

arg_enum! {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is no longer needed, can it be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i think it should be removed.

#[derive(Debug, Clone, ArgEnum)]
enum DumpFormat {
/// The different types of format available for dumping.
///
// NOTE: This can easily support other formats just by
Expand All @@ -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.
Expand Down Expand Up @@ -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();

Expand Down