Giter Club home page Giter Club logo

Comments (5)

stephanbuys avatar stephanbuys commented on July 3, 2024 1

@jcaesar you are more than welcome to submit a pull request that adds the example. tests/mod.rs has a few examples.

As for env expansion, nothing is built into this crate that would do something like that automatically, contributions welcome.

from docker-compose-types.

stephanbuys avatar stephanbuys commented on July 3, 2024 1

@jcaesar I'm going to close this issue for now, feel free to come by and help us improve the README if you still want to at some point in the future.

from docker-compose-types.

jcaesar avatar jcaesar commented on July 3, 2024

Hm. Looking at haddock, variable interpolation is somewhat complex (there's a nom parser behind this). I could make a PR that copies that code, but... :/ (One concrete problem is that that's GPL.).
[Edit:] Hm. compose_yml implements variable interpolation. But it's quite out of date…

from docker-compose-types.

jcaesar avatar jcaesar commented on July 3, 2024

All right, since I have a concrete thing I need to implement, I'll go with

struct OsEnv;
impl compose_yml::v2::Environment for OsEnv {
    fn var(&self, key: &str) -> Result<String, VarError> {
        std::env::var(key)
    }
}

fn interpolate(v: &mut YamlValue, e: &dyn compose_yml::v2::Environment) -> Result<()> {
    match v {
        YamlValue::String(s) => {
            *s = compose_yml::v2::raw::<String, _>(s.clone())?
                .interpolate_env(e)?
                .clone();
        }
        YamlValue::Sequence(s) => {
            for s in s {
                interpolate(s, e)?;
            }
        }
        YamlValue::Mapping(m) => {
            for v in m.values_mut() {
                interpolate(v, e)?;
            }
        }
        YamlValue::Tagged(tagged) => interpolate(&mut tagged.value, e)?,
        _ => (),
    }
    Ok(())
}

interpolate(&mut def, &OsEnv)?;

for now and worry about a pretty PR to docker-compose-types later.

from docker-compose-types.

stephanbuys avatar stephanbuys commented on July 3, 2024

Perfectly valid solution! Glad you managed to get something working for yourself.

from docker-compose-types.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.