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

     1  doc_meta: |
     2    folder: flow-controll
     3    title: None value
     4    head: |
     5      None value will be presented if there variable is not be to be rendered
     6  
     7      Most of the case, this is due to the non-exist variable of given path
     8  
     9    sections:
    10      - title: Demo
    11        log: yes
    12  
    13      - title: How to user the None value properly
    14        content: |
    15          * Note that if you intend to evaluate the var's value directly, in case of the var path does not exist, the variable part will be  replace by golang internal <no value> instead of None
    16          * You should always use a var to store the direct var by given a variable path, eg. person.name
    17  
    18  vars:
    19    person:
    20      name: tom
    21  
    22  
    23  tasks:
    24    -
    25      name: task
    26      task:
    27        -
    28          func: cmd
    29          desc: |
    30            the commented if statement will cause a template rendering issue since person.school is not able to be determined
    31          do:
    32            - name: print
    33              cmd: "hello: {{.person.name}}"
    34  #        if: '{{eq .person.school "None"}}'
    35  
    36        -
    37          func: cmd
    38          desc: |
    39            correct way is to try to get the school value and save it to a dvar
    40            then it is deterministic of the school value
    41          dvars:
    42            - name: school
    43              value: '{{.person.school}}'
    44          do:
    45            - name: print
    46              cmd: "hello: {{.person.name}}"
    47          if: '{{eq .school "None"}}'
    48          else:
    49            - func: cmd
    50              desc: now it is safe to access school from person object
    51              do:
    52                - name: print
    53                  cmd: "hello: {{.person.name}} from {{.person.school}}"