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

YAML comments support #410

Open
wants to merge 19 commits into
base: trunk
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Changed the example and changed the sequence node tag
Tim203 committed Jun 22, 2023

Verified

This commit was signed with the committer’s verified signature.
erikmd Erik Martin-Dorel
commit a0901bf009a2321528aec3f3973d8f57613be1cd
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ public Node representData(final Object nodeObject) {
if (node.isMap()) {
final List<NodeTuple> children = new ArrayList<>();
for (Map.Entry<Object, ? extends ConfigurationNode> ent : node.childrenMap().entrySet()) {
// SnakeYAML supports both key as value comments. Add the comments on the key
// SnakeYAML supports both key and value comments. Add the comments on the key
final Node value = represent(ent.getValue());
final Node key = represent(String.valueOf(ent.getKey()));
key.setBlockComments(value.getBlockComments());
@@ -70,7 +70,7 @@ public Node representData(final Object nodeObject) {
for (ConfigurationNode ent : node.childrenList()) {
children.add(represent(ent));
}
yamlNode = new SequenceNode(Tag.SET, children, FlowStyle.AUTO);
yamlNode = new SequenceNode(Tag.SEQ, children, FlowStyle.AUTO);
} else {
yamlNode = represent(node.rawScalar());
}
Original file line number Diff line number Diff line change
@@ -109,12 +109,16 @@ void testWriteBasicFile(final @TempDir Path tempDir) throws ConfigurateException
void testWriteComments(final @TempDir Path tempDir) throws IOException {
final Path target = tempDir.resolve("comments-actual.yml");
final ConfigurationNode node = CommentedConfigurationNode.root(n ->
n.node("pizza")
.comment("john's")
n.node("waffles-with-syrup")
.comment("hello world")
.act(p ->
p.node("pineapple")
.set(true)
.comment("who doesn't love a good pineapple\non a pizza??")));
p.node("ingredients")
.comment("multi-line\ncomments")
.act(i -> {
i.appendListNode().set("waffles").comment("would you've guessed the ingredients?");
i.appendListNode().set("syrup").comment("I certainly didn't");
})
));

final YamlConfigurationLoader loader = YamlConfigurationLoader.builder()
.path(target)
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# john's
pizza:
# who doesn't love pineapple
# on a pizza??
pineapple: true
# hello world
waffles-with-syrup:
# multi-line
# comments
ingredients:
# would you've guessed the ingredients?
- waffles
# I certainly didn't
- syrup