local vars from file

This showcases that you can use a set of local vars loaded from a file

What’s the use cae of this

There are a few benefits using vars loaded from a file

  1. segregate the context in local scope

  2. the vars externalized will be used to render the template, while they are usable in that local scope for all sub steps and sub cmd calls

A typical use case would be the batch process in the loop to load its own vars set for that loop sub call. In this case, if you use varsfile to reder template, the vars will be cached in local, they can be used not only for templating, but also in all types of func calls

How does it work if you have the declared varss in that func at the same time

The vars from the var file will be the base, the vars declared in func will be take high priority to overwrite if it has defined in the file already.

This example shows how it works

Demo

source

Main task yaml file
    tasks:
    - name: task
      desc: mock up test to test module.template rendering
      task:
      - func: cmd
        varsfile: d0146_data.yml
        vars:
          personname: Tom Cruise
          school: james rules
        do:
        - name: inspect
          desc: the vars in caller after invoking module task
          cmd:
          - exec_vars
          - exec_base_vars
        - name: template
          desc: render a template file to a file 1
          cmd:
            src: ./tests/functests/d0145.template
            dest: /tmp/mockup_doc.md
        - name: assert
          cmd:
          - '{{eq .personname "Tom Cruise"}}'
          - '{{eq .school "james rules"}}'
          - '{{eq .title "HelloWorld example"}}'
      - func: shell
        do:
        - cat /tmp/mockup_doc.md
    
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 -> c0146
                 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/c0146
    module: [self], instance id: [dev], exec profile: []
    profile -  envVars:
    
    (*core.Cache)({
    })
    
    Task1: [task ==> task: mock up test to test module.template rendering ]
    -Step1:
    loading [varsfile]:  ./tests/functests/d0146_data.yml
    self: final context exec vars:
    
    (*core.Cache)({
      "personname": "Tom Cruise",
      "school": "james rules",
      "folder": "module",
      "up_runtime_task_layer_number": 0,
      "title": "HelloWorld example"
    })
    
    ~SubStep1: [inspect: the vars in caller after invoking module task ]
     1: inspect[exec_vars]
    (*core.Cache)({
      "up_runtime_task_layer_number": 0,
      "title": "HelloWorld example",
      "personname": "Tom Cruise",
      "school": "james rules",
      "folder": "module"
    })
    
     2: inspect[exec_base_vars]
    {
    }
    
    ~SubStep2: [template: render a template file to a file 1 ]
    ~SubStep3: [assert:  ]
     1 ASSERT OK:     [{{eq .personname "Tom Cruise"}}]
     2 ASSERT OK:     [{{eq .school "james rules"}}]
     3 ASSERT OK:     [{{eq .title "HelloWorld example"}}]
    -Step2:
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0
    })
    
    cmd( 1):
    cat /tmp/mockup_doc.md
    
    -
    title: "HelloWorld example"
    date: 2020-10-06T23:42:21+1010:00
    draft: false
    -
     .. ok
    . ok
    
Logs with different verbose level
Raw logs with different verbose level