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

     1  doc_meta: |
     2    folder: vars
     3    title: local vars from file
     4    head: |
     5      This showcases that you can use a set of local vars loaded from a file
     6  
     7    sections:
     8      - title: What's the use cae of this
     9        content: |
    10          There are a few benefits using vars loaded from a file
    11  
    12          1. segregate the context in local scope
    13  
    14          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
    15  
    16          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
    17  
    18      - title: How does it work if you have the declared varss in that func at the same time
    19        content: |
    20          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.
    21  
    22          This example shows how it works
    23  
    24      - title: Demo
    25        log: yes
    26  
    27  notes:
    28    - add support to load vars in func from file
    29    - refdir apply
    30  
    31  tasks:
    32  
    33    - name: task
    34      desc: mock up test to test module.template rendering
    35      task:
    36        - func: cmd
    37          varsfile: d0146_data.yml
    38          vars:
    39            personname: Tom Cruise
    40            school: james rules
    41          do:
    42            -
    43              name: inspect
    44              desc: the vars in caller after invoking module task
    45              cmd:
    46                - exec_vars
    47                - exec_base_vars
    48  
    49            -
    50              name: template
    51              desc: render a template file to a file 1
    52              cmd:
    53                src: ./tests/functests/d0145.template
    54                dest: /tmp/mockup_doc.md
    55  
    56            -
    57              name: assert
    58              cmd:
    59                - '{{eq .personname "Tom Cruise"}}'
    60                - '{{eq .school "james rules"}}'
    61                - '{{eq .title "HelloWorld example"}}'
    62  
    63        - func: shell
    64          do:
    65            - cat /tmp/mockup_doc.md