diff --git a/pkg/yqlib/doc/Comment Operators.md b/pkg/yqlib/doc/Comment Operators.md index 20952a16..accc9b47 100644 --- a/pkg/yqlib/doc/Comment Operators.md +++ b/pkg/yqlib/doc/Comment Operators.md @@ -78,17 +78,22 @@ b: dog # leave this ``` ## Remove all comments +Note the use of `...` to ensure key nodes are included. + Given a sample.yml file of: ```yaml a: cat # comment +# great +b: # key comment ``` then ```bash -yq eval '.. comments=""' sample.yml +yq eval '... comments=""' sample.yml ``` will output ```yaml a: cat +b: ``` ## Get line comment diff --git a/pkg/yqlib/operator_comments_test.go b/pkg/yqlib/operator_comments_test.go index 5c3b0972..d88b1fb5 100644 --- a/pkg/yqlib/operator_comments_test.go +++ b/pkg/yqlib/operator_comments_test.go @@ -71,11 +71,12 @@ var commentOperatorScenarios = []expressionScenario{ }, }, { - description: "Remove all comments", - document: "# hi\n\na: cat # comment\n\n# great\n", - expression: `.. comments=""`, + description: "Remove all comments", + subdescription: "Note the use of `...` to ensure key nodes are included.", + document: "# hi\n\na: cat # comment\n\n# great\n\nb: # key comment", + expression: `... comments=""`, expected: []string{ - "D0, P[], (!!map)::a: cat\n", + "D0, P[], (!!map)::a: cat\nb:\n", }, }, {