@@ -155,6 +155,7 @@ impl<T: Trigger> FactorsTriggerCommand<T> {
155155 // Required env vars
156156 let working_dir = std:: env:: var ( SPIN_WORKING_DIR ) . context ( SPIN_WORKING_DIR ) ?;
157157 let locked_url = std:: env:: var ( SPIN_LOCKED_URL ) . context ( SPIN_LOCKED_URL ) ?;
158+ let local_app_dir = std:: env:: var ( SPIN_LOCAL_APP_DIR ) . ok ( ) ;
158159
159160 let follow_components = self . follow_components ( ) ;
160161
@@ -192,6 +193,7 @@ impl<T: Trigger> FactorsTriggerCommand<T> {
192193 TriggerAppOptions {
193194 runtime_config_file : self . runtime_config_file . as_deref ( ) ,
194195 state_dir : self . state_dir . as_deref ( ) ,
196+ local_app_dir : local_app_dir. as_deref ( ) ,
195197 initial_key_values : self . key_values ,
196198 allow_transient_write : self . allow_transient_write ,
197199 follow_components,
@@ -268,6 +270,8 @@ pub struct TriggerAppOptions<'a> {
268270 runtime_config_file : Option < & ' a Path > ,
269271 /// Path to the state directory.
270272 state_dir : Option < & ' a str > ,
273+ /// Path to the local app directory.
274+ local_app_dir : Option < & ' a str > ,
271275 /// Initial key/value pairs to set in the app's default store.
272276 initial_key_values : Vec < ( String , String ) > ,
273277 /// Whether to allow transient writes to mounted files
@@ -306,12 +310,17 @@ impl<T: Trigger> TriggerAppBuilder<T> {
306310
307311 // Hardcode `use_gpu` to true for now
308312 let use_gpu = true ;
309- // Make sure `--state-dir=""` unsets the state dir
310- let state_dir = options. state_dir . filter ( |s| !s. is_empty ( ) ) . map ( Path :: new) ;
313+ let state_dir = match options. state_dir {
314+ // Make sure `--state-dir=""` unsets the state dir
315+ Some ( s) if s. is_empty ( ) => None ,
316+ Some ( s) => Some ( PathBuf :: from ( s) ) ,
317+ // Default to `.spin/` in the local app dir
318+ None => options. local_app_dir . map ( |d| Path :: new ( d) . join ( ".spin" ) ) ,
319+ } ;
311320 let runtime_config =
312321 ResolvedRuntimeConfig :: < TriggerFactorsRuntimeConfig > :: from_optional_file (
313322 options. runtime_config_file ,
314- state_dir,
323+ state_dir. as_deref ( ) ,
315324 use_gpu,
316325 ) ?;
317326
0 commit comments