From 0b2688c0f16bedbbf956dc9b7ecd411ad1cde0dd Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Fri, 29 Oct 2021 14:14:39 +1100 Subject: [PATCH] Split printer --- .gitignore | 6 +- acceptance_tests/basic.sh | 2 +- acceptance_tests/empty.sh | 1 + acceptance_tests/front-matter.sh | 1 + acceptance_tests/leading-seperator.sh | 1 + acceptance_tests/output-format.sh | 4 + acceptance_tests/pretty-print.sh | 3 + acceptance_tests/split-printer.sh | 157 ++++++++++++++++++++++++++ cmd/constant.go | 2 + cmd/evaluate_all_command.go | 8 +- cmd/evalute_sequence_command.go | 8 +- cmd/printer_utils.go | 24 ++++ cmd/root.go | 3 + pkg/yqlib/operator_encoder_decoder.go | 3 +- pkg/yqlib/operators_test.go | 4 +- pkg/yqlib/printer.go | 130 ++++++++++++--------- pkg/yqlib/printer_test.go | 18 +-- pkg/yqlib/printer_writer.go | 81 +++++++++++++ 18 files changed, 385 insertions(+), 71 deletions(-) create mode 100755 acceptance_tests/split-printer.sh create mode 100644 cmd/printer_utils.go create mode 100644 pkg/yqlib/printer_writer.go diff --git a/.gitignore b/.gitignore index fac7e030..00b1ab74 100644 --- a/.gitignore +++ b/.gitignore @@ -38,8 +38,12 @@ parts/ prime/ .snapcraft/ yq*.snap + test.yml -test2.yml +test*.yml +0.yml +1.yml +2.yml # man page diff --git a/acceptance_tests/basic.sh b/acceptance_tests/basic.sh index f83f9085..dc9069ae 100755 --- a/acceptance_tests/basic.sh +++ b/acceptance_tests/basic.sh @@ -1,7 +1,7 @@ #!/bin/bash setUp() { - rm -f test.yml + rm test*.yml || true } testBasicEvalRoundTrip() { diff --git a/acceptance_tests/empty.sh b/acceptance_tests/empty.sh index d7f344df..7ffb813f 100755 --- a/acceptance_tests/empty.sh +++ b/acceptance_tests/empty.sh @@ -1,6 +1,7 @@ #!/bin/bash setUp() { + rm test*.yml || true cat >test.yml <test.yml <test.yml <test.yml <test.yml <test.yml <test.yml <test.yml <test.yml <test.yml <test.yml <test2.yml < 0 { + name = result.MatchingNodes.Front().Value.(*CandidateNode).Node.Value + } + name = fmt.Sprintf("%v.%v", name, sp.extension) + + f, err := os.Create(name) + + if err != nil { + return nil, err + } + sp.index = sp.index + 1 + + return bufio.NewWriter(f), nil + +}