@@ -166,14 +166,28 @@ impl UpCommand {
166
166
let trigger_cmds = trigger_command_for_resolved_app_source ( & resolved_app_source)
167
167
. with_context ( || format ! ( "Couldn't find trigger executor for {app_source}" ) ) ?;
168
168
169
+ let is_multi = trigger_cmds. len ( ) > 1 ;
170
+
169
171
if self . help {
172
+ if is_multi {
173
+ // For now, only common flags are allowed on multi-trigger apps.
174
+ let mut child = self
175
+ . start_trigger ( trigger_command ( HELP_ARGS_ONLY_TRIGGER_TYPE ) , None )
176
+ . await ?;
177
+ let _ = child. wait ( ) . await ?;
178
+ return Ok ( ( ) ) ;
179
+ }
170
180
for cmd in trigger_cmds {
171
181
let mut help_process = self . start_trigger ( cmd. clone ( ) , None ) . await ?;
172
182
_ = help_process. wait ( ) . await ;
173
183
}
174
184
return Ok ( ( ) ) ;
175
185
}
176
186
187
+ if is_multi {
188
+ self . allow_only_common_flags ( ) ?;
189
+ }
190
+
177
191
let mut locked_app = self
178
192
. load_resolved_app_source ( resolved_app_source, & working_dir)
179
193
. await ?;
@@ -190,7 +204,6 @@ impl UpCommand {
190
204
} ;
191
205
192
206
let trigger_processes = self . start_trigger_processes ( trigger_cmds, run_opts) . await ?;
193
- let is_multi = trigger_processes. len ( ) > 1 ;
194
207
let pids = get_pids ( & trigger_processes) ;
195
208
196
209
set_kill_on_ctrl_c ( & pids) ?;
@@ -410,6 +423,57 @@ impl UpCommand {
410
423
}
411
424
}
412
425
}
426
+
427
+ fn allow_only_common_flags ( & self ) -> anyhow:: Result < ( ) > {
428
+ allow_only_common_flags ( & self . trigger_args )
429
+ }
430
+ }
431
+
432
+ const COMMON_FLAGS : & [ & str ] = & [
433
+ "-L" ,
434
+ "--log-dir" ,
435
+ "--disable-cache" ,
436
+ "--cache" ,
437
+ "--disable-pooling" ,
438
+ "--follow" ,
439
+ "-q" ,
440
+ "--quiet" ,
441
+ "--sh" ,
442
+ "--shush" ,
443
+ "--allow-transient-write" ,
444
+ "--runtime-config-file" ,
445
+ "--state-dir" ,
446
+ "--key-value" ,
447
+ "--sqlite" ,
448
+ "--help-args-only" ,
449
+ ] ;
450
+
451
+ fn allow_only_common_flags ( args : & [ OsString ] ) -> anyhow:: Result < ( ) > {
452
+ for i in 0 ..( args. len ( ) ) {
453
+ let Some ( value) = args[ i] . to_str ( ) else {
454
+ // Err on the side of forgiveness
455
+ continue ;
456
+ } ;
457
+ if value. starts_with ( '-' ) {
458
+ // Flag candidate. Is it allowed?
459
+ if !is_common_flag ( value) {
460
+ anyhow:: bail!( "Cannot use trigger option '{value}'. Apps with multiple trigger types do not yet support options specific to one trigger type." ) ;
461
+ }
462
+ } else if i >= 1 {
463
+ // Value candidate. Does it immediately follow a flag?
464
+ let Some ( prev) = args[ i - 1 ] . to_str ( ) else {
465
+ continue ;
466
+ } ;
467
+ if !prev. starts_with ( '-' ) {
468
+ anyhow:: bail!( "Cannot use trigger option '{value}'. Apps with multiple trigger types do not yet support options specific to one trigger type." ) ;
469
+ }
470
+ }
471
+ }
472
+ Ok ( ( ) )
473
+ }
474
+
475
+ fn is_common_flag ( candidate : & str ) -> bool {
476
+ COMMON_FLAGS . contains ( & candidate)
413
477
}
414
478
415
479
#[ cfg( windows) ]
@@ -703,4 +767,28 @@ mod test {
703
767
UpCommand :: try_parse_from ( [ "up" , "--listen" , "127.0.0.1:39453" ] )
704
768
. expect ( "Failed to parse implicit source with trigger option" ) ;
705
769
}
770
+
771
+ #[ test]
772
+ fn multi_accept_no_trigger_args ( ) {
773
+ allow_only_common_flags ( & [ ] ) . expect ( "should allow no trigger args" ) ;
774
+ }
775
+
776
+ #[ test]
777
+ fn multi_accept_only_common_args ( ) {
778
+ let args: Vec < _ > = [ "--log-dir" , "/fie" , "-q" , "--sqlite" , "SOME SQL" ]
779
+ . iter ( )
780
+ . map ( OsString :: from)
781
+ . collect ( ) ;
782
+ allow_only_common_flags ( & args) . expect ( "should allow common trigger args" ) ;
783
+ }
784
+
785
+ #[ test]
786
+ fn multi_reject_trigger_specific_args ( ) {
787
+ let args: Vec < _ > = [ "--log-dir" , "/fie" , "--listen" , "some.address" ]
788
+ . iter ( )
789
+ . map ( OsString :: from)
790
+ . collect ( ) ;
791
+ let e = allow_only_common_flags ( & args) . expect_err ( "should reject trigger-specific args" ) ;
792
+ assert ! ( e. to_string( ) . contains( "'--listen'" ) ) ;
793
+ }
706
794
}
0 commit comments