Skip to content

Commit

Permalink
Replace structopt with clap (allocations increased)
Browse files Browse the repository at this point in the history
  • Loading branch information
dullbananas committed Jun 8, 2023
1 parent dc9e99c commit 0692377
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 168 deletions.
138 changes: 39 additions & 99 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 Cargo.toml
Expand Up @@ -16,6 +16,7 @@ atty = "0.2.14"
binary-install = "0.1.0"
cargo_metadata = "0.15.2"
chrono = "0.4.23"
clap = { version = "4.3.2", features = ["derive"] }
console = "0.15.5"
dhat = { version = "0.3.2", optional = true }
dialoguer = "0.10.3"
Expand All @@ -31,7 +32,6 @@ serde_ignored = "0.1.7"
serde_json = "1.0.91"
siphasher = "0.3.10"
strsim = "0.10.0"
structopt = "0.3.26"
toml = "0.5.11"
ureq = { version = "2.6.2", features = ["json"] }
walkdir = "2.3.2"
Expand Down
39 changes: 17 additions & 22 deletions src/command/build.rs
Expand Up @@ -19,7 +19,6 @@ use std::fmt;
use std::path::PathBuf;
use std::str::FromStr;
use std::time::Instant;
use structopt::clap::AppSettings;

/// Everything required to configure and run the `wasm-pack build` command.
#[allow(missing_docs)]
Expand Down Expand Up @@ -109,74 +108,70 @@ pub enum BuildProfile {
}

/// Everything required to configure and run the `wasm-pack build` command.
#[derive(Debug, StructOpt)]
#[structopt(
#[derive(Debug, Parser)]
#[command(
// Allows unknown `--option`s to be parsed as positional arguments, so we can forward it to `cargo`.
setting = AppSettings::AllowLeadingHyphen,
// Allows `--` to be parsed as an argument, so we can forward it to `cargo`.
setting = AppSettings::TrailingVarArg,
allow_hyphen_values = true,
)]
pub struct BuildOptions {
/// The path to the Rust crate. If not set, searches up the path from the current directory.
#[structopt(parse(from_os_str))]
pub path: Option<PathBuf>,

/// The npm scope to use in package.json, if any.
#[structopt(long = "scope", short = "s")]
#[arg(long = "scope", short = 's')]
pub scope: Option<String>,

#[structopt(long = "mode", short = "m", default_value = "normal")]
#[arg(long = "mode", short = 'm', default_value = "normal")]
/// Sets steps to be run. [possible values: no-install, normal, force]
pub mode: InstallMode,

#[structopt(long = "no-typescript")]
#[arg(long = "no-typescript")]
/// By default a *.d.ts file is generated for the generated JS file, but
/// this flag will disable generating this TypeScript file.
pub disable_dts: bool,

#[structopt(long = "weak-refs")]
#[arg(long = "weak-refs")]
/// Enable usage of the JS weak references proposal.
pub weak_refs: bool,

#[structopt(long = "reference-types")]
#[arg(long = "reference-types")]
/// Enable usage of WebAssembly reference types.
pub reference_types: bool,

#[structopt(long = "target", short = "t", default_value = "bundler")]
#[arg(long = "target", short = 't', default_value = "bundler")]
/// Sets the target environment. [possible values: bundler, nodejs, web, no-modules]
pub target: Target,

#[structopt(long = "debug")]
#[arg(long = "debug")]
/// Deprecated. Renamed to `--dev`.
pub debug: bool,

#[structopt(long = "dev")]
#[arg(long = "dev")]
/// Create a development build. Enable debug info, and disable
/// optimizations.
pub dev: bool,

#[structopt(long = "release")]
#[arg(long = "release")]
/// Create a release build. Enable optimizations and disable debug info.
pub release: bool,

#[structopt(long = "profiling")]
#[arg(long = "profiling")]
/// Create a profiling build. Enable optimizations and debug info.
pub profiling: bool,

#[structopt(long = "out-dir", short = "d", default_value = "pkg")]
#[arg(long = "out-dir", short = 'd', default_value = "pkg")]
/// Sets the output directory with a relative path.
pub out_dir: String,

#[structopt(long = "out-name")]
#[arg(long = "out-name")]
/// Sets the output file names. Defaults to package name.
pub out_name: Option<String>,

#[structopt(long = "no-pack", alias = "no-package")]
#[arg(long = "no-pack", alias = "no-package")]
/// Option to not generate a package.json
pub no_pack: bool,

#[structopt(allow_hyphen_values = true)]
#[structopt(allow_hyphen_values = true, trailing_var_arg = true)]
/// List of extra options to pass to `cargo build`
pub extra_options: Vec<String>,
}
Expand Down

1 comment on commit 0692377

@dullbananas
Copy link
Owner Author

Choose a reason for hiding this comment

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

Actually this might be better because the heap usage after parsing is lower

clap-rs/clap#4956 (comment)

Please sign in to comment.