modify yml content

ymlWrite cmd allow you to modify yml content with provide simple or complex value

How to use

  • 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
  • path: path is the yq path
  • value: a simple value of string
  • nodevalue: a complex value in yml content
  • reg: the var name to register to
  • flags:
    • localOnly: to indicate that the registered var is in local func var scope

Note that value and nodevalue are mutual exclusive

Demo

source

Main task yaml file
    vars:
      tom: |
        tom:
          sex: male
          age: 23
      emily: |
        emily:
          sex: female
          age: 32
    tasks:
    - name: task
      task:
      - func: cmd
        desc: inplace modification
        do:
        - name: ymlWrite
          cmd:
            ymlstr: '{{.tom}}'
            path: tom.sex
            value: female
            verbose: v
            reg: tomyml
        - name: print
          cmd: '{{.tomyml }}'
        - name: ymlWrite
          cmd:
            ymlstr: '{{.tomyml}}'
            path: tom.wife
            nodevalue: '{{.emily}}'
            verbose: vvvv
            reg: tomyml
        - name: print
          cmd: '{{.tomyml }}'
    
Main log file
    loading [Config]:  ./tests/functests/upconfig.yml
    Main config:
                 Version -> 1.0.0
                  RefDir -> ./tests/functests
                 WorkDir -> cwd
              AbsWorkDir -> /up_project/up
                TaskFile -> c0103
                 Verbose -> vvv
              ModuleName -> self
               ShellType -> /bin/sh
           MaxCallLayers -> 8
                 Timeout -> 3600000
     MaxModuelCallLayers -> 256
               EntryTask -> task
      ModRepoUsernameRef -> 
      ModRepoPasswordRef -> 
    work dir: /up_project/up
    -exec task: task
    loading [Task]:  ./tests/functests/c0103
    module: [self], instance id: [dev], exec profile: []
    profile -  envVars:
    
    (*core.Cache)({
    })
    
    Task1: [task ==> task:  ]
    -Step1: [: inplace modification ]
    self: final context exec vars:
    
    (*core.Cache)({
      "emily": "emily:\n  sex: female\n  age: 32\n",
      "tom": "tom:\n  sex: male\n  age: 23\n",
      "up_runtime_task_layer_number": 0
    })
    
    ~SubStep1: [ymlWrite:  ]
    ~SubStep2: [print:  ]
    tom:
      sex: female
      age: 23
    
    ~SubStep3: [ymlWrite:  ]
    ~SubStep4: [print:  ]
    tom:
      sex: female
      age: 23
      wife:
        emily:
          sex: female
          age: 32
    
    
Logs with different verbose level
Raw logs with different verbose level

Other references: