From ed4fb52a881ce98300c70f75db4e800be322da54 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Tue, 17 May 2022 08:35:57 +0200 Subject: [PATCH] Migrate to clap from structopt --- Cargo.lock | 74 +++++++++++++++++++++++++---- lib/cli/Cargo.toml | 5 +- lib/cli/src/cli.rs | 39 +++++++-------- lib/cli/src/commands/binfmt.rs | 10 ++-- lib/cli/src/commands/cache.rs | 8 ++-- lib/cli/src/commands/compile.rs | 19 ++++---- lib/cli/src/commands/config.rs | 18 +++---- lib/cli/src/commands/create_exe.rs | 22 +++++---- lib/cli/src/commands/inspect.rs | 8 ++-- lib/cli/src/commands/run.rs | 26 +++++----- lib/cli/src/commands/run/wasi.rs | 25 ++++++---- lib/cli/src/commands/self_update.rs | 4 +- lib/cli/src/commands/validate.rs | 8 ++-- lib/cli/src/commands/wast.rs | 10 ++-- lib/cli/src/common.rs | 16 +++---- lib/cli/src/store.rs | 32 ++++++------- 16 files changed, 201 insertions(+), 123 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 29c762cc714..78b48946171 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -149,7 +149,7 @@ dependencies = [ "bitflags", "cexpr", "clang-sys", - "clap", + "clap 2.34.0", "env_logger", "lazy_static", "lazycell", @@ -267,8 +267,8 @@ version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38728c31b994e4b849cf59feefb4a8bf26acd299ee0b92c9fb35bd14ad4b8dfa" dependencies = [ - "clap", - "heck", + "clap 2.34.0", + "heck 0.3.3", "indexmap", "log", "proc-macro2", @@ -328,11 +328,50 @@ dependencies = [ "atty", "bitflags", "strsim 0.8.0", - "textwrap", + "textwrap 0.11.0", "unicode-width", "vec_map", ] +[[package]] +name = "clap" +version = "3.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b" +dependencies = [ + "atty", + "bitflags", + "clap_derive", + "clap_lex", + "indexmap", + "lazy_static", + "strsim 0.10.0", + "termcolor", + "textwrap 0.15.0", +] + +[[package]] +name = "clap_derive" +version = "3.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c" +dependencies = [ + "heck 0.4.0", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "cmake" version = "0.1.48" @@ -510,7 +549,7 @@ checksum = "1604dafd25fba2fe2d5895a9da139f8dc9b319a5fe5354ca137cbbce4e178d10" dependencies = [ "atty", "cast", - "clap", + "clap 2.34.0", "criterion-plot", "csv", "itertools", @@ -1029,6 +1068,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -1466,6 +1511,12 @@ dependencies = [ "web-sys", ] +[[package]] +name = "os_str_bytes" +version = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "029d8d0b2f198229de29dca79676f2738ff952edf3fde542eb8bf94d8c21b435" + [[package]] name = "output_vt100" version = "0.1.3" @@ -2228,7 +2279,7 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" dependencies = [ - "clap", + "clap 2.34.0", "lazy_static", "structopt-derive", ] @@ -2239,7 +2290,7 @@ version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" dependencies = [ - "heck", + "heck 0.3.3", "proc-macro-error", "proc-macro2", "quote", @@ -2356,6 +2407,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "textwrap" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" + [[package]] name = "thiserror" version = "1.0.30" @@ -2862,11 +2919,12 @@ dependencies = [ "atty", "bytesize", "cfg-if 1.0.0", + "clap 3.1.18", "colored 2.0.0", "distance", "fern", "log", - "structopt", + "target-lexicon 0.12.3", "tempfile", "unix_mode", "wasmer", diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index 2303da10dd6..908910dcb78 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -44,7 +44,7 @@ wasmer-vfs = { version = "=2.2.1", path = "../vfs", default-features = false, f atty = "0.2" colored = "2.0" anyhow = "1.0" -structopt = { version = "0.3", features = ["suggestions"] } +clap = { version = "3.1.18", features = ["derive"] } # For the function names autosuggestion distance = "0.4" # For the inspect subcommand @@ -54,6 +54,7 @@ cfg-if = "1.0" fern = { version = "0.6", features = ["colored"], optional = true } log = { version = "0.4", optional = true } tempfile = "3" +target-lexicon = { version = "0.12.2", features = ["std"] } [target.'cfg(target_os = "linux")'.dependencies] unix_mode = "0.1.3" @@ -119,4 +120,4 @@ headless-minimal = ["headless", "disable-all-logging", "wasi", "dylib", "univers # Deprecated features. jit = ["universal"] -native = ["dylib"] \ No newline at end of file +native = ["dylib"] diff --git a/lib/cli/src/cli.rs b/lib/cli/src/cli.rs index f7bbb5cdf88..e6e2ffc4cae 100644 --- a/lib/cli/src/cli.rs +++ b/lib/cli/src/cli.rs @@ -12,16 +12,16 @@ use crate::commands::{Cache, Config, Inspect, Run, SelfUpdate, Validate}; use crate::error::PrettyError; use anyhow::Result; -use structopt::{clap::ErrorKind, StructOpt}; +use clap::{ErrorKind, Parser}; -#[derive(StructOpt)] +#[derive(Parser)] #[cfg_attr( not(feature = "headless"), - structopt(name = "wasmer", about = "WebAssembly standalone runtime.", author) + clap(name = "wasmer", about = "WebAssembly standalone runtime.", author) )] #[cfg_attr( feature = "headless", - structopt( + clap( name = "wasmer-headless", about = "Headless WebAssembly standalone runtime.", author @@ -30,48 +30,49 @@ use structopt::{clap::ErrorKind, StructOpt}; /// The options for the wasmer Command Line Interface enum WasmerCLIOptions { /// Run a WebAssembly file. Formats accepted: wasm, wat - #[structopt(name = "run")] + #[clap(name = "run")] Run(Run), + // TODO: check whether this should really be a subcommand. /// Wasmer cache - #[structopt(name = "cache")] + #[clap(subcommand, name = "cache")] Cache(Cache), /// Validate a WebAssembly binary - #[structopt(name = "validate")] + #[clap(name = "validate")] Validate(Validate), /// Compile a WebAssembly binary #[cfg(feature = "compiler")] - #[structopt(name = "compile")] + #[clap(name = "compile")] Compile(Compile), /// Compile a WebAssembly binary into a native executable #[cfg(all(feature = "staticlib", feature = "compiler"))] - #[structopt(name = "create-exe")] + #[clap(name = "create-exe")] CreateExe(CreateExe), /// Get various configuration information needed /// to compile programs which use Wasmer - #[structopt(name = "config")] + #[clap(name = "config")] Config(Config), /// Update wasmer to the latest version - #[structopt(name = "self-update")] + #[clap(name = "self-update")] SelfUpdate(SelfUpdate), /// Inspect a WebAssembly file - #[structopt(name = "inspect")] + #[clap(name = "inspect")] Inspect(Inspect), /// Run spec testsuite #[cfg(feature = "wast")] - #[structopt(name = "wast")] + #[clap(name = "wast")] Wast(Wast), /// Unregister and/or register wasmer as binfmt interpreter #[cfg(target_os = "linux")] - #[structopt(name = "binfmt")] + #[clap(name = "binfmt")] Binfmt(Binfmt), } @@ -117,15 +118,15 @@ pub fn wasmer_main() { } else { match command.unwrap_or(&"".to_string()).as_ref() { "cache" | "compile" | "config" | "create-exe" | "help" | "inspect" | "run" - | "self-update" | "validate" | "wast" | "binfmt" => WasmerCLIOptions::from_args(), + | "self-update" | "validate" | "wast" | "binfmt" => WasmerCLIOptions::parse(), _ => { - WasmerCLIOptions::from_iter_safe(args.iter()).unwrap_or_else(|e| { - match e.kind { + WasmerCLIOptions::try_parse_from(args.iter()).unwrap_or_else(|e| { + match e.kind() { // This fixes a issue that: // 1. Shows the version twice when doing `wasmer -V` // 2. Shows the run help (instead of normal help) when doing `wasmer --help` - ErrorKind::VersionDisplayed | ErrorKind::HelpDisplayed => e.exit(), - _ => WasmerCLIOptions::Run(Run::from_args()), + ErrorKind::DisplayVersion | ErrorKind::DisplayHelp => e.exit(), + _ => WasmerCLIOptions::Run(Run::parse()), } }) } diff --git a/lib/cli/src/commands/binfmt.rs b/lib/cli/src/commands/binfmt.rs index 9fa7ef22727..d8acd48a069 100644 --- a/lib/cli/src/commands/binfmt.rs +++ b/lib/cli/src/commands/binfmt.rs @@ -5,10 +5,10 @@ use std::io::Write; use std::os::unix::ffi::OsStrExt; use std::os::unix::fs::MetadataExt; use std::path::{Path, PathBuf}; -use structopt::StructOpt; +use clap::Parser; use Action::*; -#[derive(StructOpt, Clone, Copy)] +#[derive(Parser, Clone, Copy)] enum Action { /// Register wasmer as binfmt interpreter Register, @@ -22,14 +22,14 @@ enum Action { /// /// Check the wasmer repository for a systemd service definition example /// to automate the process at start-up. -#[derive(StructOpt)] +#[derive(Parser)] pub struct Binfmt { // Might be better to traverse the mount list /// Mount point of binfmt_misc fs - #[structopt(long, default_value = "/proc/sys/fs/binfmt_misc/")] + #[clap(long, default_value = "/proc/sys/fs/binfmt_misc/")] binfmt_misc: PathBuf, - #[structopt(subcommand)] + #[clap(subcommand)] action: Action, } diff --git a/lib/cli/src/commands/cache.rs b/lib/cli/src/commands/cache.rs index f5aa21be8e2..af52170f6e0 100644 --- a/lib/cli/src/commands/cache.rs +++ b/lib/cli/src/commands/cache.rs @@ -1,17 +1,17 @@ use crate::common::get_cache_dir; use anyhow::{Context, Result}; use std::fs; -use structopt::StructOpt; +use clap::Parser; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] /// The options for the `wasmer cache` subcommand pub enum Cache { /// Clear the cache - #[structopt(name = "clean")] + #[clap(name = "clean")] Clean, /// Display the location of the cache - #[structopt(name = "dir")] + #[clap(name = "dir")] Dir, } diff --git a/lib/cli/src/commands/compile.rs b/lib/cli/src/commands/compile.rs index 26b60ba8634..37fdd521f59 100644 --- a/lib/cli/src/commands/compile.rs +++ b/lib/cli/src/commands/compile.rs @@ -2,32 +2,35 @@ use crate::store::{EngineType, StoreOptions}; use crate::warning; use anyhow::{Context, Result}; use std::path::PathBuf; -use structopt::StructOpt; +use clap::Parser; use wasmer::*; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] /// The options for the `wasmer compile` subcommand pub struct Compile { /// Input file - #[structopt(name = "FILE", parse(from_os_str))] + #[clap(name = "FILE", parse(from_os_str))] path: PathBuf, /// Output file - #[structopt(name = "OUTPUT PATH", short = "o", parse(from_os_str))] + #[clap(name = "OUTPUT PATH", short = 'o', parse(from_os_str))] output: PathBuf, /// Output path for generated header file - #[structopt(name = "HEADER PATH", long = "header", parse(from_os_str))] + #[clap(name = "HEADER PATH", long = "header", parse(from_os_str))] header_path: Option, /// Compilation Target triple - #[structopt(long = "target")] + #[clap(long = "target")] target_triple: Option, - #[structopt(flatten)] + #[clap(flatten)] store: StoreOptions, - #[structopt(short = "m", multiple = true, number_of_values = 1)] + // TODO: multiple_values or multiple_occurrences, or both? + // TODO: number_of_values = 1 required? need to read some more documentation + // before I can be sure + #[clap(short = 'm', multiple_occurrences = true, number_of_values = 1)] cpu_features: Vec, } diff --git a/lib/cli/src/commands/config.rs b/lib/cli/src/commands/config.rs index 0ded2bf4540..e3bfd90889b 100644 --- a/lib/cli/src/commands/config.rs +++ b/lib/cli/src/commands/config.rs @@ -2,38 +2,38 @@ use crate::VERSION; use anyhow::{Context, Result}; use std::env; use std::path::PathBuf; -use structopt::StructOpt; +use clap::Parser; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] /// The options for the `wasmer config` subcommand pub struct Config { /// Print the installation prefix. - #[structopt(long, conflicts_with = "pkg-config")] + #[clap(long, conflicts_with = "pkg-config")] prefix: bool, /// Directory containing Wasmer executables. - #[structopt(long, conflicts_with = "pkg-config")] + #[clap(long, conflicts_with = "pkg-config")] bindir: bool, /// Directory containing Wasmer headers. - #[structopt(long, conflicts_with = "pkg-config")] + #[clap(long, conflicts_with = "pkg-config")] includedir: bool, /// Directory containing Wasmer libraries. - #[structopt(long, conflicts_with = "pkg-config")] + #[clap(long, conflicts_with = "pkg-config")] libdir: bool, /// Libraries needed to link against Wasmer components. - #[structopt(long, conflicts_with = "pkg-config")] + #[clap(long, conflicts_with = "pkg-config")] libs: bool, /// C compiler flags for files that include Wasmer headers. - #[structopt(long, conflicts_with = "pkg-config")] + #[clap(long, conflicts_with = "pkg-config")] cflags: bool, /// It outputs the necessary details for compiling /// and linking a program to Wasmer, using the `pkg-config` format. - #[structopt(long)] + #[clap(long)] pkg_config: bool, } diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index 960f7310e7b..9ed963fee49 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -6,35 +6,41 @@ use std::env; use std::fs; use std::path::{Path, PathBuf}; use std::process::Command; -use structopt::StructOpt; +use clap::Parser; use wasmer::*; const WASMER_MAIN_C_SOURCE: &[u8] = include_bytes!("wasmer_create_exe_main.c"); -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] /// The options for the `wasmer create-exe` subcommand pub struct CreateExe { /// Input file - #[structopt(name = "FILE", parse(from_os_str))] + #[clap(name = "FILE", parse(from_os_str))] path: PathBuf, /// Output file - #[structopt(name = "OUTPUT PATH", short = "o", parse(from_os_str))] + #[clap(name = "OUTPUT PATH", short = 'o', parse(from_os_str))] output: PathBuf, /// Compilation Target triple - #[structopt(long = "target")] + #[clap(long = "target")] target_triple: Option, - #[structopt(flatten)] + #[clap(flatten)] compiler: CompilerOptions, - #[structopt(short = "m", multiple = true, number_of_values = 1)] + // TODO: multiple_values or multiple_occurrences, or both? + // TODO: number_of_values = 1 required? need to read some more documentation + // before I can be sure + #[clap(short = 'm', multiple_occurrences = true, number_of_values = 1)] cpu_features: Vec, + // TODO: multiple_values or multiple_occurrences, or both? + // TODO: number_of_values = 1 required? need to read some more documentation + // before I can be sure /// Additional libraries to link against. /// This is useful for fixing linker errors that may occur on some systems. - #[structopt(short = "l", multiple = true, number_of_values = 1)] + #[clap(short = 'l', multiple_occurrences = true, number_of_values = 1)] libraries: Vec, } diff --git a/lib/cli/src/commands/inspect.rs b/lib/cli/src/commands/inspect.rs index 4858c749ac8..57ab68a7d12 100644 --- a/lib/cli/src/commands/inspect.rs +++ b/lib/cli/src/commands/inspect.rs @@ -2,17 +2,17 @@ use crate::store::StoreOptions; use anyhow::{Context, Result}; use bytesize::ByteSize; use std::path::PathBuf; -use structopt::StructOpt; +use clap::Parser; use wasmer::*; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] /// The options for the `wasmer validate` subcommand pub struct Inspect { /// File to validate as WebAssembly - #[structopt(name = "FILE", parse(from_os_str))] + #[clap(name = "FILE", parse(from_os_str))] path: PathBuf, - #[structopt(flatten)] + #[clap(flatten)] store: StoreOptions, } diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index 6f82382b922..65af7a77a0f 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -11,7 +11,7 @@ use wasmer::*; #[cfg(feature = "cache")] use wasmer_cache::{Cache, FileSystemCache, Hash}; -use structopt::StructOpt; +use clap::Parser; #[cfg(feature = "wasi")] mod wasi; @@ -19,59 +19,59 @@ mod wasi; #[cfg(feature = "wasi")] use wasi::Wasi; -#[derive(Debug, StructOpt, Clone, Default)] +#[derive(Debug, Parser, Clone, Default)] /// The options for the `wasmer run` subcommand pub struct Run { /// Disable the cache #[cfg(feature = "cache")] - #[structopt(long = "disable-cache")] + #[clap(long = "disable-cache")] disable_cache: bool, /// File to run - #[structopt(name = "FILE", parse(from_os_str))] + #[clap(name = "FILE", parse(from_os_str))] path: PathBuf, /// Invoke a specified function - #[structopt(long = "invoke", short = "i")] + #[clap(long = "invoke", short = 'i')] invoke: Option, /// The command name is a string that will override the first argument passed /// to the wasm program. This is used in wapm to provide nicer output in /// help commands and error messages of the running wasm program - #[structopt(long = "command-name", hidden = true)] + #[clap(long = "command-name", hide = true)] command_name: Option, /// A prehashed string, used to speed up start times by avoiding hashing the /// wasm module. If the specified hash is not found, Wasmer will hash the module /// as if no `cache-key` argument was passed. #[cfg(feature = "cache")] - #[structopt(long = "cache-key", hidden = true)] + #[clap(long = "cache-key", hide = true)] cache_key: Option, - #[structopt(flatten)] + #[clap(flatten)] store: StoreOptions, // TODO: refactor WASI structure to allow shared options with Emscripten #[cfg(feature = "wasi")] - #[structopt(flatten)] + #[clap(flatten)] wasi: Wasi, /// Enable non-standard experimental IO devices #[cfg(feature = "io-devices")] - #[structopt(long = "enable-io-devices")] + #[clap(long = "enable-io-devices")] enable_experimental_io_devices: bool, /// Enable debug output #[cfg(feature = "debug")] - #[structopt(long = "debug", short = "d")] + #[clap(long = "debug", short = 'd')] debug: bool, #[cfg(feature = "debug")] - #[structopt(short, long, parse(from_occurrences))] + #[clap(short, long, parse(from_occurrences))] verbose: u8, /// Application arguments - #[structopt(value_name = "ARGS")] + #[clap(value_name = "ARGS")] args: Vec, } diff --git a/lib/cli/src/commands/run/wasi.rs b/lib/cli/src/commands/run/wasi.rs index 8f408fd443e..47a48b5b916 100644 --- a/lib/cli/src/commands/run/wasi.rs +++ b/lib/cli/src/commands/run/wasi.rs @@ -5,36 +5,45 @@ use std::path::PathBuf; use wasmer::{Instance, Module, RuntimeError, Val}; use wasmer_wasi::{get_wasi_versions, WasiError, WasiState, WasiVersion}; -use structopt::StructOpt; +use clap::Parser; -#[derive(Debug, StructOpt, Clone, Default)] +#[derive(Debug, Parser, Clone, Default)] /// WASI Options pub struct Wasi { + // TODO: multiple_values or multiple_occurrences, or both? + // TODO: number_of_values = 1 required? need to read some more documentation + // before I can be sure /// WASI pre-opened directory - #[structopt( + #[clap( long = "dir", name = "DIR", - multiple = true, + multiple_occurrences = true, group = "wasi", number_of_values = 1 - )] +)] pre_opened_directories: Vec, + // TODO: multiple_values or multiple_occurrences, or both? + // TODO: number_of_values = 1 required? need to read some more documentation + // before I can be sure /// Map a host directory to a different location for the Wasm module - #[structopt( + #[clap( long = "mapdir", name = "GUEST_DIR:HOST_DIR", - multiple = true, + multiple_occurrences = true, parse(try_from_str = parse_mapdir), number_of_values = 1, )] mapped_dirs: Vec<(String, PathBuf)>, + // TODO: multiple_values or multiple_occurrences, or both? + // TODO: number_of_values = 1 required? need to read some more documentation + // before I can be sure /// Pass custom environment variables #[structopt( long = "env", name = "KEY=VALUE", - multiple = true, + multiple_occurrences = true, parse(try_from_str = parse_envvar), )] env_vars: Vec<(String, String)>, diff --git a/lib/cli/src/commands/self_update.rs b/lib/cli/src/commands/self_update.rs index 2218107c3f2..fcd6a276f78 100644 --- a/lib/cli/src/commands/self_update.rs +++ b/lib/cli/src/commands/self_update.rs @@ -2,10 +2,10 @@ use anyhow::{Context, Result}; #[cfg(not(target_os = "windows"))] use std::process::{Command, Stdio}; -use structopt::StructOpt; +use clap::Parser; /// The options for the `wasmer self-update` subcommand -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct SelfUpdate {} impl SelfUpdate { diff --git a/lib/cli/src/commands/validate.rs b/lib/cli/src/commands/validate.rs index fb9554d684e..e438ccd3b89 100644 --- a/lib/cli/src/commands/validate.rs +++ b/lib/cli/src/commands/validate.rs @@ -1,17 +1,17 @@ use crate::store::StoreOptions; use anyhow::{bail, Context, Result}; use std::path::PathBuf; -use structopt::StructOpt; +use clap::Parser; use wasmer::*; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] /// The options for the `wasmer validate` subcommand pub struct Validate { /// File to validate as WebAssembly - #[structopt(name = "FILE", parse(from_os_str))] + #[clap(name = "FILE", parse(from_os_str))] path: PathBuf, - #[structopt(flatten)] + #[clap(flatten)] store: StoreOptions, } diff --git a/lib/cli/src/commands/wast.rs b/lib/cli/src/commands/wast.rs index 2837069f21f..2fc43e42c49 100644 --- a/lib/cli/src/commands/wast.rs +++ b/lib/cli/src/commands/wast.rs @@ -2,20 +2,20 @@ use crate::store::StoreOptions; use anyhow::{Context, Result}; use std::path::PathBuf; -use structopt::StructOpt; +use clap::Parser; use wasmer_wast::Wast as WastSpectest; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] /// The options for the `wasmer wast` subcommand pub struct Wast { /// Wast file to run - #[structopt(name = "FILE", parse(from_os_str))] + #[clap(name = "FILE", parse(from_os_str))] path: PathBuf, - #[structopt(flatten)] + #[clap(flatten)] store: StoreOptions, - #[structopt(short, long)] + #[clap(short, long)] /// A flag to indicate wast stop at the first error or continue. fail_fast: bool, } diff --git a/lib/cli/src/common.rs b/lib/cli/src/common.rs index 863e154103f..d0012e1754a 100644 --- a/lib/cli/src/common.rs +++ b/lib/cli/src/common.rs @@ -3,34 +3,34 @@ use crate::VERSION; use std::env; use std::path::PathBuf; -use structopt::StructOpt; +use clap::Parser; -#[derive(Debug, StructOpt, Clone, Default)] +#[derive(Debug, Parser, Clone, Default)] /// The WebAssembly features that can be passed through the /// Command Line args. pub struct WasmFeatures { /// Enable support for the SIMD proposal. - #[structopt(long = "enable-simd")] + #[clap(long = "enable-simd")] pub simd: bool, /// Enable support for the threads proposal. - #[structopt(long = "enable-threads")] + #[clap(long = "enable-threads")] pub threads: bool, /// Enable support for the reference types proposal. - #[structopt(long = "enable-reference-types")] + #[clap(long = "enable-reference-types")] pub reference_types: bool, /// Enable support for the multi value proposal. - #[structopt(long = "enable-multi-value")] + #[clap(long = "enable-multi-value")] pub multi_value: bool, /// Enable support for the bulk memory proposal. - #[structopt(long = "enable-bulk-memory")] + #[clap(long = "enable-bulk-memory")] pub bulk_memory: bool, /// Enable support for all pre-standard proposals. - #[structopt(long = "enable-all")] + #[clap(long = "enable-all")] pub all: bool, } diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index caf7fa40745..4ad630396e5 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -10,69 +10,69 @@ use std::path::PathBuf; use std::string::ToString; #[allow(unused_imports)] use std::sync::Arc; -use structopt::StructOpt; +use clap::Parser; use wasmer::*; #[cfg(feature = "compiler")] use wasmer_compiler::CompilerConfig; -#[derive(Debug, Clone, StructOpt, Default)] +#[derive(Debug, Clone, Parser, Default)] /// The compiler and engine options pub struct StoreOptions { #[cfg(feature = "compiler")] - #[structopt(flatten)] + #[clap(flatten)] compiler: CompilerOptions, /// Use the Universal Engine. - #[structopt(long, conflicts_with_all = &["dylib", "staticlib", "jit", "native", "object_file"])] + #[clap(long, conflicts_with_all = &["dylib", "staticlib", "jit", "native", "object_file"])] universal: bool, /// Use the Dylib Engine. - #[structopt(long, conflicts_with_all = &["universal", "staticlib", "jit", "native", "object_file"])] + #[clap(long, conflicts_with_all = &["universal", "staticlib", "jit", "native", "object_file"])] dylib: bool, /// Use the Staticlib Engine. - #[structopt(long, conflicts_with_all = &["universal", "dylib", "jit", "native", "object_file"])] + #[clap(long, conflicts_with_all = &["universal", "dylib", "jit", "native", "object_file"])] staticlib: bool, /// Use the JIT (Universal) Engine. - #[structopt(long, hidden = true, conflicts_with_all = &["universal", "dylib", "staticlib", "native", "object_file"])] + #[clap(long, hide = true, conflicts_with_all = &["universal", "dylib", "staticlib", "native", "object_file"])] jit: bool, /// Use the Native (Dylib) Engine. - #[structopt(long, hidden = true, conflicts_with_all = &["universal", "dylib", "staticlib", "jit", "object_file"])] + #[clap(long, hide = true, conflicts_with_all = &["universal", "dylib", "staticlib", "jit", "object_file"])] native: bool, /// Use the ObjectFile (Staticlib) Engine. - #[structopt(long, hidden = true, conflicts_with_all = &["universal", "dylib", "staticlib", "jit", "native"])] + #[clap(long, hide = true, conflicts_with_all = &["universal", "dylib", "staticlib", "jit", "native"])] object_file: bool, } #[cfg(feature = "compiler")] -#[derive(Debug, Clone, StructOpt, Default)] +#[derive(Debug, Clone, Parser, Default)] /// The compiler options pub struct CompilerOptions { /// Use Singlepass compiler. - #[structopt(long, conflicts_with_all = &["cranelift", "llvm"])] + #[clap(long, conflicts_with_all = &["cranelift", "llvm"])] singlepass: bool, /// Use Cranelift compiler. - #[structopt(long, conflicts_with_all = &["singlepass", "llvm"])] + #[clap(long, conflicts_with_all = &["singlepass", "llvm"])] cranelift: bool, /// Use LLVM compiler. - #[structopt(long, conflicts_with_all = &["singlepass", "cranelift"])] + #[clap(long, conflicts_with_all = &["singlepass", "cranelift"])] llvm: bool, /// Enable compiler internal verification. - #[structopt(long)] + #[clap(long)] enable_verifier: bool, /// LLVM debug directory, where IR and object files will be written to. #[cfg(feature = "llvm")] - #[structopt(long, parse(from_os_str))] + #[clap(long, parse(from_os_str))] llvm_debug_dir: Option, - #[structopt(flatten)] + #[clap(flatten)] features: WasmFeatures, }