if condition advanced

Showcase you can use if condition for cmd func and call func too

What’s good about it when you use if with call func?

The call func actually is very powerfully to create a execution branch with its own stack. So if you use a if condition to call another task, it actually separate the implementation with your own main flow.

Also with multiple if, it is similar to convert the workflow to if/if else, or switch/case etc. Or with embeded if in callee, you could create branched flows so this enrichs the workflow management in very simple way compare to other tools

Demo

source

Main task yaml file
    tasks:
    - name: task
      task:
      - func: call
        do:
        - taska
        if: "false"
      - func: cmd
        dvars:
        - name: greet
          value: hello
          flags: [vvvv]
        if: "true"
      - func: call
        do:
        - taska
        if: "true"
    - name: taska
      task:
      - func: shell
        desc: greet var will be no value as it is a local var for cmd step
        do:
        - echo "hello from taska"
        - echo "{{.greet}} from taska"
    
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 -> c0055
                 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/c0055
    module: [self], instance id: [dev], exec profile: []
    profile -  envVars:
    
    (*core.Cache)({
    })
    
    Task1: [task ==> task:  ]
    -Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0
    })
    
    condition failed, skip executing step 
    
    -Step2:
    dvar> greet:
    "hello"
    
    -
    hello
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0,
      "greet": "hello"
    })
    
     WARN: [cmd] - [Not implemented or void for no action!]
    -Step3:
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0
    })
    
    =Task2: [task ==> taska:  ]
    --Step1: [: greet var will be no value as it is a local var for cmd step ]
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 1
    })
    
    cmd( 1):
    echo "hello from taska"
    
    -
    hello from taska
    
    -
     .. ok
    cmd( 2):
    echo "{{.greet}} from taska"
    
    -
    <no value> from taska
    
    -
     .. ok
    . ok
    
Logs with different verbose level
Raw logs with different verbose level