Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add quick start information in README #167

Open
ppom0 opened this issue Jun 9, 2024 · 1 comment
Open

Add quick start information in README #167

ppom0 opened this issue Jun 9, 2024 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@ppom0
Copy link

ppom0 commented Jun 9, 2024

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())
}
@ppom0 ppom0 changed the title Add quick information in README Add quick start information in README Jun 9, 2024
@CertainLach
Copy link
Owner

Usually, when I need to get examples on using the code, I look into tests, there is one for basic initialization and using std.native
https://github.com/CertainLach/jrsonnet/blob/master/tests/tests/std_native.rs

But I agree tests are sometimes more complicated than it should be, I'll create a dedicated examples which are ran by cargo run --example basic

@CertainLach CertainLach added documentation Improvements or additions to documentation labels Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants