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

Insert into dash-val block #65

Open
spacekookie opened this issue Aug 6, 2023 · 1 comment
Open

Insert into dash-val block #65

spacekookie opened this issue Aug 6, 2023 · 1 comment

Comments

@spacekookie
Copy link

Hey,

I have a config schema that has a peers block where I use dash vals to create a list:

peers {
  - "foo"
  - "bar"
}

I have a function which finds the correct node and then inserts a node into its child block:

 match doc.nodes_mut().iter_mut().find_map(|node| {
        let node_name = node.name().repr().unwrap();

        if node_name == tree_id {
            Some(node)
        } else {
            None
        }
    }) {
        Some(subtree) => {
            let block = subtree.children_mut().as_mut().expect("Invalid sub-block");
            let mut new_node = KdlNode::new("-");
            new_node.push(KdlEntry::new(item));
            block.nodes_mut().push(new_node);
        }
        None => panic!("invalid subtree ?!"),
    }

This works, but the resulting formatting seems really wonky:

   peers {        - "foo"
        - "bar"

    }

Which makes me think that maybe I'm doing something wrong? Or this is a bug. In either way, I thought I'd open an issue about it. Any help is much appreciated!

@zkat
Copy link
Member

zkat commented Aug 7, 2023

oh. Yeah this is probably a bug? I don't have time to look at it right now, but I imagine we should be putting newlines in the right places by default?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants