Skip to content

Commit

Permalink
Update to clap v4 (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamspofford-dfinity committed Sep 15, 2023
1 parent b82c944 commit 7a67191
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 93 deletions.
155 changes: 80 additions & 75 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ic-transport-types = { path = "ic-transport-types", version = "0.27.0" }

ic-certification = "0.27.0"
candid = "0.9.5"
clap = "4.4.3"
hex = "0.4.3"
leb128 = "0.2.5"
ring = "0.16.20"
Expand Down
2 changes: 1 addition & 1 deletion icx-cert/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ include = ["src", "Cargo.toml", "../LICENSE", "README.md"]
[dependencies]
anyhow = "1.0"
base64 = "0.13"
clap = { version = "3.1.8", features = ["derive", "cargo"] }
clap = { workspace = true, features = ["derive", "cargo", "color"] }
hex = { workspace = true }
ic-certification = { workspace = true }
leb128 = "0.2.4"
Expand Down
20 changes: 13 additions & 7 deletions icx-cert/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clap::{crate_authors, crate_version, Parser};
mod pprint;

#[derive(Parser)]
#[clap(
#[command(
version = crate_version!(),
author = crate_authors!(),
)]
Expand All @@ -15,12 +15,7 @@ enum Command {
url: String,

/// Specifies one or more encodings to accept.
#[clap(
long,
multiple_occurrences(true),
multiple_values(true),
number_of_values(1)
)]
#[arg(long)]
accept_encoding: Option<Vec<String>>,
},
}
Expand All @@ -33,3 +28,14 @@ fn main() -> Result<()> {
} => pprint::pprint(url, accept_encoding),
}
}

#[cfg(test)]
mod tests {
use super::Command;
use clap::CommandFactory;

#[test]
fn valid_command() {
Command::command().debug_assert();
}
}
2 changes: 1 addition & 1 deletion icx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ path = "src/main.rs"
[dependencies]
anyhow = { version = "1.0", features = ["backtrace"] }
candid = { workspace = true, features = ["parser"] }
clap = { version = "3.0.14", features = ["derive", "cargo"] }
clap = { workspace = true, features = ["derive", "cargo", "color"] }
hex = { workspace = true }
humantime = "2.0.1"
ic-agent = { workspace = true, default-features = true }
Expand Down
26 changes: 17 additions & 9 deletions icx/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use candid::{
types::{Function, Type, TypeInner},
CandidType, Decode, Deserialize, IDLArgs, IDLProg, TypeEnv,
};
use clap::{crate_authors, crate_version, Parser};
use clap::{crate_authors, crate_version, Parser, ValueEnum};
use ic_agent::{
agent::{self, signed::SignedUpdate},
agent::{
Expand Down Expand Up @@ -75,35 +75,32 @@ enum SubCommand {
#[derive(Parser)]
struct CallOpts {
/// The Canister ID to call.
#[clap(parse(try_from_str), required = true)]
canister_id: Principal,

/// Output the serialization of a message to STDOUT.
#[clap(long)]
#[arg(long)]
serialize: bool,

/// Path to a candid file to analyze the argument. Otherwise candid will parse the
/// argument without type hint.
#[clap(long)]
#[arg(long)]
candid: Option<PathBuf>,

#[clap(required = true)]
method_name: String,

/// The type of output (hex or IDL).
#[clap(long, default_value = "idl")]
#[arg(long, value_enum, default_value_t = ArgType::Idl)]
arg: ArgType,

/// The type of output (hex or IDL).
#[clap(long, default_value = "idl")]
#[arg(long, value_enum, default_value_t = ArgType::Idl)]
output: ArgType,

/// Argument to send, in Candid textual format.
#[clap()]
arg_value: Option<String>,
}

#[derive(Parser)]
#[derive(ValueEnum, Clone)]
enum ArgType {
Idl,
Raw,
Expand Down Expand Up @@ -583,3 +580,14 @@ async fn main() -> Result<()> {

Ok(())
}

#[cfg(test)]
mod tests {
use crate::Opts;
use clap::CommandFactory;

#[test]
fn valid_command() {
Opts::command().debug_assert();
}
}

0 comments on commit 7a67191

Please sign in to comment.