Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In YAML how can I comment a part of a line?

Tags:

yaml

In YAML how can I comment a part of a line?

for example:

- name: "JAVA_OPTIONS"
value: "-Dconfig.dir.path=$(CONF_PATH) -Dpoint.dir.path=$(POINT_PATH)-
Xms256m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$(LOG_PATH) 
-DMY_POD_NAME=$(MY_POD_NAME)"

How can I comment a string inside the value line?

Like "-Dpoint.dir.path=$(POINT_PATH)" will be remarked but all the rest will take affect.

like image 860
Shahar Hamuzim Rajuan Avatar asked Jul 19 '17 09:07

Shahar Hamuzim Rajuan


People also ask

How do I comment a section in YAML?

The shortcut key combination for commenting YAML blocks is Ctrl+Q. Select the block. Use “CTRL + /” on Linux and Windows and “CMD+/” for Mac operating system.

Can you write comments in YAML?

YAML does not support block or multi-line comments. In order to create a multi-line comment, we need to suffix each line with a # . # block comments.

How to comment multiple lines in a YAML file?

Each line of comment starts with hashtag (#) symbol and blank space followed by description. Each line will end with new line break. Block comments are to comment the multiple lines . YAML has no support for block comments by default, You can use multiple inline comments

How to roll-back a line in YAML?

So unless there is some other commenting mechanism implemented by the program that interprets the YAML data (unlikely), the best thing to do is copy the whole line, comment one version out, and adjust the other: If you want to "roll-back" just move the comment token ( #) from the one line to the other.

How to edit a code in YAML?

YEdit is editor for yaml , to support Edit,Syntax highlight, Checking and content highligh with multiple colors. Please issue a shortcut command CTRL + Shift + C to comment the code To uncomment the code, Please select and issue the same shortcut command again to revert the comments. The other way is using menu or context menu option

How to comment a YAML block in Sublime Text?

The shortcut key combination for commenting YAML blocks is Ctrl+Q. If you are using Sublime Text editor, the steps for commenting the block are mentioned below − Select the block. Use “CTRL + /” on Linux and Windows and “CMD+/” for Mac operating system. Execute the block. Note that the same steps are applicable...


1 Answers

YAML only has comments that are in effect until the end of the line. So unless there is some other commenting mechanism implemented by the program that interprets the YAML data (unlikely), the best thing to do is copy the whole line, comment one version out, and adjust the other:

- name: "JAVA_OPTIONS"
  # value: "-Dconfig.dir.path=$(CONF_PATH) -Dpoint.dir.path=$(POINT_PATH)-Xms256m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$(LOG_PATH) -DMY_POD_NAME=$(MY_POD_NAME)"
  value: "-Dpoint.dir.path=$(POINT_PATH)-Xms256m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$(LOG_PATH) -DMY_POD_NAME=$(MY_POD_NAME)"

If you want to "roll-back" just move the comment token (#) from the one line to the other.

In the above I adjusted your input to be valid YAML. Your example is not valid because you cannot have both a sequence element and a key-value pair on the same level with the same parent (in this case the YAML document root).

like image 68
Anthon Avatar answered Sep 18 '22 21:09

Anthon