zint/
utils.rs

1use anyhow::{anyhow, Result};
2use serde::Deserialize;
3use std::path::PathBuf;
4
5/// Represents the Foundry configuration (foundry.toml)
6#[derive(Deserialize)]
7pub struct FoundryConfig {
8    /// The profile section of the `foundry.toml` configuration.
9    pub profile: Profile,
10}
11
12/// Represents a profile in the Foundry configuration.
13#[derive(Deserialize)]
14pub struct Profile {
15    /// The default profile settings.
16    pub default: ProfileSettings,
17}
18
19/// Represents the settings for a Foundry profile.
20#[derive(Deserialize)]
21pub struct ProfileSettings {
22    /// The output directory for compiled artifacts.
23    pub out: Option<String>,
24}
25
26/// Find a file by walking up the directory tree
27pub fn find_up(filename: &str) -> Result<PathBuf> {
28    let mut path = std::env::current_dir()?;
29    loop {
30        let candidate = path.join(filename);
31        if candidate.exists() {
32            return Ok(candidate);
33        }
34        if !path.pop() {
35            return Err(anyhow!(
36                "Could not find {} in current or parent directories",
37                filename
38            ));
39        }
40    }
41}