@@ -71,7 +71,6 @@ struct LoadArgs {
7171
7272#[ cfg( any( target_os = "macos" , target_os = "linux" ) ) ]
7373#[ derive( Debug , Args ) ]
74- #[ command( trailing_var_arg = true ) ]
7574struct RecordArgs {
7675 /// Do not run a local server after recording.
7776 #[ arg( short, long) ]
@@ -93,12 +92,8 @@ struct RecordArgs {
9392 server_args : ServerArgs ,
9493
9594 /// Profile the execution of this command.
96- #[ arg( required = true ) ]
97- command : std:: ffi:: OsString ,
98-
99- /// The arguments passed to the recorded command.
100- #[ arg( allow_hyphen_values = true ) ]
101- command_args : Vec < std:: ffi:: OsString > ,
95+ #[ arg( required = true , allow_hyphen_values = true , trailing_var_arg = true ) ]
96+ command : Vec < std:: ffi:: OsString > ,
10297}
10398
10499#[ derive( Debug , Args ) ]
@@ -156,8 +151,8 @@ fn main() {
156151 let interval = Duration :: from_secs_f64 ( 1.0 / record_args. rate ) ;
157152 let exit_status = match profiler:: start_recording (
158153 & record_args. output ,
159- record_args. command ,
160- & record_args. command_args ,
154+ record_args. command [ 0 ] . clone ( ) ,
155+ & record_args. command [ 1 .. ] ,
161156 time_limit,
162157 interval,
163158 server_props,
@@ -209,5 +204,22 @@ fn attempt_conversion(filename: &Path, input_file: &File) -> Option<NamedTempFil
209204#[ test]
210205fn verify_cli ( ) {
211206 use clap:: CommandFactory ;
212- Opt :: command ( ) . debug_assert ( )
207+ Opt :: command ( ) . debug_assert ( ) ;
208+
209+ let opt = Opt :: parse_from ( [ "samply" , "record" , "rustup" , "show" ] ) ;
210+ assert ! (
211+ matches!( opt. action, Action :: Record ( record_args) if record_args. command == [ "rustup" , "show" ] )
212+ ) ;
213+
214+ let opt = Opt :: parse_from ( [ "samply" , "record" , "rustup" , "--no-open" ] ) ;
215+ assert ! (
216+ matches!( opt. action, Action :: Record ( record_args) if record_args. command == [ "rustup" , "--no-open" ] ) ,
217+ "Arguments of the form --arg should be considered part of the command even if they match samply options."
218+ ) ;
219+
220+ let opt = Opt :: parse_from ( [ "samply" , "record" , "--no-open" , "rustup" ] ) ;
221+ assert ! (
222+ matches!( opt. action, Action :: Record ( record_args) if record_args. command == [ "rustup" ] && record_args. server_args. no_open) ,
223+ "Arguments which come before the command name should be treated as samply arguments."
224+ ) ;
213225}
0 commit comments