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

Output configuration as Nickel file #811

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading