Skip to content

Commit

Permalink
update to clap 4 from structopt
Browse files Browse the repository at this point in the history
  • Loading branch information
ranile committed May 30, 2023
1 parent 624ed91 commit a028357
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 177 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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ serde_ignored = "0.1.7"
serde_json = "1.0.91"
siphasher = "0.3.10"
strsim = "0.10.0"
structopt = "0.3.26"
clap = { version = "4.2.5", features = ["derive"] }
toml = "0.5.11"
ureq = { version = "2.6.2", features = ["json"] }
walkdir = "2.3.2"
Expand Down
43 changes: 18 additions & 25 deletions src/command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::fmt;
use std::path::PathBuf;
use std::str::FromStr;
use std::time::Instant;
use structopt::clap::AppSettings;
use clap::{Args};

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

/// Everything required to configure and run the `wasm-pack build` command.
#[derive(Debug, StructOpt)]
#[structopt(
// 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,
)]
#[derive(Debug, Args)]
#[command(allow_hyphen_values = true, trailing_var_arg = 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))]
#[clap()]
pub path: Option<PathBuf>,

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

#[structopt(long = "mode", short = "m", default_value = "normal")]
#[clap(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")]
#[clap(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")]
#[clap(long = "weak-refs")]
/// Enable usage of the JS weak references proposal.
pub weak_refs: bool,

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

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

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

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

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

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

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

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

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

#[structopt(allow_hyphen_values = true)]
/// List of extra options to pass to `cargo build`
pub extra_options: Vec<String>,
}
Expand Down Expand Up @@ -225,7 +218,7 @@ impl Build {
(false, false, false) | (false, true, false) => BuildProfile::Release,
(true, false, false) => BuildProfile::Dev,
(false, false, true) => BuildProfile::Profiling,
// Unfortunately, `structopt` doesn't expose clap's `conflicts_with`
// Unfortunately, `clap` doesn't expose clap's `conflicts_with`
// functionality yet, so we have to implement it ourselves.
_ => bail!("Can only supply one of the --dev, --release, or --profiling flags"),
};
Expand Down
Loading

0 comments on commit a028357

Please sign in to comment.