Skip to content

Commit

Permalink
Merge pull request #811 from tweag/nb/nickel_config_output
Browse files Browse the repository at this point in the history
Output configuration as Nickel file
  • Loading branch information
nbacquey authored Dec 11, 2024
2 parents 462d47e + 6079813 commit 1dbf717
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ This name should be decided amongst the team before the release.
- [#780](https://github.com/tweag/topiary/pull/780) Measuring scopes are now independent from captures order
- [#790](https://github.com/tweag/topiary/pull/790) No longer merge config files by default, use priority instead.
- [#801](https://github.com/tweag/topiary/pull/801) Improved documentation of the `visualise` subcommand
- [#811](https://github.com/tweag/topiary/pull/811) The `config` subcommand now outputs a Nickel file instead of some inner representation

### Fixed
- [#779](https://github.com/tweag/topiary/pull/779) Load relevant grammars before CLI tests
Expand Down
6 changes: 3 additions & 3 deletions topiary-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async fn main() -> ExitCode {
async fn run() -> CLIResult<()> {
let args = cli::get_args()?;

let config = topiary_config::Configuration::fetch(
let (config, nickel_config) = topiary_config::Configuration::fetch(
args.global.merge_configuration,
&args.global.configuration,
)?;
Expand Down Expand Up @@ -145,8 +145,8 @@ async fn run() -> CLIResult<()> {
}

Commands::Config => {
// Output collated configuration as debug
print!("{:#?}", config);
// Output the collated nickel configuration
println!("{nickel_config}")
}

Commands::Prefetch => {
Expand Down
16 changes: 8 additions & 8 deletions topiary-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{
};

use language::{Language, LanguageConfiguration};
use nickel_lang_core::{eval::cache::CacheImpl, program::Program};
use nickel_lang_core::{eval::cache::CacheImpl, program::Program, term::RichTerm};
use serde::Deserialize;

#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -51,7 +51,7 @@ impl Configuration {
/// with the path that was not found.
/// If the configuration file exists, but cannot be parsed, this function will return a
/// `TopiaryConfigError` with the error that occurred.
pub fn fetch(merge: bool, file: &Option<PathBuf>) -> TopiaryConfigResult<Self> {
pub fn fetch(merge: bool, file: &Option<PathBuf>) -> TopiaryConfigResult<(Self, RichTerm)> {
// If we have an explicit file, fail if it doesn't exist
if let Some(path) = file {
if !path.exists() {
Expand Down Expand Up @@ -161,26 +161,26 @@ impl Configuration {
Err(TopiaryConfigError::NoExtension(pb.clone()))
}

fn parse_and_merge(sources: &[Source]) -> TopiaryConfigResult<Self> {
fn parse_and_merge(sources: &[Source]) -> TopiaryConfigResult<(Self, RichTerm)> {
let inputs = sources.iter().map(|s| s.clone().into());

let mut program = Program::<CacheImpl>::new_from_inputs(inputs, std::io::stderr())?;

let term = program.eval_full_for_export()?;

let serde_config = SerdeConfiguration::deserialize(term)?;
let serde_config = SerdeConfiguration::deserialize(term.clone())?;

Ok(serde_config.into())
Ok((serde_config.into(), term))
}

fn parse(source: Source) -> TopiaryConfigResult<Self> {
fn parse(source: Source) -> TopiaryConfigResult<(Self, RichTerm)> {
let mut program = Program::<CacheImpl>::new_from_input(source.into(), std::io::stderr())?;

let term = program.eval_full_for_export()?;

let serde_config = SerdeConfiguration::deserialize(term)?;
let serde_config = SerdeConfiguration::deserialize(term.clone())?;

Ok(serde_config.into())
Ok((serde_config.into(), term))
}
}

Expand Down

0 comments on commit 1dbf717

Please sign in to comment.