Skip to content

Commit 98027a2

Browse files
committed
Move where user defined paths are defined
Signed-off-by: Ryan Levick <[email protected]>
1 parent cc81c12 commit 98027a2

File tree

7 files changed

+39
-40
lines changed

7 files changed

+39
-40
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/runtime-config/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ spin-factor-variables = { path = "../factor-variables" }
2626
spin-factor-wasi = { path = "../factor-wasi" }
2727
spin-factors = { path = "../factors" }
2828
spin-sqlite = { path = "../sqlite" }
29+
spin-trigger = { path = "../trigger" }
2930
toml = "0.8"
3031

3132
[lints]

crates/runtime-config/src/lib.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use spin_factors::{
2020
};
2121
use spin_key_value_spin::{SpinKeyValueRuntimeConfig, SpinKeyValueStore};
2222
use spin_sqlite as sqlite;
23+
use spin_trigger::cli::UserProvidedPath;
2324

2425
/// The default state directory for the trigger.
2526
pub const DEFAULT_STATE_DIR: &str = ".spin";
@@ -453,13 +454,10 @@ fn sqlite_config_resolver(
453454
))
454455
}
455456

456-
/// A user provided option which be either be provided, default, or explicitly none.
457-
#[derive(Clone, Debug)]
458-
pub enum UserProvidedPath {
459-
/// Use the explicitly provided directory.
460-
Provided(PathBuf),
461-
/// Use the default.
462-
Default,
463-
/// Explicitly unset.
464-
Unset,
457+
impl TryFrom<TomlRuntimeConfigSource<'_, '_>> for spin_trigger::TriggerFactorsRuntimeConfig {
458+
type Error = anyhow::Error;
459+
460+
fn try_from(value: TomlRuntimeConfigSource<'_, '_>) -> Result<Self, Self::Error> {
461+
Self::from_source(value)
462+
}
465463
}

crates/trigger/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ spin-factor-variables = { path = "../factor-variables" }
3939
spin-factor-wasi = { path = "../factor-wasi" }
4040
spin-factors = { path = "../factors" }
4141
spin-factors-executor = { path = "../factors-executor" }
42-
spin-runtime-config = { path = "../runtime-config" }
4342
spin-telemetry = { path = "../telemetry" }
4443
terminal = { path = "../terminal" }
4544
tokio = { version = "1.23", features = ["fs", "rt"] }

crates/trigger/src/cli.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use spin_common::url::parse_file_url;
1414
use spin_core::async_trait;
1515
use spin_factors::RuntimeFactors;
1616
use spin_factors_executor::{ComponentLoader, FactorsExecutor};
17-
use spin_runtime_config::{ResolvedRuntimeConfig, UserProvidedPath};
1817
use sqlite_statements::SqlStatementExecutorHook;
1918
use summary::{
2019
summarize_runtime_config, KeyValueDefaultStoreSummaryHook, SqliteDefaultStoreSummaryHook,
@@ -134,15 +133,15 @@ pub struct CommonTriggerOptions {
134133
/// Path to the runtime config file.
135134
pub runtime_config_file: Option<PathBuf>,
136135
/// Path to the state directory.
137-
pub state_dir: Option<String>,
136+
pub state_dir: UserProvidedPath,
138137
/// Path to the local app directory.
139138
pub local_app_dir: Option<String>,
140139
/// Whether to allow transient writes to mounted files
141140
pub allow_transient_write: bool,
142141
/// Which components should have their logs followed.
143142
pub follow_components: FollowComponents,
144143
/// Log directory for component stdout/stderr.
145-
pub log_dir: Option<PathBuf>,
144+
pub log_dir: UserProvidedPath,
146145
}
147146

148147
/// An empty implementation of clap::Args to be used as TriggerExecutor::RunConfig
@@ -205,14 +204,26 @@ impl<T: Trigger<B::Factors>, B: RuntimeFactorsBuilder> FactorsTriggerCommand<T,
205204
config.disable_pooling();
206205
}
207206

207+
let state_dir = match &self.state_dir {
208+
// Make sure `--state-dir=""` unsets the state dir
209+
Some(s) if s.is_empty() => UserProvidedPath::Unset,
210+
Some(s) => UserProvidedPath::Provided(PathBuf::from(s)),
211+
None => UserProvidedPath::Default,
212+
};
213+
let log_dir = match &self.log {
214+
// Make sure `--log-dir=""` unsets the log dir
215+
Some(p) if p.as_os_str().is_empty() => UserProvidedPath::Unset,
216+
Some(p) => UserProvidedPath::Provided(p.clone()),
217+
None => UserProvidedPath::Default,
218+
};
208219
let common_options = CommonTriggerOptions {
209220
working_dir: PathBuf::from(working_dir),
210221
runtime_config_file: self.runtime_config_file.clone(),
211-
state_dir: self.state_dir.clone(),
222+
state_dir,
212223
local_app_dir: local_app_dir.clone(),
213224
allow_transient_write: self.allow_transient_write,
214225
follow_components,
215-
log_dir: self.log,
226+
log_dir,
216227
};
217228
let run_fut = builder.run(app, common_options, self.builder_args).await?;
218229

@@ -431,3 +442,14 @@ pub mod help {
431442
}
432443
}
433444
}
445+
446+
/// A user provided option which be either be provided, default, or explicitly none.
447+
#[derive(Clone, Debug)]
448+
pub enum UserProvidedPath {
449+
/// Use the explicitly provided directory.
450+
Provided(PathBuf),
451+
/// Use the default.
452+
Default,
453+
/// Explicitly unset.
454+
Unset,
455+
}

crates/trigger/src/factors.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use spin_factor_sqlite::SqliteFactor;
1414
use spin_factor_variables::VariablesFactor;
1515
use spin_factor_wasi::{spin::SpinFilesMounter, WasiFactor};
1616
use spin_factors::RuntimeFactors;
17-
use spin_runtime_config::TomlRuntimeConfigSource;
1817

1918
#[derive(RuntimeFactors)]
2019
pub struct TriggerFactors {
@@ -82,14 +81,6 @@ fn outbound_networking_factor() -> OutboundNetworkingFactor {
8281
factor
8382
}
8483

85-
impl TryFrom<TomlRuntimeConfigSource<'_, '_>> for TriggerFactorsRuntimeConfig {
86-
type Error = anyhow::Error;
87-
88-
fn try_from(value: TomlRuntimeConfigSource<'_, '_>) -> Result<Self, Self::Error> {
89-
Self::from_source(value)
90-
}
91-
}
92-
9384
/// Options for building a [`TriggerFactors`].
9485
#[derive(Default, clap::Args)]
9586
pub struct TriggerAppOptions {

src/bin/spin.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use spin_cli::commands::{
1717
watch::WatchCommand,
1818
};
1919
use spin_cli::{build_info::*, subprocess::ExitStatusError};
20-
use spin_runtime_config::{ResolvedRuntimeConfig, UserProvidedPath};
20+
use spin_runtime_config::ResolvedRuntimeConfig;
2121
use spin_trigger::cli::help::HelpArgsOnlyTrigger;
2222
use spin_trigger::cli::{CommonTriggerOptions, FactorsTriggerCommand, RuntimeFactorsBuilder};
2323
use spin_trigger::{TriggerAppOptions, TriggerFactors, TriggerFactorsRuntimeConfig};
@@ -187,26 +187,14 @@ impl RuntimeFactorsBuilder for Builder {
187187
)> {
188188
let runtime_config_path = common_options.runtime_config_file;
189189
let local_app_dir = common_options.local_app_dir.map(PathBuf::from);
190-
let state_dir = match common_options.state_dir {
191-
// Make sure `--state-dir=""` unsets the state dir
192-
Some(s) if s.is_empty() => UserProvidedPath::Unset,
193-
Some(s) => UserProvidedPath::Provided(PathBuf::from(s)),
194-
None => UserProvidedPath::Default,
195-
};
196-
let log_dir = match &common_options.log_dir {
197-
// Make sure `--log-dir=""` unsets the log dir
198-
Some(p) if p.as_os_str().is_empty() => UserProvidedPath::Unset,
199-
Some(p) => UserProvidedPath::Provided(p.clone()),
200-
None => UserProvidedPath::Default,
201-
};
202190
// Hardcode `use_gpu` to true for now
203191
let use_gpu = true;
204192
let runtime_config =
205193
ResolvedRuntimeConfig::<TriggerFactorsRuntimeConfig>::from_optional_file(
206194
runtime_config_path.as_deref(),
207195
local_app_dir,
208-
state_dir,
209-
log_dir,
196+
common_options.state_dir,
197+
common_options.log_dir,
210198
use_gpu,
211199
)?;
212200

0 commit comments

Comments
 (0)