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

Multilined comments support? #39

Closed
Osiris-Team opened this issue Oct 28, 2020 · 2 comments
Closed

Multilined comments support? #39

Osiris-Team opened this issue Oct 28, 2020 · 2 comments
Labels

Comments

@Osiris-Team
Copy link

No description provided.

@Carleslc
Copy link
Owner

As specified in setComment method documentation, multiline comments can be provided using \n character.

A comment is identified by a path, so there can only be one comment for each path, this is the reason why the method is called setComment and not addComment, but in that comment you can provide multiple lines as you'd do in any String. This is only useful for BLOCK comments.

If you need to add a comment with several lines you have two equivalent approaches:

  1. Build a single String with several lines using \n character and then use setComment.
yamlFile.setComment("test", "Line one\nLine two");

Or using a StringBuilder:

StringBuilder commentBuilder = new StringBuilder();
commentBuilder.append("Line one");
commentBuilder.append('\n');
commentBuilder.append("Line two");
yamlFile.setComment("test", commentBuilder.build());
  1. Use setComment for the first line and then add the following lines prefixing the result ofgetComment.
yamlFile.setComment("test", "Line one");
yamlFile.setComment("test", yamlFile.getComment("test") + '\n' + "Line two");

@Osiris-Team
Copy link
Author

@Carleslc Great thanks

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

No branches or pull requests

2 participants