2 Commits
Author SHA1 Message Date
johannes 8539e0308d 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
2026-11-15 22:05:56 +01:00
gitea-actions ef53278466 ci: bin.json v0.1.1 2026-11-15 15:23:13 +00:00
2 changed files with 16 additions and 11 deletions

No files matched your search

+3 -3
View File
@@ -1,7 +1,7 @@
{ {
"version": "0.1.0", "version": "0.1.1",
"sha256": { "sha256": {
"aarch64-apple-darwin": "910820e932ae36b65e313a23fa66c5ca5c0a0aa93fc00dc3dbf8441be1a2bcb5", "aarch64-apple-darwin": "f7859070acf2b34527a14fa031e0deff8a07540e61a32138b1a5f1b19c4025e4",
"x86_64-unknown-linux-musl": "9964dc4ff29edc7289503d52b07ae45de9a604343d6003710718bc11c3d87076" "x86_64-unknown-linux-musl": "202c05f892e29f16e5446b4e6b51ec24f8fd55ee73fc1359b202fe7bfa8cc28f"
} }
} }
+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 anyhow::{Context, Result, bail};
use serde::Deserialize; use serde::Deserialize;
use std::path::PathBuf; 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. /// [`Profile::add_allow`] on a file.
fn add_allow_at(path: &std::path::Path, entry: &str) -> Result<bool> { fn add_allow_at(path: &std::path::Path, entry: &str) -> Result<bool> {
crate::policy::check_entry(entry)?; crate::policy::check_entry(entry)?;
@@ -172,9 +182,7 @@ impl Profile {
if name.is_empty() || name.contains(['/', '.']) { if name.is_empty() || name.contains(['/', '.']) {
bail!("bad profile name {name:?}"); bail!("bad profile name {name:?}");
} }
let path = crate::config_dir() let path = profile_path(name);
.join("profiles")
.join(format!("{name}.toml"));
let s = match std::fs::read_to_string(&path) { 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 // 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 => { Err(e) if name == "default" && e.kind() == std::io::ErrorKind::NotFound => {
@@ -192,10 +200,7 @@ impl Profile {
if name.is_empty() || name.contains(['/', '.']) { if name.is_empty() || name.contains(['/', '.']) {
bail!("bad profile name {name:?}"); bail!("bad profile name {name:?}");
} }
let path = crate::config_dir() add_allow_at(&profile_path(name), entry)
.join("profiles")
.join(format!("{name}.toml"));
add_allow_at(&path, entry)
} }
pub fn account<'a>(&'a self, profile: &'a str) -> &'a str { pub fn account<'a>(&'a self, profile: &'a str) -> &'a str {