38 lines
1.2 KiB
Rust
38 lines
1.2 KiB
Rust
|
|
//! Provider registry: selects concrete providers for core resources (e.g. FileBox).
|
||
|
|
//! This is a placeholder documenting the intended API; wiring is added later.
|
||
|
|
|
||
|
|
use std::sync::Arc;
|
||
|
|
|
||
|
|
#[allow(unused_imports)]
|
||
|
|
use crate::boxes::file::provider::FileIo;
|
||
|
|
#[allow(unused_imports)]
|
||
|
|
use crate::boxes::file::core_ro::CoreRoFileIo;
|
||
|
|
|
||
|
|
#[allow(dead_code)]
|
||
|
|
pub enum FileBoxMode { Auto, CoreRo, PluginOnly }
|
||
|
|
|
||
|
|
#[allow(dead_code)]
|
||
|
|
pub fn read_filebox_mode_from_env() -> FileBoxMode {
|
||
|
|
match std::env::var("NYASH_FILEBOX_MODE").unwrap_or_else(|_| "auto".to_string()).as_str() {
|
||
|
|
"core-ro" => FileBoxMode::CoreRo,
|
||
|
|
"plugin-only" => FileBoxMode::PluginOnly,
|
||
|
|
_ => {
|
||
|
|
if std::env::var("NYASH_DISABLE_PLUGINS").as_deref() == Ok("1") {
|
||
|
|
FileBoxMode::CoreRo
|
||
|
|
} else { FileBoxMode::Auto }
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[allow(dead_code)]
|
||
|
|
pub fn select_file_provider(mode: FileBoxMode) -> Arc<dyn FileIo> {
|
||
|
|
match mode {
|
||
|
|
FileBoxMode::CoreRo => Arc::new(CoreRoFileIo::new()),
|
||
|
|
FileBoxMode::PluginOnly | FileBoxMode::Auto => {
|
||
|
|
// TODO: if plugin present, return PluginFileIo; otherwise fallback/Fail-Fast
|
||
|
|
Arc::new(CoreRoFileIo::new())
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|