Skip to content

Commit

Permalink
migrated to clap 3 (#1957)
Browse files Browse the repository at this point in the history
This Pull Request fixes/closes #1955.

It changes the following:

- changes structopt to clap
  • Loading branch information
manthanabc committed Mar 20, 2022
1 parent e73c3fd commit 5fa1668
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 32 deletions.
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! {
#[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

0 comments on commit 5fa1668

Please sign in to comment.