indirect reference

Showcase using if condition in the case of non-exist value, you will probably need to use query cmd to query element from yml string then use if condition in the next step

Note

For this case, if you need to reference to a dynamic value from a yml doc rather than var object, you can use query and register it, then refernce to that registered var value for if condition

Demo

source

Main task yaml file
    vars:
      student:
        name: tom
        sex: male
      ymldoc: |
        student:
          name: tom
          sex: male
    tasks:
    - name: task
      desc: main entry
      task:
      - func: cmd
        do:
        - name: print
          cmd: '{{.student.name}}'
        - name: print
          cmd: '{{.student.age}}'
      - func: cmd
        do:
        - name: print
          cmd: hello tom
        if: '{{eq .student.name "tom"}}'
      - func: cmd
        desc: add support if the element does not exist, then if condition should be false
          by default
        do:
        - name: print
          cmd: you will not see this message
        if: '{{.student.age}}'
      - func: cmd
        name: query
        cmd:
          ymlkey: ymldoc
          path: student.age.
          reg: studentage
        flags: [ymlOnly]
      - func: cmd
        do:
        - name: print
          cmd: you will not see this message
        if: '{{.studentage}}'
    
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 -> c0123
                 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/c0123
    module: [self], instance id: [dev], exec profile: []
    profile -  envVars:
    
    (*core.Cache)({
    })
    
    Task1: [task ==> task: main entry ]
    -Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0,
      "student": {
        "sex": "male",
        "name": "tom"
      },
      "ymldoc": "student:\n  name: tom\n  sex: male\n"
    })
    
    ~SubStep1: [print:  ]
    tom
    ~SubStep2: [print:  ]
    None
    -Step2:
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0,
      "student": {
        "sex": "male",
        "name": "tom"
      },
      "ymldoc": "student:\n  name: tom\n  sex: male\n"
    })
    
    ~SubStep1: [print:  ]
    hello tom
    -Step3: [: add support if the element does not exist, then if condition should be false by default ]
    self: final context exec vars:
    
    (*core.Cache)({
      "ymldoc": "student:\n  name: tom\n  sex: male\n",
      "up_runtime_task_layer_number": 0,
      "student": {
        "name": "tom",
        "sex": "male"
      }
    })
    
    condition failed, skip executing step 
    
    -Step4: [query:  ]
    self: final context exec vars:
    
    (*core.Cache)({
      "student": {
        "name": "tom",
        "sex": "male"
      },
      "ymldoc": "student:\n  name: tom\n  sex: male\n",
      "up_runtime_task_layer_number": 0
    })
    
     WARN: [cmd] - [Not implemented or void for no action!]
    -Step5:
    self: final context exec vars:
    
    (*core.Cache)({
      "student": {
        "sex": "male",
        "name": "tom"
      },
      "ymldoc": "student:\n  name: tom\n  sex: male\n",
      "up_runtime_task_layer_number": 0
    })
    
    condition failed, skip executing step 
    
    
Logs with different verbose level
Raw logs with different verbose level