0

I would like to create the following Yaml using yaml-cpp:

  steps:
    - - name: flip-coin
        template: flip-coin
    - - name: heads
        template: heads
        when: "{{steps.flip-coin.outputs.result}} == heads"
      - name: tails
        template: tails
        when: "{{steps.flip-coin.outputs.result}} == tails"

But I cannot print the minus symbols on the same line. This is what I am getting:

  steps:
    -
      - name: flip-coin
        template: flip-coin
    -
      - name: heads
        template: heads
        when: "{{steps.flip-coin.outputs.result}} == heads"
      - name: tails
        template: tails
        when: "{{steps.flip-coin.outputs.result}} == tails"

My code is

    YAML::Node node;
    node["steps"][0][0]["name"]="flip-coin";
    node["steps"][0][0]["template"]="flip-coin";

    node["steps"][1][0]["name"]="heads";
    node["steps"][1][0]["template"]="heads";
    node["steps"][1][0]["when"]="{{steps.flip-coin.outputs.result}} == heads";

    node["steps"][1][1]["name"]="tails";
    node["steps"][1][1]["template"]="tails";
    node["steps"][1][1]["when"]="{{steps.flip-coin.outputs.result}} == tails";

    YAML::Emitter out;
    out << node;
    std::cout << out.c_str();
Blascone
  • 11
  • 2

1 Answers1

1

The existing manipulators do not contain anything that would enable you to configure compact inline sequence notation, so I am pretty sure this isn't possible.

Generally, YAML is not designed to fine-tune character by character how your output looks like. See also this related question. Spacing information is a presentation detail and not present in your data. Therefore, your data is presented as the implementation sees fit and except for the available manipulators, you can't do anything about it.

flyx
  • 35,506
  • 7
  • 89
  • 126