Skip to content

Commit 9479ea7

Browse files
committed
Update to clap v4.
1 parent aa6b925 commit 9479ea7

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

samply/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ framehop = "0.7"
1818
linux-perf-data = "0.7.0"
1919

2020
tokio = { version = "1.17.0", features = ["rt", "rt-multi-thread", "macros"] }
21-
clap = { version = "3.2", features = ["derive"] }
21+
clap = { version = "4", features = ["derive"] }
2222
byteorder = "1.4.3"
2323
debugid = "0.8.0"
2424
memchr = "2.4.1"

samply/src/main.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ use mac::profiler;
2828
use server::{start_server_main, ServerProps};
2929

3030
#[derive(Debug, Parser)]
31-
#[clap(
31+
#[command(
3232
name = "samply",
3333
about = r#"
3434
samply is a sampling CPU profiler.
3535
Run a command, record a CPU profile of its execution, and open the profiler UI.
36-
On non-macOS platforms, samply can only load existing profiles.
36+
Recording is currently supported on Linux and macOS.
37+
On other platforms, samply can only load existing profiles.
3738
3839
EXAMPLES:
3940
# Default usage:
@@ -45,7 +46,7 @@ EXAMPLES:
4546
"#
4647
)]
4748
struct Opt {
48-
#[clap(subcommand)]
49+
#[command(subcommand)]
4950
action: Action,
5051
}
5152

@@ -62,62 +63,61 @@ enum Action {
6263
#[derive(Debug, Args)]
6364
struct LoadArgs {
6465
/// Path to the file that should be loaded.
65-
#[clap(parse(from_os_str))]
6666
file: PathBuf,
6767

68-
#[clap(flatten)]
68+
#[command(flatten)]
6969
server_args: ServerArgs,
7070
}
7171

7272
#[cfg(any(target_os = "macos", target_os = "linux"))]
7373
#[derive(Debug, Args)]
74-
#[clap(trailing_var_arg = true)]
74+
#[command(trailing_var_arg = true)]
7575
struct RecordArgs {
7676
/// Do not run a local server after recording.
77-
#[clap(short, long)]
77+
#[arg(short, long)]
7878
save_only: bool,
7979

8080
/// Sampling rate, in Hz
81-
#[clap(short, long, default_value = "1000")]
81+
#[arg(short, long, default_value = "1000")]
8282
rate: f64,
8383

8484
/// Limit the recorded time to the specified number of seconds
85-
#[clap(short, long)]
85+
#[arg(short, long)]
8686
duration: Option<f64>,
8787

8888
/// Output filename.
89-
#[clap(short, long, default_value = "profile.json", parse(from_os_str))]
89+
#[arg(short, long, default_value = "profile.json")]
9090
output: PathBuf,
9191

92-
#[clap(flatten)]
92+
#[command(flatten)]
9393
server_args: ServerArgs,
9494

9595
/// Profile the execution of this command.
96-
#[clap(required = true)]
96+
#[arg(required = true)]
9797
command: std::ffi::OsString,
9898

9999
/// The arguments passed to the recorded command.
100-
#[clap(multiple_values = true, allow_hyphen_values = true)]
100+
#[arg(allow_hyphen_values = true)]
101101
command_args: Vec<std::ffi::OsString>,
102102
}
103103

104104
#[derive(Debug, Args)]
105105
struct ServerArgs {
106106
/// Do not open the profiler UI.
107-
#[clap(short, long)]
107+
#[arg(short, long)]
108108
no_open: bool,
109109

110110
/// The port to use for the local web server
111-
#[clap(short, long, default_value = "3000+")]
111+
#[arg(short, long, default_value = "3000+")]
112112
port: String,
113113

114114
/// Print debugging output.
115-
#[clap(short, long)]
115+
#[arg(short, long)]
116116
verbose: bool,
117117
}
118118

119119
fn main() {
120-
let opt = Opt::from_args();
120+
let opt = Opt::parse();
121121
match opt.action {
122122
Action::Load(load_args) => {
123123
let input_file = match File::open(&load_args.file) {
@@ -205,3 +205,9 @@ fn attempt_conversion(filename: &Path, input_file: &File) -> Option<NamedTempFil
205205
serde_json::to_writer(writer, &profile).ok()?;
206206
Some(output_file)
207207
}
208+
209+
#[test]
210+
fn verify_cli() {
211+
use clap::CommandFactory;
212+
Opt::command().debug_assert()
213+
}

0 commit comments

Comments
 (0)