Skip to content

Commit

Permalink
Replace clap attributes with command and arg
Browse files Browse the repository at this point in the history
  • Loading branch information
iawia002 committed Dec 8, 2023
1 parent 3b61c51 commit 358d438
Show file tree
Hide file tree
Showing 25 changed files with 158 additions and 166 deletions.
4 changes: 2 additions & 2 deletions cranelift/isle/islec/src/main.rs
Expand Up @@ -12,11 +12,11 @@ use std::{
struct Opts {
/// The output file to write the generated Rust code to. `stdout` is used if
/// this is not given.
#[clap(short, long)]
#[arg(short, long)]
output: Option<PathBuf>,

/// The input ISLE DSL source files.
#[clap(required = true)]
#[arg(required = true)]
inputs: Vec<PathBuf>,
}

Expand Down
4 changes: 2 additions & 2 deletions cranelift/serde/src/clif-json.rs
Expand Up @@ -37,12 +37,12 @@ fn call_de(file: &File) -> Result<(), String> {

/// Cranelift JSON serializer/deserializer utility
#[derive(Parser, Debug)]
#[clap(about)]
#[command(about)]
enum Args {
/// Serializes Cranelift IR into JSON
Serialize {
/// Generate pretty json
#[clap(long, short)]
#[arg(long, short)]
pretty: bool,

/// Input file for serialization
Expand Down
4 changes: 2 additions & 2 deletions cranelift/src/bugpoint.rs
Expand Up @@ -26,14 +26,14 @@ pub struct Options {
file: PathBuf,

/// Configure Cranelift settings
#[clap(long = "set")]
#[arg(long = "set")]
settings: Vec<String>,

/// Specify the target architecture.
target: String,

/// Be more verbose
#[clap(short, long)]
#[arg(short, long)]
verbose: bool,
}

Expand Down
2 changes: 1 addition & 1 deletion cranelift/src/cat.rs
Expand Up @@ -13,7 +13,7 @@ use std::path::{Path, PathBuf};
#[derive(Parser)]
pub struct Options {
/// Specify input file(s) to be used. Use '-' for stdin.
#[clap(required = true)]
#[arg(required = true)]
files: Vec<PathBuf>,
}

Expand Down
12 changes: 6 additions & 6 deletions cranelift/src/clif-util.rs
Expand Up @@ -43,27 +43,27 @@ enum Commands {
#[derive(Parser)]
struct TestOptions {
/// Be more verbose
#[clap(short, long)]
#[arg(short, long)]
verbose: bool,

/// Print pass timing report for test
#[clap(short = 'T')]
#[arg(short = 'T')]
time_passes: bool,

/// Specify an input file to be used. Use '-' for stdin.
#[clap(required = true)]
#[arg(required = true)]
files: Vec<PathBuf>,
}

/// Run specified pass(es) on an input file.
#[derive(Parser)]
struct PassOptions {
/// Be more verbose
#[clap(short, long)]
#[arg(short, long)]
verbose: bool,

/// Print pass timing report for test
#[clap(short = 'T')]
#[arg(short = 'T')]
time_passes: bool,

/// Specify an input file to be used. Use '-' for stdin.
Expand All @@ -73,7 +73,7 @@ struct PassOptions {
target: String,

/// Specify pass(es) to be run on the input file
#[clap(required = true)]
#[arg(required = true)]
passes: Vec<String>,
}

Expand Down
12 changes: 6 additions & 6 deletions cranelift/src/compile.rs
Expand Up @@ -17,30 +17,30 @@ use std::path::PathBuf;
#[derive(Parser)]
pub struct Options {
/// Print the resulting Cranelift IR
#[clap(short)]
#[arg(short)]
print: bool,

/// Print pass timing report
#[clap(short = 'T')]
#[arg(short = 'T')]
report_times: bool,

/// Print machine code disassembly
#[clap(short = 'D', long)]
#[arg(short = 'D', long)]
disasm: bool,

/// Configure Cranelift settings
#[clap(long = "set")]
#[arg(long = "set")]
settings: Vec<String>,

/// Specify the Cranelift target
#[clap(long = "target")]
#[arg(long = "target")]
target: String,

/// Specify an input file to be used. Use '-' for stdin.
files: Vec<PathBuf>,

/// Output object file
#[clap(short = 'o', long = "output")]
#[arg(short = 'o', long = "output")]
output: Option<PathBuf>,
}

Expand Down
4 changes: 2 additions & 2 deletions cranelift/src/interpret.rs
Expand Up @@ -14,11 +14,11 @@ use thiserror::Error;
#[derive(Parser)]
pub struct Options {
/// Specify an input file to be used. Use '-' for stdin.
#[clap(required = true)]
#[arg(required = true)]
files: Vec<PathBuf>,

/// Be more verbose
#[clap(short, long)]
#[arg(short, long)]
verbose: bool,
}

Expand Down
2 changes: 1 addition & 1 deletion cranelift/src/print_cfg.rs
Expand Up @@ -14,7 +14,7 @@ use std::path::{Path, PathBuf};
#[derive(Parser)]
pub struct Options {
/// Specify an input file to be used. Use '-' for stdin.
#[clap(required = true)]
#[arg(required = true)]
files: Vec<PathBuf>,
}

Expand Down
4 changes: 2 additions & 2 deletions cranelift/src/run.rs
Expand Up @@ -14,11 +14,11 @@ use target_lexicon::Triple;
#[derive(Parser)]
pub struct Options {
/// Specify an input file to be used. Use '-' for stdin.
#[clap(required = true)]
#[arg(required = true)]
files: Vec<PathBuf>,

/// Be more verbose
#[clap(short, long)]
#[arg(short, long)]
verbose: bool,
}

Expand Down
10 changes: 5 additions & 5 deletions cranelift/src/souper_harvest.rs
Expand Up @@ -22,21 +22,21 @@ pub struct Options {

/// Specify the directory where harvested left-hand side files should be
/// written to.
#[clap(short, long)]
#[arg(short, long)]
output_dir: PathBuf,

/// Configure Cranelift settings
#[clap(long = "set")]
#[arg(long = "set")]
settings: Vec<String>,

/// Specify the Cranelift target
#[clap(long = "target")]
#[arg(long = "target")]
target: String,

/// Add a comment from which CLIF variable and function each left-hand side
/// was harvested from. This prevents deduplicating harvested left-hand
/// sides.
#[clap(long)]
#[arg(long)]
add_harvest_source: bool,
}

Expand All @@ -56,7 +56,7 @@ pub fn run(options: &Options) -> Result<()> {
))
};

match std::fs::create_dir_all(&options.output_dir) {
match fs::create_dir_all(&options.output_dir) {
Ok(_) => {}
Err(e)
if e.kind() == io::ErrorKind::AlreadyExists
Expand Down
20 changes: 10 additions & 10 deletions cranelift/src/wasm.rs
Expand Up @@ -59,46 +59,46 @@ macro_rules! vcprint {
#[derive(Parser)]
pub struct Options {
/// Be more verbose
#[clap(short, long)]
#[arg(short, long)]
verbose: bool,

/// Print the resulting Cranelift IR
#[clap(short)]
#[arg(short)]
print: bool,

/// Print pass timing report
#[clap(short = 'T')]
#[arg(short = 'T')]
report_times: bool,

/// Print machine code disassembly
#[clap(short = 'D', long)]
#[arg(short = 'D', long)]
disasm: bool,

/// Configure Cranelift settings
#[clap(long = "set")]
#[arg(long = "set")]
settings: Vec<String>,

/// Specify the Cranelift target
#[clap(long = "target")]
#[arg(long = "target")]
target: String,

/// Specify an input file to be used. Use '-' for stdin.
files: Vec<PathBuf>,

/// Print bytecode size
#[clap(short = 'X')]
#[arg(short = 'X')]
print_size: bool,

/// Just decode Wasm into Cranelift IR, don't compile it to native code
#[clap(short = 't')]
#[arg(short = 't')]
just_decode: bool,

/// Just checks the correctness of Cranelift IR translated from Wasm
#[clap(short = 'c')]
#[arg(short = 'c')]
check_translation: bool,

/// Use colors in output? [options: auto/never/always; default: auto]
#[clap(long = "color", default_value("auto"))]
#[arg(long = "color", default_value("auto"))]
color: ColorOpt,
}

Expand Down
22 changes: 11 additions & 11 deletions crates/cli-flags/src/lib.rs
Expand Up @@ -290,39 +290,39 @@ pub struct CommonOptions {
// now.
/// Optimization and tuning related options for wasm performance, `-O help` to
/// see all.
#[clap(short = 'O', long = "optimize", value_name = "KEY[=VAL[,..]]")]
#[arg(short = 'O', long = "optimize", value_name = "KEY[=VAL[,..]]")]
opts_raw: Vec<opt::CommaSeparated<Optimize>>,

/// Codegen-related configuration options, `-C help` to see all.
#[clap(short = 'C', long = "codegen", value_name = "KEY[=VAL[,..]]")]
#[arg(short = 'C', long = "codegen", value_name = "KEY[=VAL[,..]]")]
codegen_raw: Vec<opt::CommaSeparated<Codegen>>,

/// Debug-related configuration options, `-D help` to see all.
#[clap(short = 'D', long = "debug", value_name = "KEY[=VAL[,..]]")]
#[arg(short = 'D', long = "debug", value_name = "KEY[=VAL[,..]]")]
debug_raw: Vec<opt::CommaSeparated<Debug>>,

/// Options for configuring semantic execution of WebAssembly, `-W help` to see
/// all.
#[clap(short = 'W', long = "wasm", value_name = "KEY[=VAL[,..]]")]
#[arg(short = 'W', long = "wasm", value_name = "KEY[=VAL[,..]]")]
wasm_raw: Vec<opt::CommaSeparated<Wasm>>,

/// Options for configuring WASI and its proposals, `-S help` to see all.
#[clap(short = 'S', long = "wasi", value_name = "KEY[=VAL[,..]]")]
#[arg(short = 'S', long = "wasi", value_name = "KEY[=VAL[,..]]")]
wasi_raw: Vec<opt::CommaSeparated<Wasi>>,

// These fields are filled in by the `configure` method below via the
// options parsed from the CLI above. This is what the CLI should use.
#[clap(skip)]
#[arg(skip)]
configured: bool,
#[clap(skip)]
#[arg(skip)]
pub opts: OptimizeOptions,
#[clap(skip)]
#[arg(skip)]
pub codegen: CodegenOptions,
#[clap(skip)]
#[arg(skip)]
pub debug: DebugOptions,
#[clap(skip)]
#[arg(skip)]
pub wasm: WasmOptions,
#[clap(skip)]
#[arg(skip)]
pub wasi: WasiOptions,
}

Expand Down
22 changes: 11 additions & 11 deletions crates/environ/examples/factc.rs
Expand Up @@ -24,53 +24,53 @@ use wasmtime_environ::fact::Module;
#[derive(Parser)]
struct Factc {
/// Whether or not debug code is inserted into the generated adapter.
#[clap(long)]
#[arg(long)]
debug: bool,

/// Whether or not the lifting options (the callee of the exported adapter)
/// uses a 64-bit memory as opposed to a 32-bit memory.
#[clap(long)]
#[arg(long)]
lift64: bool,

/// Whether or not the lowering options (the caller of the exported adapter)
/// uses a 64-bit memory as opposed to a 32-bit memory.
#[clap(long)]
#[arg(long)]
lower64: bool,

/// Whether or not a call to a `post-return` configured function is enabled
/// or not.
#[clap(long)]
#[arg(long)]
post_return: bool,

/// Whether or not to skip validation of the generated adapter module.
#[clap(long)]
#[arg(long)]
skip_validate: bool,

/// Where to place the generated adapter module. Standard output is used if
/// this is not specified.
#[clap(short, long)]
#[arg(short, long)]
output: Option<PathBuf>,

/// Output the text format for WebAssembly instead of the binary format.
#[clap(short, long)]
#[arg(short, long)]
text: bool,

#[clap(long, value_parser = parse_string_encoding, default_value = "utf8")]
#[arg(long, value_parser = parse_string_encoding, default_value = "utf8")]
lift_str: StringEncoding,

#[clap(long, value_parser = parse_string_encoding, default_value = "utf8")]
#[arg(long, value_parser = parse_string_encoding, default_value = "utf8")]
lower_str: StringEncoding,

/// TODO
input: PathBuf,
}

fn parse_string_encoding(name: &str) -> anyhow::Result<StringEncoding> {
fn parse_string_encoding(name: &str) -> Result<StringEncoding> {
Ok(match name {
"utf8" => StringEncoding::Utf8,
"utf16" => StringEncoding::Utf16,
"compact-utf16" => StringEncoding::CompactUtf16,
other => anyhow::bail!("invalid string encoding: `{other}`"),
other => bail!("invalid string encoding: `{other}`"),
})
}

Expand Down
6 changes: 3 additions & 3 deletions src/bin/wasmtime.rs
Expand Up @@ -8,7 +8,7 @@ use clap::Parser;

/// Wasmtime WebAssembly Runtime
#[derive(Parser, PartialEq)]
#[clap(
#[command(
version = version(),
after_help = "If a subcommand is not provided, the `run` subcommand will be used.\n\
\n\
Expand All @@ -34,9 +34,9 @@ use clap::Parser;
args_conflicts_with_subcommands = true
)]
struct Wasmtime {
#[clap(subcommand)]
#[command(subcommand)]
subcommand: Option<Subcommand>,
#[clap(flatten)]
#[command(flatten)]
run: wasmtime_cli::commands::RunCommand,
}

Expand Down

0 comments on commit 358d438

Please sign in to comment.