Configurable search paths (#5356)
This commit is contained in:
@@ -136,6 +136,16 @@ impl Default for Config {
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! declare_param {
|
||||
($param_name:ident, $param_type:ty) => {
|
||||
paste::paste! {
|
||||
pub fn [<get_ $param_name:lower>](&self) -> Result<$param_type, ConfigError> {
|
||||
self.get_param(stringify!($param_name))
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl Config {
|
||||
/// Get the global configuration instance.
|
||||
///
|
||||
@@ -730,6 +740,8 @@ impl Config {
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
declare_param!(GOOSE_SEARCH_PATHS, Vec<String>);
|
||||
}
|
||||
|
||||
/// Load init-config.yaml from workspace root if it exists.
|
||||
|
||||
@@ -4,6 +4,7 @@ mod experiments;
|
||||
pub mod extensions;
|
||||
pub mod paths;
|
||||
pub mod permission;
|
||||
pub mod search_path;
|
||||
pub mod signup_openrouter;
|
||||
pub mod signup_tetrate;
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
use std::{env, ffi::OsString, path::PathBuf};
|
||||
|
||||
use crate::config::{Config, ConfigError};
|
||||
|
||||
pub fn search_path_var() -> Result<OsString, ConfigError> {
|
||||
let paths = Config::global()
|
||||
.get_goose_search_paths()
|
||||
.or_else(|err| match err {
|
||||
ConfigError::NotFound(_) => Ok(vec![]),
|
||||
err => Err(err),
|
||||
})?
|
||||
.into_iter()
|
||||
.map(|s| PathBuf::from(shellexpand::tilde(&s).as_ref()));
|
||||
|
||||
env::join_paths(
|
||||
paths.chain(
|
||||
env::var_os("PATH")
|
||||
.as_ref()
|
||||
.map(env::split_paths)
|
||||
.into_iter()
|
||||
.flatten(),
|
||||
),
|
||||
)
|
||||
.map_err(|e| ConfigError::DeserializeError(format!("{}", e)))
|
||||
}
|
||||
Reference in New Issue
Block a user