use super::StdlibConfig;
use crate::localization::{self, keys};
use anyhow::{Context, anyhow};
use camino::Utf8PathBuf;
use cap_std::{ambient_authority, fs_utf8::Dir};
use std::env;
impl StdlibConfig {
pub fn from_current_dir() -> anyhow::Result<Self> {
let cwd =
env::current_dir().context(localization::message(keys::STDLIB_CONFIG_RESOLVE_CWD))?;
let path = Utf8PathBuf::from_path_buf(cwd).map_err(|path| {
anyhow!(
"{}",
localization::message(keys::STDLIB_CONFIG_CWD_NON_UTF8)
.with_arg("path", path.display().to_string())
)
})?;
let root = Dir::open_ambient_dir(path.as_path(), ambient_authority()).context(
localization::message(keys::STDLIB_CONFIG_OPEN_WORKSPACE_ROOT),
)?;
tracing::debug!(path = %path, "resolved stdlib workspace root from current directory");
Self::new(root)
.context("default fetch cache path should be valid")?
.with_workspace_root_path(path)
.context("workspace root must be absolute")
}
}