diff --git a/CHANGELOG.md b/CHANGELOG.md index e4bc6ffb..22190c10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/topiary-cli/src/main.rs b/topiary-cli/src/main.rs index a3fe2340..aef62e71 100644 --- a/topiary-cli/src/main.rs +++ b/topiary-cli/src/main.rs @@ -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, )?; @@ -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 => { diff --git a/topiary-config/src/lib.rs b/topiary-config/src/lib.rs index 765d3e82..9b3536df 100644 --- a/topiary-config/src/lib.rs +++ b/topiary-config/src/lib.rs @@ -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"))] @@ -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) -> TopiaryConfigResult { + pub fn fetch(merge: bool, file: &Option) -> TopiaryConfigResult<(Self, RichTerm)> { // If we have an explicit file, fail if it doesn't exist if let Some(path) = file { if !path.exists() { @@ -161,26 +161,26 @@ impl Configuration { Err(TopiaryConfigError::NoExtension(pb.clone())) } - fn parse_and_merge(sources: &[Source]) -> TopiaryConfigResult { + fn parse_and_merge(sources: &[Source]) -> TopiaryConfigResult<(Self, RichTerm)> { let inputs = sources.iter().map(|s| s.clone().into()); let mut program = Program::::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 { + fn parse(source: Source) -> TopiaryConfigResult<(Self, RichTerm)> { let mut program = Program::::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)) } }