github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0103.yml (about)

     1  doc_meta: |
     2    folder: cmd-func
     3    title: modify yml content
     4    head: |
     5      ymlWrite cmd allow you to modify yml content with provide simple or complex value
     6  
     7    sections:
     8      - title: How to use
     9        content: |
    10          * ymlstr: use a templating expression to load a predefined yml value, you could use readFile or other mechansim to preload yml content to a var name
    11          * path: path is the yq path
    12          * value: a simple value of string
    13          * nodevalue: a complex value in yml content
    14          * reg: the var name to register to
    15          * flags:
    16            * localOnly: to indicate that the registered var is in local func var scope
    17  
    18          Note that value and nodevalue are mutual exclusive
    19  
    20      - title: Demo
    21        log: yes
    22  
    23    related:
    24      refs:
    25        - title: yq and yq path reference
    26          link: https://github.com/mikefarah/yq
    27  
    28  notes:
    29    goal:
    30      - add feature to modify a node value of a yml string
    31  
    32  vars:
    33    tom: |
    34      tom:
    35        sex: male
    36        age: 23
    37    emily: |
    38      emily:
    39        sex: female
    40        age: 32
    41  
    42  tasks:
    43    -
    44      name: task
    45      task:
    46        -
    47          func: cmd
    48          desc: inplace modification
    49          do:
    50            - name: ymlWrite
    51              cmd:
    52                ymlstr: '{{.tom}}'
    53                path: tom.sex
    54                value: female
    55                verbose: v
    56                reg: tomyml
    57  
    58            - name: print
    59              cmd: '{{.tomyml }}'
    60  
    61            - name: ymlWrite
    62              cmd:
    63                ymlstr: '{{.tomyml}}'
    64                path: tom.wife
    65                nodevalue: '{{.emily}}'
    66                verbose: vvvv
    67                reg: tomyml
    68  
    69            - name: print
    70              cmd: '{{.tomyml }}'