phase: 20.49 COMPLETE; 20.50 Flow+String minimal reps; 20.51 selfhost v0/v1 minimal (Option A/B); hv1-inline binop/unop/copy; docs + run_all + CURRENT_TASK -> 21.0
This commit is contained in:
@ -17,28 +17,37 @@ pub fn populate_from_toml(
|
||||
let mut policy = UsingPolicy::default();
|
||||
// Prefer CWD nyash.toml; if missing, honor NYASH_ROOT/nyash.toml for tools that run from subdirs
|
||||
let (text, toml_path) = {
|
||||
let path = std::path::Path::new("nyash.toml");
|
||||
if path.exists() {
|
||||
(
|
||||
std::fs::read_to_string(path)
|
||||
.map_err(|e| UsingError::ReadToml(e.to_string()))?,
|
||||
path.to_path_buf(),
|
||||
)
|
||||
} else if let Ok(root) = std::env::var("NYASH_ROOT") {
|
||||
let alt = std::path::Path::new(&root).join("nyash.toml");
|
||||
if alt.exists() {
|
||||
(
|
||||
std::fs::read_to_string(&alt)
|
||||
.map_err(|e| UsingError::ReadToml(e.to_string()))?,
|
||||
alt,
|
||||
)
|
||||
} else {
|
||||
return Ok(policy);
|
||||
// Prefer hakorune.toml, fallback to nyash.toml; check CWD then NYASH_ROOT
|
||||
let candidates = ["hakorune.toml", "nyash.toml"];
|
||||
let mut found: Option<(String, std::path::PathBuf)> = None;
|
||||
|
||||
// 1) Try current directory
|
||||
for name in candidates.iter() {
|
||||
let p = std::path::Path::new(name);
|
||||
if p.exists() {
|
||||
let txt = std::fs::read_to_string(p)
|
||||
.map_err(|e| UsingError::ReadToml(e.to_string()))?;
|
||||
found = Some((txt, p.to_path_buf()));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
return Ok(policy);
|
||||
}
|
||||
};
|
||||
// 2) Try NYASH_ROOT if not found yet
|
||||
if found.is_none() {
|
||||
if let Ok(root) = std::env::var("NYASH_ROOT") {
|
||||
for name in candidates.iter() {
|
||||
let alt = std::path::Path::new(&root).join(name);
|
||||
if alt.exists() {
|
||||
let txt = std::fs::read_to_string(&alt)
|
||||
.map_err(|e| UsingError::ReadToml(e.to_string()))?;
|
||||
found = Some((txt, alt));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 3) Fallback: empty content and path
|
||||
Ok(found.unwrap_or((String::new(), std::path::PathBuf::from(""))))
|
||||
}?;
|
||||
let doc = toml::from_str::<toml::Value>(&text)
|
||||
.map_err(|e| UsingError::ParseToml(e.to_string()))?;
|
||||
let toml_dir = toml_path
|
||||
|
||||
Reference in New Issue
Block a user