@@ -28,12 +28,13 @@ use mac::profiler;
2828use server:: { start_server_main, ServerProps } ;
2929
3030#[ derive( Debug , Parser ) ]
31- #[ clap (
31+ #[ command (
3232 name = "samply" ,
3333 about = r#"
3434samply is a sampling CPU profiler.
3535Run 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
3839EXAMPLES:
3940 # Default usage:
@@ -45,7 +46,7 @@ EXAMPLES:
4546"#
4647) ]
4748struct Opt {
48- #[ clap ( subcommand) ]
49+ #[ command ( subcommand) ]
4950 action : Action ,
5051}
5152
@@ -62,62 +63,61 @@ enum Action {
6263#[ derive( Debug , Args ) ]
6364struct 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 ) ]
7575struct 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 ) ]
105105struct 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
119119fn 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