Add --stack-path CLI option for custom stack path

Allows overriding the default botserver-stack location via:
- --stack-path /path/to/stack CLI argument
- BOTSERVER_STACK_PATH environment variable

Useful for testing botserver bootstrap in isolated temp directories.
This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2025-12-06 14:55:42 -03:00
parent 67c971557e
commit 41f5847f56
2 changed files with 30 additions and 0 deletions

View file

@ -20,6 +20,8 @@ impl PackageManager {
let os_type = detect_os();
let base_path = if mode == InstallMode::Container {
PathBuf::from("/opt/gbo")
} else if let Ok(custom_path) = std::env::var("BOTSERVER_STACK_PATH") {
PathBuf::from(custom_path)
} else {
std::env::current_dir()?.join("botserver-stack")
};
@ -36,6 +38,26 @@ impl PackageManager {
Ok(pm)
}
/// Create a PackageManager with a custom base path (for testing)
pub fn with_base_path(
mode: InstallMode,
tenant: Option<String>,
base_path: PathBuf,
) -> Result<Self> {
let os_type = detect_os();
let tenant = tenant.unwrap_or_else(|| "default".to_string());
let mut pm = PackageManager {
mode,
os_type,
base_path,
tenant,
components: HashMap::new(),
};
pm.register_components();
Ok(pm)
}
fn register_components(&mut self) {
self.register_tables();
self.register_cache();

View file

@ -386,6 +386,14 @@ async fn main() -> std::io::Result<()> {
None
};
// Set custom stack path if provided (for testing)
if let Some(idx) = args.iter().position(|a| a == "--stack-path") {
if let Some(path) = args.get(idx + 1) {
std::env::set_var("BOTSERVER_STACK_PATH", path);
info!("Using custom stack path: {}", path);
}
}
// Bootstrap
trace!("Starting bootstrap process...");
let progress_tx_clone = progress_tx.clone();