From 461661112c7a78889f9483fb1a45618bf0c46978 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Mon, 11 Jan 2021 15:52:06 +1100 Subject: [PATCH] Better add documentation --- pkg/yqlib/doc/Add.md | 12 ++++-------- pkg/yqlib/operator_add_test.go | 8 ++++---- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/pkg/yqlib/doc/Add.md b/pkg/yqlib/doc/Add.md index ab48df88..e7fd6b26 100644 --- a/pkg/yqlib/doc/Add.md +++ b/pkg/yqlib/doc/Add.md @@ -67,23 +67,19 @@ will output - 2 ``` -## Add object to array +## Add new object to array Given a sample.yml file of: ```yaml a: - - 1 - - 2 -c: - cat: meow + - dog: woof ``` then ```bash -yq eval '.a + .c' sample.yml +yq eval '.a + {"cat": "meow"}' sample.yml ``` will output ```yaml -- 1 -- 2 +- dog: woof - cat: meow ``` diff --git a/pkg/yqlib/operator_add_test.go b/pkg/yqlib/operator_add_test.go index f4b3def7..5edb8433 100644 --- a/pkg/yqlib/operator_add_test.go +++ b/pkg/yqlib/operator_add_test.go @@ -38,11 +38,11 @@ var addOperatorScenarios = []expressionScenario{ }, }, { - description: "Add object to array", - document: `{a: [1,2], c: {cat: meow}}`, - expression: `.a + .c`, + description: "Add new object to array", + document: `a: [{dog: woof}]`, + expression: `.a + {"cat": "meow"}`, expected: []string{ - "D0, P[a], (!!seq)::[1, 2, {cat: meow}]\n", + "D0, P[a], (!!seq)::[{dog: woof}, {cat: meow}]\n", }, }, {