Skip to content

Commit

Permalink
Upgrade clap to 4.0, add value hints for zsh and fish (#2336)
Browse files Browse the repository at this point in the history
This Pull Request fixes/closes #2330.

It changes the following:

- Upgrades from clap 3 to clap 4 (note that criterion still uses clap 3, tracked here: bheisler/criterion.rs#596)
- Updates the derive syntax with the new 4.0 syntax
- Adds hints for fish & zsh


Co-authored-by: José Julián Espina <jedel0124@gmail.com>
  • Loading branch information
Razican and jedel1043 committed Oct 15, 2022
1 parent c645f85 commit 9998a67
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 27 deletions.
35 changes: 27 additions & 8 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 = { workspace = true, features = ["deser", "console"] }
boa_interner.workspace = true
rustyline = "10.0.0"
rustyline-derive = "0.7.0"
clap = { version = "3.2.22", features = ["derive"] }
clap = { version = "4.0.12", features = ["derive"] }
serde_json = "1.0.86"
colored = "2.0.0"
regex = "1.6.0"
Expand Down
20 changes: 13 additions & 7 deletions boa_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
)]

use boa_engine::{syntax::ast::node::StatementList, Context};
use clap::{ArgEnum, Parser};
use clap::{Parser, ValueEnum, ValueHint};
use colored::{Color, Colorize};
use rustyline::{config::Config, error::ReadlineError, EditMode, Editor};
use std::{fs::read, fs::OpenOptions, io, path::PathBuf};
Expand All @@ -83,22 +83,28 @@ const READLINE_COLOR: Color = Color::Cyan;
// https://docs.rs/structopt/0.3.11/structopt/#type-magic
#[allow(clippy::option_option)]
#[derive(Debug, Parser)]
#[clap(author, version, about, name = "boa")]
#[command(author, version, about, name = "boa")]
struct Opt {
/// The JavaScript file(s) to be evaluated.
#[clap(name = "FILE", parse(from_os_str))]
#[arg(name = "FILE", value_hint = ValueHint::FilePath)]
files: Vec<PathBuf>,

/// Dump the AST to stdout with the given format.
#[clap(long, short = 'a', value_name = "FORMAT", ignore_case = true, arg_enum)]
#[arg(
long,
short = 'a',
value_name = "FORMAT",
ignore_case = true,
value_enum
)]
dump_ast: Option<Option<DumpFormat>>,

/// Dump the AST to stdout with the given format.
#[clap(long = "trace", short = 't')]
#[arg(long, short)]
trace: bool,

/// Use vi mode in the REPL
#[clap(long = "vi")]
#[arg(long = "vi")]
vi_mode: bool,
}

Expand All @@ -109,7 +115,7 @@ impl Opt {
}
}

#[derive(Debug, Clone, ArgEnum)]
#[derive(Debug, Clone, ValueEnum)]
enum DumpFormat {
/// The different types of format available for dumping.
///
Expand Down
2 changes: 1 addition & 1 deletion boa_tester/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rust-version.workspace = true
boa_engine = { workspace = true, features = ["intl"] }
boa_interner.workspace = true
boa_gc.workspace = true
clap = { version = "3.2.22", features = ["derive"] }
clap = { version = "4.0.12", features = ["derive"] }
serde = { version = "1.0.145", features = ["derive"] }
serde_yaml = "0.9.13"
serde_json = "1.0.86"
Expand Down
21 changes: 11 additions & 10 deletions boa_tester/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ use self::{
};
use anyhow::{bail, Context};
use bitflags::bitflags;
use clap::Parser;
use clap::{ArgAction, Parser, ValueHint};
use colored::Colorize;
use fxhash::{FxHashMap, FxHashSet};
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -194,41 +194,42 @@ static IGNORED: Lazy<Ignored> = Lazy::new(|| {

/// Boa test262 tester
#[derive(Debug, Parser)]
#[clap(author, version, about, name = "Boa test262 tester")]
#[command(author, version, about, name = "Boa test262 tester")]
enum Cli {
/// Run the test suite.
Run {
/// Whether to show verbose output.
#[clap(short, long, parse(from_occurrences))]
#[arg(short, long, action = ArgAction::Count)]
verbose: u8,

/// Path to the Test262 suite.
#[clap(long, parse(from_os_str), default_value = "./test262")]
#[arg(long, default_value = "./test262", value_hint = ValueHint::DirPath)]
test262_path: PathBuf,

/// Which specific test or test suite to run. Should be a path relative to the Test262 directory: e.g. "test/language/types/number"
#[clap(short, long, parse(from_os_str), default_value = "test")]
#[arg(short, long, default_value = "test", value_hint = ValueHint::AnyPath)]
suite: PathBuf,

/// Optional output folder for the full results information.
#[clap(short, long, parse(from_os_str))]
#[arg(short, long, value_hint = ValueHint::DirPath)]
output: Option<PathBuf>,

/// Execute tests serially
#[clap(short, long)]
#[arg(short, long)]
disable_parallelism: bool,
},
/// Compare two test suite results.
Compare {
/// Base results of the suite.
#[clap(parse(from_os_str))]
#[arg(value_hint = ValueHint::FilePath)]
base: PathBuf,

/// New results to compare.
#[clap(parse(from_os_str))]
#[arg(value_hint = ValueHint::FilePath)]
new: PathBuf,

/// Whether to use markdown output
#[clap(short, long)]
#[arg(short, long)]
markdown: bool,
},
}
Expand Down

0 comments on commit 9998a67

Please sign in to comment.