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

     1  doc_meta: |
     2    folder: cmd-func
     3    title: reg and deReg
     4    head: |
     5      reg and deReg cmd is used to register a variable or remove a variable
     6  
     7    sections:
     8      - title: reg cmd spec
     9        content: |
    10          reg will automatically register it to global runtime vars map
    11          ```
    12           -  name: reg
    13              desc: description
    14              cmd:
    15                name: this is varname it will register to
    16                value: this is the value, or dvar to be assigned to the varname
    17              flags:
    18                - localOnly
    19  
    20          ```
    21  
    22      - title: deReg cmd spec
    23        content: |
    24          reg will automatically register it to global runtime vars map
    25          ```
    26            -
    27              name: deReg
    28              desc: demo of deReg command
    29              cmd: this_will_be_the_var_name_to_be_removed
    30          ```
    31  
    32      - title: localOnly flag
    33        content: |
    34          Indicating if this var only availbe in the local scope within one func call by default, it register the var to global scope
    35  
    36      - title: note
    37        content: |
    38          Compare to the template pipeline reg/deReg command, the difference of these two command here reg and deReg the vars immediately in the current func step, rather than the next func step. Check it out the demo step
    39  
    40      - title: Demo
    41        log: yes
    42  
    43  vars:
    44    student:
    45      name: Tom
    46      gender: Male
    47      school: Sydney Grammar
    48  
    49  tasks:
    50  
    51    -
    52      name: task
    53      task:
    54        - func: shell
    55          do:
    56            - echo "hello 1"
    57  
    58  
    59        - func: cmd
    60          dvars:
    61            - name: school
    62              value: "{{.student.school}}"
    63          do:
    64            -
    65              name: print
    66              desc: demo of print command
    67              cmd: "hello, {{.student.school}}"
    68  
    69            -
    70              name: reg
    71              desc: demo of reg command
    72              cmd:
    73                name: greet
    74                value: "from local dvars, {{.school}}. registered to global runtime"
    75  
    76            -
    77              name: print
    78              desc: |
    79                show above reg var greet and it is available immediately in current func
    80                unlike the reg in template, it is available in the next step func execution
    81              cmd: "hello, {{.greet}}"
    82  
    83            -
    84              name: reg
    85              desc: |
    86                demo greetlocal is registered to local var only
    87                it is accessible in current func, but not next one
    88              cmd:
    89                name: greetlocal
    90                value: "hello, {{.student.school}}. registered to local func only"
    91              flags:
    92                - localOnly
    93  
    94            -
    95              name: print
    96              desc: |
    97                this show display a correct rendered value
    98              cmd: "hello, {{.greetlocal}}"
    99  
   100  
   101        - func: cmd
   102          desc: the greetlocal will not be availe in this func call
   103          do:
   104            -
   105              name: print
   106              desc: |
   107                this will show the registered global runtime var
   108              cmd: "hello, {{.greetlocal}}"
   109  
   110            -
   111              name: print
   112              desc: |
   113                this will show <no value> for greetlocal, as it is not registered to global
   114              cmd: "hello, {{.greet}}"
   115  
   116        - func: cmd
   117          do:
   118            -
   119              name: deReg
   120              desc: demo of deReg command
   121              cmd: greet
   122  
   123        - func: shell
   124          desc: |
   125            you will see that greet var is removed from global var map
   126            you will see <no value> here
   127          do:
   128            - echo "hello {{.greet}}"