Update to clap 3.* (#4082)

* Update to clap 3.0

This commit migrates all CLI commands internally used in this project
from structopt/clap2 to clap 3. The intent here is to ensure that we're
using maintained versions of the dependencies as structopt and clap 2
are less maintained nowadays. Most transitions were pretty
straightforward and mostly dealing with structopt/clap3 differences.

* Fix a number of `cargo deny` errors

This commit fixes a few errors around duplicate dependencies which
arose from the prior update to clap3. This also uses a new feature in
`deny.toml`, `skip-tree`, which allows having a bit more targeted
ignores for skips of duplicate version checks. This showed a few more
locations in Wasmtime itself where we could update some dependencies.
This commit is contained in:
Alex Crichton
2022-04-28 12:47:12 -05:00
committed by GitHub
parent 871a9d93f2
commit 5fe06f7345
30 changed files with 295 additions and 325 deletions

View File

@@ -21,7 +21,7 @@
)
)]
use clap::{App, Arg, SubCommand};
use clap::Parser;
use cranelift_codegen::ir::Function;
use cranelift_reader::parse_functions;
use std::fs::File;
@@ -54,50 +54,40 @@ fn call_de(file: &File) -> Result<(), String> {
Ok(())
}
fn main() {
let matches = App::new("Cranelift JSON serializer/deserializer utility")
.subcommand(
SubCommand::with_name("serialize")
.display_order(1)
.about("Serializes Cranelift IR into JSON.")
.arg(Arg::with_name("pretty").short("p").help("pretty json"))
.arg(
Arg::with_name("FILE")
.required(true)
.value_name("FILE")
.help("Input file for serialization"),
),
)
.subcommand(
SubCommand::with_name("deserialize")
.about("Deserializes Cranelift IR into JSON.")
.arg(
Arg::with_name("FILE")
.required(true)
.value_name("FILE")
.help("Input file for deserialization"),
),
)
.get_matches();
/// Cranelift JSON serializer/deserializer utility
#[derive(Parser, Debug)]
#[clap(about)]
enum Args {
/// Serializes Cranelift IR into JSON
Serialize {
/// Generate pretty json
#[clap(long, short)]
pretty: bool,
let res_serde = match matches.subcommand() {
("serialize", Some(m)) => {
let mut file =
File::open(m.value_of("FILE").unwrap()).expect("Unable to open the file");
/// Input file for serialization
file: String,
},
/// Deserializes Cranelift IR into JSON
Deserialize {
/// Input file for deserialization
file: String,
},
}
fn main() {
let res_serde = match Args::parse() {
Args::Serialize { pretty, file } => {
let mut contents = String::new();
let mut file = File::open(file).expect("Unable to open the file");
file.read_to_string(&mut contents)
.expect("Unable to read the file");
match m.occurrences_of("pretty") {
0 => call_ser(&contents, false),
_ => call_ser(&contents, true),
}
call_ser(&contents, pretty)
}
("deserialize", Some(m)) => {
let file = File::open(m.value_of("FILE").unwrap()).expect("Unable to open the file");
Args::Deserialize { file } => {
let file = File::open(file).expect("Unable to open the file");
call_de(&file)
}
_ => Err("Invalid subcommand.".to_string()),
};
if let Err(mut msg) = res_serde {