feat: add local profiles inspection before global
build / version (push) Successful in 9s
build / build (aarch64-apple-darwin) (push) Successful in 3m57s
build / build (x86_64-unknown-linux-musl) (push) Successful in 3m35s
build / release (push) Successful in 20s

This commit is contained in:
johannes committed 2026-11-15 22:05:56 +01:00
1 parent ef53278466
commit 8539e0308d
1 file changed
+13 -8
+13 -8
View File
@@ -1,9 +1,19 @@
//! Profile: `<config>/profiles/NAME.toml`. One profile = one identity (own HOME/auth), budget and gate.
//! Profile: `./.hx/profiles/NAME.toml` (repo-local, checked first), else `<config>/profiles/NAME.toml`. One profile = one identity (own HOME/auth), budget and gate.
use anyhow::{Context, Result, bail};
use serde::Deserialize;
use std::path::PathBuf;
/// `./.hx/profiles/NAME.toml` when it exists (repo-local wins), else `<config>/profiles/NAME.toml`.
fn profile_path(name: &str) -> PathBuf {
let file = format!("{name}.toml");
let local = PathBuf::from(".hx/profiles").join(&file);
if local.is_file() {
return local;
}
crate::config_dir().join("profiles").join(file)
}
/// [`Profile::add_allow`] on a file.
fn add_allow_at(path: &std::path::Path, entry: &str) -> Result<bool> {
crate::policy::check_entry(entry)?;
@@ -172,9 +182,7 @@ impl Profile {
if name.is_empty() || name.contains(['/', '.']) {
bail!("bad profile name {name:?}");
}
let path = crate::config_dir()
.join("profiles")
.join(format!("{name}.toml"));
let path = profile_path(name);
let s = match std::fs::read_to_string(&path) {
// only the implicit profile may be missing; a typo in any other name must still fail
Err(e) if name == "default" && e.kind() == std::io::ErrorKind::NotFound => {
@@ -192,10 +200,7 @@ impl Profile {
if name.is_empty() || name.contains(['/', '.']) {
bail!("bad profile name {name:?}");
}
let path = crate::config_dir()
.join("profiles")
.join(format!("{name}.toml"));
add_allow_at(&path, entry)
add_allow_at(&profile_path(name), entry)
}
pub fn account<'a>(&'a self, profile: &'a str) -> &'a str {