Skip to content

Commit cbb1e3f

Browse files
Update clap requirement from 3.1.0 to 4.0.8 (#137)
* Update clap requirement from 3.1.0 to 4.0.8 Updates the requirements on [clap](https://github.com/clap-rs/clap) to permit the latest version. - [Release notes](https://github.com/clap-rs/clap/releases) - [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md) - [Commits](clap-rs/clap@clap_complete-v3.1.0...v4.0.8) --- updated-dependencies: - dependency-name: clap dependency-type: direct:production ... Signed-off-by: dependabot[bot] <[email protected]> * chore: upgrade to latest version of clap Fix the code to address the API changes of clap v4 Signed-off-by: Flavio Castelli <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Flavio Castelli <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Flavio Castelli <[email protected]>
1 parent 37ff09d commit cbb1e3f

File tree

10 files changed

+119
-78
lines changed

10 files changed

+119
-78
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ ed25519-dalek-fiat = "0.1.0"
5454
anyhow = "1.0.54"
5555
assert-json-diff = "2.0.2"
5656
chrono = "0.4.20"
57-
clap = { version = "3.1.0", features = ["derive"] }
57+
clap = { version = "4.0.8", features = ["derive"] }
5858
openssl = "0.10.38"
5959
rstest = "0.15.0"
6060
tempfile = "3.3.0"

examples/cosign/verify/main.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,7 @@ struct Cli {
7676
cert_url: Option<String>,
7777

7878
/// Annotations that have to be satisfied
79-
#[clap(
80-
short,
81-
long,
82-
parse(from_str),
83-
takes_value(true),
84-
required(false),
85-
multiple_occurrences(true)
86-
)]
79+
#[clap(short, long, required(false))]
8780
annotations: Vec<String>,
8881

8982
/// Enable verbose mode

examples/rekor/create_log_entry/main.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,27 @@ async fn main() {
7070
let matches = Command::new("cmd")
7171
.arg(Arg::new("hash")
7272
.long("hash")
73-
.takes_value(true)
73+
.value_name("HASH")
7474
.help("hash of the artifact"))
7575
.arg(Arg::new("url")
7676
.long("url")
77-
.takes_value(true)
77+
.value_name("URL")
7878
.help("url containing the contents of the artifact (raw github url)"))
7979
.arg(Arg::new("public_key")
8080
.long("public_key")
81-
.takes_value(true)
81+
.value_name("PUBLIC_KEY")
8282
.help("base64 encoded public_key. Look at https://raw.githubusercontent.com/jyotsna-penumaka/rekor-rs/rekor-functionality/test_data/create_log_entry.md for more details on generating keys."))
8383
.arg(Arg::new("key_format")
8484
.long("key_format")
85-
.takes_value(true)
85+
.value_name("KEY_FORMAT")
8686
.help("Accepted formats are : pgp / x509 / minsign / ssh / tuf"))
8787
.arg(Arg::new("signature")
8888
.long("signature")
89-
.takes_value(true)
89+
.value_name("SIGNATURE")
9090
.help("base64 encoded signature of the artifact. Look at https://raw.githubusercontent.com/jyotsna-penumaka/rekor-rs/rekor-functionality/test_data/create_log_entry.md for more details on generating keys."))
9191
.arg(Arg::new("api_version")
9292
.long("api_version")
93-
.takes_value(true)
93+
.value_name("API_VERSION")
9494
.help("Rekor-rs open api version"));
9595

9696
let flags = matches.get_matches();
@@ -107,33 +107,39 @@ async fn main() {
107107

108108
let hash = Hash::new(
109109
AlgorithmKind::sha256,
110-
flags.value_of("hash").unwrap_or(HASH).to_string(),
110+
flags
111+
.get_one::<String>("hash")
112+
.unwrap_or(&HASH.to_string())
113+
.to_owned(),
111114
);
112115
let data = Data::new(
113116
hash,
114-
Url::parse(flags.value_of("url").unwrap_or(URL)).unwrap(),
117+
Url::parse(flags.get_one::<String>("url").unwrap_or(&URL.to_string())).unwrap(),
115118
);
116119
let public_key = PublicKey::new(
117120
flags
118-
.value_of("public_key")
119-
.unwrap_or(PUBLIC_KEY)
120-
.to_string(),
121+
.get_one::<String>("public_key")
122+
.unwrap_or(&PUBLIC_KEY.to_string())
123+
.to_owned(),
121124
);
122125
let signature = Signature::new(
123126
flags
124-
.value_of("key_format")
125-
.unwrap_or(KEY_FORMAT)
126-
.to_string(),
127-
flags.value_of("signature").unwrap_or(SIGNATURE).to_string(),
127+
.get_one::<String>("key_format")
128+
.unwrap_or(&KEY_FORMAT.to_string())
129+
.to_owned(),
130+
flags
131+
.get_one("signature")
132+
.unwrap_or(&SIGNATURE.to_string())
133+
.to_owned(),
128134
public_key,
129135
);
130136
let spec = Spec::new(signature, data);
131137
let proposed_entry = ProposedEntry::Hashedrekord {
132138
api_version: flags
133-
.value_of("api_version")
134-
.unwrap_or(API_VERSION)
135-
.to_string(),
136-
spec: spec,
139+
.get_one::<String>("api_version")
140+
.unwrap_or(&API_VERSION.to_string())
141+
.to_owned(),
142+
spec,
137143
};
138144

139145
let log_entry = entries_api::create_log_entry(&configuration, proposed_entry).await;

examples/rekor/get_log_entry_by_index/main.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,20 @@ async fn main() {
3131
let matches = Command::new("cmd").arg(
3232
Arg::new("log_index")
3333
.long("log_index")
34-
.takes_value(true)
34+
.value_name("LOG_INDEX")
3535
.help("log_index of the artifact"),
3636
);
3737

3838
// The following default value will be used if the user does not input values using cli flags
3939
const LOG_INDEX: &str = "1";
4040

4141
let flags = matches.get_matches();
42-
let index = i32::from_str(flags.value_of("log_index").unwrap_or(LOG_INDEX)).unwrap();
42+
let index = i32::from_str(
43+
flags
44+
.get_one::<String>("log_index")
45+
.unwrap_or(&LOG_INDEX.to_string()),
46+
)
47+
.unwrap();
4348

4449
let configuration = Configuration::default();
4550

examples/rekor/get_log_entry_by_uuid/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,18 @@ async fn main() {
3030
let matches = Command::new("cmd").arg(
3131
Arg::new("uuid")
3232
.long("uuid")
33-
.takes_value(true)
33+
.value_name("UUID")
3434
.help("uuid of the artifact"),
3535
);
3636

3737
// The following default value will be used if the user does not input values using cli flags
3838
const UUID: &str = "073970a07c978b7a9ff15b69fe15d87dfb58fd5756086e3d1fb671c2d0bd95c0";
3939

4040
let flags = matches.get_matches();
41-
let uuid = flags.value_of("uuid").unwrap_or(UUID).to_string();
41+
let uuid = flags
42+
.get_one::<String>("uuid")
43+
.unwrap_or(&UUID.to_string())
44+
.to_owned();
4245
let configuration = Configuration::default();
4346
let message: LogEntry = entries_api::get_log_entry_by_uuid(&configuration, &uuid)
4447
.await

examples/rekor/get_log_proof/main.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ async fn main() {
3333
let matches = Command::new("cmd")
3434
.arg(Arg::new("last_size")
3535
.long("last_size")
36-
.takes_value(true)
36+
.value_name("LAST_SIZE")
3737
.help("The size of the tree that you wish to prove consistency to"))
3838
.arg(Arg::new("first_size")
3939
.long("first_size")
40-
.takes_value(true)
40+
.value_name("FIRST_SIZE")
4141
.help("The size of the tree that you wish to prove consistency from (1 means the beginning of the log). Defaults to 1. To use the default value, do not input any value"))
4242
.arg(Arg::new("tree_id")
4343
.long("tree_id")
44-
.takes_value(true)
44+
.value_name("TREE_ID")
4545
.help("The tree ID of the tree that you wish to prove consistency for. To use the default value, do not input any value."));
4646

4747
let configuration = Configuration::default();
@@ -52,9 +52,14 @@ async fn main() {
5252

5353
let log_proof: ConsistencyProof = tlog_api::get_log_proof(
5454
&configuration,
55-
i32::from_str(flags.value_of("last_size").unwrap_or(LAST_SIZE)).unwrap(),
56-
flags.value_of("first_size"),
57-
flags.value_of("tree_id"),
55+
i32::from_str(
56+
flags
57+
.get_one::<String>("last_size")
58+
.unwrap_or(&LAST_SIZE.to_string()),
59+
)
60+
.unwrap(),
61+
flags.get_one::<String>("first_size").map(|s| s.as_str()),
62+
flags.get_one::<String>("tree_id").map(|s| s.as_str()),
5863
)
5964
.await
6065
.unwrap();

examples/rekor/get_public_key/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ async fn main() {
2828
let matches = Command::new("cmd")
2929
.arg(Arg::new("tree_id")
3030
.long("tree_id")
31-
.takes_value(true)
31+
.value_name("TREE_ID")
3232
.help("The tree ID of the tree that you wish to prove consistency for. To use the default value, do not input any value."));
3333

3434
let flags = matches.get_matches();
3535
let configuration = Configuration::default();
36-
let pubkey = pubkey_api::get_public_key(&configuration, flags.value_of("tree_id")).await;
36+
let pubkey = pubkey_api::get_public_key(
37+
&configuration,
38+
flags.get_one::<String>("tree_id").map(|s| s.as_str()),
39+
)
40+
.await;
3741
println!("{:#?}", pubkey.unwrap());
3842
}

examples/rekor/search_index/main.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,23 @@ async fn main() {
4545
let matches = Command::new("cmd")
4646
.arg(Arg::new("hash")
4747
.long("hash")
48-
.takes_value(true)
48+
.value_name("HASH")
4949
.help("hash of the artifact"))
5050
.arg(Arg::new("url")
5151
.long("url")
52-
.takes_value(true)
52+
.value_name("URL")
5353
.help("url containing the contents of the artifact (raw github url)"))
5454
.arg(Arg::new("public_key")
5555
.long("public_key")
56-
.takes_value(true)
56+
.value_name("PUBLIC_KEY")
5757
.help("base64 encoded public_key. Look at https://raw.githubusercontent.com/jyotsna-penumaka/rekor-rs/rekor-functionality/test_data/create_log_entry.md for more details on generating keys."))
5858
.arg(Arg::new("key_format")
5959
.long("key_format")
60-
.takes_value(true)
60+
.value_name("KEY_FORMAT")
6161
.help("Accepted formats are : pgp / x509 / minsign / ssh / tuf"))
6262
.arg(Arg::new("email")
6363
.long("email")
64-
.takes_value(true)
64+
.value_name("EMAIL")
6565
.help("Author's email"));
6666

6767
let flags = matches.get_matches();
@@ -72,7 +72,11 @@ async fn main() {
7272
const KEY_FORMAT: &str = "x509";
7373
const EMAIL: &str = "[email protected]";
7474

75-
let key_format = match flags.value_of("key_format").unwrap_or(KEY_FORMAT) {
75+
let key_format = match flags
76+
.get_one::<String>("key_format")
77+
.unwrap_or(&KEY_FORMAT.to_string())
78+
.as_str()
79+
{
7680
"pgp" => Format::Pgp,
7781
"x509" => Format::X509,
7882
"minisign" => Format::Minisign,
@@ -84,17 +88,27 @@ async fn main() {
8488
format: key_format,
8589
content: Some(
8690
flags
87-
.value_of("public_key")
88-
.unwrap_or(PUBLIC_KEY)
89-
.to_string(),
91+
.get_one::<String>("public_key")
92+
.unwrap_or(&PUBLIC_KEY.to_string())
93+
.to_owned(),
9094
),
9195
url: None,
9296
};
9397

9498
let query = SearchIndex {
95-
email: Some(flags.value_of("email").unwrap_or(EMAIL).to_string()),
99+
email: Some(
100+
flags
101+
.get_one::<String>("email")
102+
.unwrap_or(&EMAIL.to_string())
103+
.to_owned(),
104+
),
96105
public_key: Some(public_key),
97-
hash: Some(flags.value_of("hash").unwrap_or(HASH).to_string()),
106+
hash: Some(
107+
flags
108+
.get_one("hash")
109+
.unwrap_or(&HASH.to_string())
110+
.to_owned(),
111+
),
98112
};
99113
let configuration = Configuration::default();
100114

examples/rekor/search_log_query/main.rs

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,77 +53,85 @@ async fn main() {
5353
let matches = Command::new("cmd")
5454
.arg(Arg::new("hash")
5555
.long("hash")
56-
.takes_value(true)
56+
.value_name("HASH")
5757
.help("hash of the artifact"))
5858
.arg(Arg::new("url")
5959
.long("url")
60-
.takes_value(true)
60+
.value_name("URL")
6161
.help("url containing the contents of the artifact (raw github url)"))
6262
.arg(Arg::new("public_key")
6363
.long("public_key")
64-
.takes_value(true)
64+
.value_name("PUBLIC_KEY")
6565
.help("base64 encoded public_key. Look at https://raw.githubusercontent.com/jyotsna-penumaka/rekor-rs/rekor-functionality/test_data/create_log_entry.md for more details on generating keys."))
6666
.arg(Arg::new("key_format")
6767
.long("key_format")
68-
.takes_value(true)
68+
.value_name("KEY_FORMAT")
6969
.help("Accepted formats are : pgp / x509 / minsign / ssh / tuf"))
7070
.arg(Arg::new("signature")
7171
.long("signature")
72-
.takes_value(true)
72+
.value_name("SIGNATURE")
7373
.help("base64 encoded signature of the artifact. Look at https://raw.githubusercontent.com/jyotsna-penumaka/rekor-rs/rekor-functionality/test_data/create_log_entry.md for more details on generating keys."))
7474
.arg(Arg::new("api_version")
7575
.long("api_version")
76-
.takes_value(true)
76+
.value_name("API_VERSION")
7777
.help("Rekor-rs open api version"))
7878
.arg(Arg::new("entry_uuids")
7979
.long("entry_uuids")
80-
.takes_value(true)
80+
.value_name("ENTRY_UUIDS")
8181
.help("the uuids of the entries to search for"))
8282
.arg(Arg::new("log_indexes")
8383
.long("log_indexes")
84-
.takes_value(true)
84+
.value_name("LOG_INDEXES")
8585
.help("the log_indexes of the entries to search for"));
8686

8787
let flags = matches.get_matches();
8888

8989
let hash = Hash::new(
9090
AlgorithmKind::sha256,
91-
flags.value_of("hash").unwrap_or(HASH).to_string(),
91+
flags
92+
.get_one::<String>("hash")
93+
.unwrap_or(&HASH.to_string())
94+
.to_owned(),
9295
);
9396
let data = Data::new(
9497
hash,
95-
Url::parse(flags.value_of("url").unwrap_or(URL)).unwrap(),
98+
Url::parse(flags.get_one::<String>("url").unwrap_or(&URL.to_string())).unwrap(),
9699
);
97100
let public_key = PublicKey::new(
98101
flags
99-
.value_of("public_key")
100-
.unwrap_or(PUBLIC_KEY)
101-
.to_string(),
102+
.get_one::<String>("public_key")
103+
.unwrap_or(&PUBLIC_KEY.to_string())
104+
.to_owned(),
102105
);
103106
let signature = Signature::new(
104107
flags
105-
.value_of("key_format")
106-
.unwrap_or(KEY_FORMAT)
107-
.to_string(),
108-
flags.value_of("signature").unwrap_or(SIGNATURE).to_string(),
108+
.get_one::<String>("key_format")
109+
.unwrap_or(&KEY_FORMAT.to_string())
110+
.to_owned(),
111+
flags
112+
.get_one::<String>("signature")
113+
.unwrap_or(&SIGNATURE.to_string())
114+
.to_owned(),
109115
public_key,
110116
);
111117
let spec = Spec::new(signature, data);
112118
let proposed_entry = ProposedEntry::Hashedrekord {
113119
api_version: flags
114-
.value_of("api_version")
115-
.unwrap_or(API_VERSION)
116-
.to_string(),
117-
spec: spec,
120+
.get_one::<String>("api_version")
121+
.unwrap_or(&API_VERSION.to_string())
122+
.to_owned(),
123+
spec,
118124
};
119125

120126
let query = SearchLogQuery {
121127
entry_uuids: Some(vec![flags
122-
.value_of("entry_uuids")
123-
.unwrap_or(ENTRY_UUIDS)
124-
.to_string()]),
128+
.get_one::<String>("entry_uuids")
129+
.unwrap_or(&ENTRY_UUIDS.to_string())
130+
.to_owned()]),
125131
log_indexes: Some(vec![i32::from_str(
126-
flags.value_of("log_indexes").unwrap_or(LOG_INDEXES),
132+
flags
133+
.get_one::<String>("log_indexes")
134+
.unwrap_or(&LOG_INDEXES.to_string()),
127135
)
128136
.unwrap()]),
129137
entries: Some(vec![proposed_entry]),

0 commit comments

Comments
 (0)