Skip to content

Add quick start information in README #167

@ppom0

Description

@ppom0

I spent a lot of time reading cmds/jrsonnet/src/main.rs and libraries source code to be able to make this quick start example, so I guess it would help other people as well to have a minimal example to start with!

I've written this code for 0.4.2.

Maybe this could be added to the README or somewhere in the doc?

use std::path::PathBuf;
                                                                                   
use jrsonnet_evaluator::{error::LocError, EvaluationState, FileImportResolver};
                                                                                   
pub fn from_path(path: &PathBuf) -> Result<String, String> {
    let state = EvaluationState::default();
    state.with_stdlib();
    state.set_import_resolver(Box::new(FileImportResolver::default()));
                                                                                   
    match evaluate(path, &state) {
        Ok(val) => Ok(val),
        Err(err) => Err(state.stringify_err(&err)),
    }
}
fn evaluate(path: &PathBuf, state: &EvaluationState) -> Result<String, LocError> {
    let val = state.evaluate_file_raw(path)?;
    let result = state.manifest(val)?;
    Ok(result.to_string())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions