feat(cli): add source directory support to config loading and decryption functions

This commit is contained in:
Ray Andrew 2026-02-18 20:50:20 -06:00
parent 8808a7fc89
commit a7548dc356
Signed by: rayandrew
SSH key fingerprint: SHA256:EUCV+qCSqkap8rR+p+zGjxHfKI06G0GJKgo1DIOniQY
5 changed files with 18 additions and 16 deletions

View file

@ -436,7 +436,12 @@ pub fn run(config_path: Option<PathBuf>, dry_run: bool, prune: bool) -> anyhow::
.collect();
let mut template_vars = evaluator.get_template_variables();
super::decrypt_encrypted_vars(&result, &config, &mut template_vars)?;
super::decrypt_encrypted_vars_with_source_dir(
&result,
&config,
&mut template_vars,
Some(&source_dir),
)?;
let deployer = Deployer::new(config, result.sandbox, Some(&template_vars));
let progress = if !dry_run {

View file

@ -28,9 +28,14 @@ pub fn run(
let mut evaluator = Evaluator::new().with_source_dir(source_dir.clone());
let result = evaluator.eval_sync(&program)?;
let mut template_vars = evaluator.get_template_variables();
let config = Config::default();
let config = Config::new(source_dir.clone());
super::decrypt_encrypted_vars(&result, &config, &mut template_vars)?;
super::decrypt_encrypted_vars_with_source_dir(
&result,
&config,
&mut template_vars,
Some(&source_dir),
)?;
let state = StateStore::new(&config.state_file);
let target_path = expand_tilde(&target);

View file

@ -108,16 +108,6 @@ pub fn type_check(
Ok(())
}
/// Decrypts encrypted vars and files from `EvalResult` and inserts them into template variables
/// as `Value::Struct("encrypted", { KEY: "plaintext", ... })`.
pub fn decrypt_encrypted_vars(
result: &EvalResult,
config: &Config,
template_vars: &mut HashMap<String, Value>,
) -> anyhow::Result<()> {
decrypt_encrypted_vars_with_source_dir(result, config, template_vars, None)
}
/// Decrypts encrypted vars and files, resolving file paths relative to `source_dir`.
pub fn decrypt_encrypted_vars_with_source_dir(
result: &EvalResult,

View file

@ -122,7 +122,7 @@ impl App {
let mut evaluator = Evaluator::new().with_source_dir(source_dir.clone());
let result = evaluator.eval_sync(&program)?;
let config = Config::default();
let config = Config::new(source_dir.clone());
let state = StateStore::new(&config.state_file);
let dotfiles: Vec<DotfileItem> = result
@ -440,7 +440,7 @@ impl App {
self.apply_progress = 0;
// Apply dotfiles
let config = Config::default();
let config = Config::new(self.source_dir.clone());
let linker = Linker::new(config.clone());
let mut state = StateStore::new(&config.state_file);

View file

@ -1067,7 +1067,9 @@ impl Evaluator {
// available, so patterns like "config" / "*" expand relative to the
// config file rather than the current working directory.
let resolve_glob_base = |p: &std::path::Path| -> std::path::PathBuf {
if p.is_relative() && let Some(ref sd) = self.source_dir {
if p.is_relative()
&& let Some(ref sd) = self.source_dir
{
return sd.join(p);
}
p.to_path_buf()