Generalize function.

This commit is contained in:
Justus Winter 2024-12-02 14:57:49 +01:00
parent 7d2fab14f9
commit 092ba48e5a
No known key found for this signature in database
GPG Key ID: 686F55B4AB2B3386
2 changed files with 5 additions and 4 deletions

View File

@ -45,7 +45,7 @@ fn get(sq: Sq, cmd: config::get::Command) -> Result<()> {
let mut acc = Default::default();
// First, look in the configuration.
let config = sq.config_file.augment_with_policy(&sq.policy)?;
let config = sq.config_file.effective_configuration(&sq)?;
let r0 = Node::traverse(&*config.as_item() as _, &path)
.map_err(Into::into)
.and_then(

View File

@ -390,19 +390,20 @@ impl ConfigFile {
Ok(())
}
/// Augments the configuration with the given policy.
/// Augments the configuration with the effective configuration
/// and policy.
///
/// XXX: Due to the way doc.remove works, it will leave misleading
/// comments behind. Therefore, the resulting configuration is
/// not suitable for dumping, but may only be used for
/// commands::config::get.
pub fn augment_with_policy(&self, p: &StandardPolicy) -> Result<Self> {
pub fn effective_configuration(&self, sq: &crate::Sq) -> Result<Self> {
use std::io::Write;
let mut raw = Vec::new();
// First, start with our configuration, and drop most of the
// policy with the exception of the path.
let p = ConfiguredStandardPolicy::from_policy(p.clone());
let p = ConfiguredStandardPolicy::from_policy(sq.policy.clone());
let mut doc = self.doc.clone();
doc.remove("policy");