Skip to content

Commit 0fdfa46

Browse files
committed
Update Clap to 4.4
This commit updates Clap from 3.2 to 4.4. This change is needed because old Clap has a dependency on crate `atty` which is unmaintained: https://rustsec.org/advisories/RUSTSEC-2024-0375 This commit updates the dependency version and the code. Signed-off-by: Mark Kirichenko <[email protected]>
1 parent b715e45 commit 0fdfa46

File tree

13 files changed

+314
-430
lines changed

13 files changed

+314
-430
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ rust-version = "1.71"
99
[dependencies]
1010
serde = { version = ">=1.0", features = ["derive"] }
1111
chrono = "0.4"
12-
clap = "3.2"
12+
clap = "~4.4"
1313
inotify = "0.10"
1414
serde_json = "1.0"
1515
nix = "0.26"

enclave_build/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ rust-version = "1.71"
99

1010
[dependencies]
1111
bollard = "0.16.0"
12-
clap = "3.2"
12+
clap = "~4.4"
1313
serde = { version = "1.0", features = ["derive"] }
1414
serde_yaml = "0.8"
1515
serde_json = "1.0"

enclave_build/src/main.rs

Lines changed: 40 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,127 @@
11
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use clap::{App, AppSettings, Arg};
4+
use clap::{Arg, ArgAction, Command};
55
use std::fs::OpenOptions;
66

77
use aws_nitro_enclaves_image_format::generate_build_info;
88
use enclave_build::Docker2Eif;
99

1010
fn main() {
11-
let matches = App::new("Docker2Eif builder")
11+
let matches = Command::new("Docker2Eif builder")
1212
.about("Generate consistent EIF image from a Docker image")
13-
.setting(AppSettings::DisableVersion)
1413
.arg(
15-
Arg::with_name("docker_image")
14+
Arg::new("docker_image")
1615
.short('t')
1716
.long("tag")
1817
.help("Docker image tag")
19-
.takes_value(true)
2018
.required(true),
2119
)
2220
.arg(
23-
Arg::with_name("init_path")
21+
Arg::new("init_path")
2422
.short('i')
2523
.long("init")
2624
.help("Path to a binary representing the init process for the enclave")
27-
.takes_value(true)
2825
.required(true),
2926
)
3027
.arg(
31-
Arg::with_name("nsm_path")
28+
Arg::new("nsm_path")
3229
.short('n')
3330
.long("nsm")
3431
.help("Path to the NitroSecureModule Kernel Driver")
35-
.takes_value(true)
3632
.required(true),
3733
)
3834
.arg(
39-
Arg::with_name("kernel_img_path")
35+
Arg::new("kernel_img_path")
4036
.short('k')
4137
.long("kernel")
4238
.help("Path to a bzImage/Image file for x86_64/aarch64 linux kernel")
43-
.takes_value(true)
4439
.required(true),
4540
)
4641
.arg(
47-
Arg::with_name("kernel_cfg_path")
42+
Arg::new("kernel_cfg_path")
4843
.long("kernel_config")
4944
.help("Path to a bzImage.config/Image.config file for x86_64/aarch64 linux kernel config")
50-
.takes_value(true)
5145
.required(true),
5246
)
5347
.arg(
54-
Arg::with_name("cmdline")
48+
Arg::new("cmdline")
5549
.short('c')
5650
.long("cmdline")
5751
.help("Cmdline for kernel")
58-
.takes_value(true)
5952
.required(true),
6053
)
6154
.arg(
62-
Arg::with_name("linuxkit_path")
55+
Arg::new("linuxkit_path")
6356
.short('l')
6457
.long("linuxkit")
6558
.help("Linuxkit executable path")
66-
.takes_value(true)
6759
.required(true),
6860
)
6961
.arg(
70-
Arg::with_name("output")
62+
Arg::new("output")
7163
.short('o')
7264
.long("output")
7365
.help("Output file for EIF image")
74-
.takes_value(true)
7566
.required(true),
7667
)
7768
.arg(
78-
Arg::with_name("signing-certificate")
69+
Arg::new("signing-certificate")
7970
.long("signing-certificate")
80-
.help("Specify the path to the signing certificate")
81-
.takes_value(true),
71+
.help("Specify the path to the signing certificate"),
8272
)
8373
.arg(
84-
Arg::with_name("private-key")
74+
Arg::new("private-key")
8575
.long("private-key")
86-
.help("Specify the path to the private-key")
87-
.takes_value(true),
76+
.help("Specify the path to the private-key"),
8877
)
8978
.arg(
90-
Arg::with_name("build")
79+
Arg::new("build")
9180
.short('b')
9281
.long("build")
9382
.help("Build image from Dockerfile")
94-
.takes_value(true)
95-
.required(false),
83+
.conflicts_with("pull"),
9684
)
9785
.arg(
98-
Arg::with_name("pull")
86+
Arg::new("pull")
9987
.short('p')
10088
.long("pull")
10189
.help("Pull the Docker image before generating EIF")
102-
.required(false)
90+
.action(ArgAction::SetTrue)
10391
.conflicts_with("build"),
10492
)
10593
.arg(
106-
Arg::with_name("image_name")
94+
Arg::new("image_name")
10795
.long("name")
108-
.help("Name for enclave image")
109-
.takes_value(true),
96+
.help("Name for enclave image"),
11097
)
11198
.arg(
112-
Arg::with_name("image_version")
99+
Arg::new("image_version")
113100
.long("version")
114-
.help("Version of the enclave image")
115-
.takes_value(true),
101+
.help("Version of the enclave image"),
116102
)
117103
.arg(
118-
Arg::with_name("metadata")
104+
Arg::new("metadata")
119105
.long("metadata")
120-
.help("Path to JSON containing the custom metadata provided by the user.")
121-
.takes_value(true),
106+
.help("Path to JSON containing the custom metadata provided by the user"),
122107
)
123108
.get_matches();
124109

125-
let docker_image = matches.value_of("docker_image").unwrap();
126-
let init_path = matches.value_of("init_path").unwrap();
127-
let nsm_path = matches.value_of("nsm_path").unwrap();
128-
let kernel_img_path = matches.value_of("kernel_img_path").unwrap();
129-
let kernel_cfg_path = matches.value_of("kernel_cfg_path").unwrap();
130-
let cmdline = matches.value_of("cmdline").unwrap();
131-
let linuxkit_path = matches.value_of("linuxkit_path").unwrap();
132-
let output = matches.value_of("output").unwrap();
110+
let docker_image = matches.get_one::<String>("docker_image").unwrap();
111+
let init_path = matches.get_one::<String>("init_path").unwrap();
112+
let nsm_path = matches.get_one::<String>("nsm_path").unwrap();
113+
let kernel_img_path = matches.get_one::<String>("kernel_img_path").unwrap();
114+
let kernel_cfg_path = matches.get_one::<String>("kernel_cfg_path").unwrap();
115+
let cmdline = matches.get_one::<String>("cmdline").unwrap();
116+
let linuxkit_path = matches.get_one::<String>("linuxkit_path").unwrap();
117+
let output = matches.get_one::<String>("output").unwrap();
133118
let signing_certificate = matches
134-
.value_of("signing_certificate")
135-
.map(|val| val.to_string());
136-
let private_key = matches
137-
.value_of("private_certificate")
138-
.map(|val| val.to_string());
139-
let img_name = matches.value_of("image_name").map(|val| val.to_string());
140-
let img_version = matches.value_of("image_version").map(|val| val.to_string());
141-
let metadata = matches.value_of("metadata").map(|val| val.to_string());
119+
.get_one::<String>("signing-certificate")
120+
.map(String::from);
121+
let private_key = matches.get_one::<String>("private-key").map(String::from);
122+
let img_name = matches.get_one::<String>("image_name").map(String::from);
123+
let img_version = matches.get_one::<String>("image_version").map(String::from);
124+
let metadata = matches.get_one::<String>("metadata").map(String::from);
142125

143126
let mut output = OpenOptions::new()
144127
.read(true)
@@ -166,10 +149,9 @@ fn main() {
166149
)
167150
.unwrap();
168151

169-
if matches.is_present("build") {
170-
let dockerfile_dir = matches.value_of("build").unwrap();
152+
if let Some(dockerfile_dir) = matches.get_one::<String>("build") {
171153
img.build_docker_image(dockerfile_dir.to_string()).unwrap();
172-
} else if matches.is_present("pull") {
154+
} else if matches.get_flag("pull") {
173155
img.pull_docker_image().unwrap();
174156
}
175157

samples/command_executer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ rust-version = "1.71"
88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

1010
[dependencies]
11-
clap = "3.2"
11+
clap = "~4.4"
1212
log = "0.4"
1313
nix = "0.26"
1414
serde = { version = ">=1.0", features = ["derive"] }

samples/command_executer/src/command_parser.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,40 +80,37 @@ impl CommandOutput {
8080
}
8181

8282
fn parse_cid(args: &ArgMatches) -> Result<u32, String> {
83-
let port = args.value_of("cid").ok_or("Could not find cid argument")?;
84-
port.parse()
83+
args.get_one::<String>("cid")
84+
.ok_or("Could not find cid argument")?
85+
.parse()
8586
.map_err(|_err| "cid is not a number".to_string())
8687
}
8788

8889
fn parse_port(args: &ArgMatches) -> Result<u32, String> {
89-
let port = args
90-
.value_of("port")
91-
.ok_or("Could not find port argument")?;
92-
port.parse()
90+
args.get_one::<String>("port")
91+
.ok_or("Could not find port argument")?
92+
.parse()
9393
.map_err(|_err| "port is not a number".to_string())
9494
}
9595

9696
fn parse_command(args: &ArgMatches) -> Result<String, String> {
97-
let command = args
98-
.value_of("command")
99-
.ok_or("Could not find command argument")?;
100-
Ok(String::from(command))
97+
args.get_one::<String>("command")
98+
.map(String::from)
99+
.ok_or_else(|| "Could not find command argument".to_string())
101100
}
102101

103102
fn parse_no_wait(args: &ArgMatches) -> bool {
104-
args.is_present("no-wait")
103+
args.get_flag("no-wait")
105104
}
106105

107106
fn parse_localfile(args: &ArgMatches) -> Result<String, String> {
108-
let output = args
109-
.value_of("localpath")
110-
.ok_or("Could not find localpath")?;
111-
Ok(String::from(output))
107+
args.get_one::<String>("localpath")
108+
.map(String::from)
109+
.ok_or_else(|| "Could not find localpath".to_string())
112110
}
113111

114112
fn parse_remotefile(args: &ArgMatches) -> Result<String, String> {
115-
let output = args
116-
.value_of("remotepath")
117-
.ok_or("Could not find remotepath")?;
118-
Ok(String::from(output))
113+
args.get_one::<String>("remotepath")
114+
.map(String::from)
115+
.ok_or_else(|| "Could not find remotepath".to_string())
119116
}

samples/command_executer/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clap::{App, AppSettings, Arg, SubCommand};
1+
use clap::{Arg, ArgAction, Command};
22

33
use command_executer::command_parser::{FileArgs, ListenArgs, RunArgs};
44
use command_executer::create_app;

0 commit comments

Comments
 (0)