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

     1  doc_meta: |
     2    folder: cmd-func
     3    title: toObj
     4    head: |
     5      toObj is a cmd to convert yml string to a a registered variable. By default it will register the var to global runtime scope, you can use flag localOnly to indicate that this var will be only registered to local scope
     6  
     7    sections:
     8      - title: Difference from toObj in dvar
     9        content: |
    10          toObj in dvar is limited and can not inherit the loopitem unless you register the loopitem to another var
    11  
    12      - title: Relavant
    13        content: toObj in dvar
    14        refs:
    15          - title: toObj in dvar
    16            link: ../../object-oriented/c0074
    17  
    18      - title: Demo
    19        log: yes
    20  
    21  notes:
    22    goal:
    23      - add a cmd to convert yml to object
    24      - |
    25        toObj in dvar is limited and can not inherit
    26        the loopitem unless you register the loopitem to another var
    27      - it does not need load to implment load from file, use readFile instead
    28  
    29  tasks:
    30  
    31    - name: task
    32      task:
    33  
    34        - func: cmd
    35          vars:
    36            person_yml: |
    37              person:
    38                name: tom
    39                age: 23
    40            name_to_convert: person_yml
    41            name_to_reg: person_dyna_object
    42            person: jason
    43  
    44          do:
    45            - name: toObj
    46              desc: |
    47                the key is pointing to a var name and use its content as yml content
    48              cmd:
    49                fromkey: person_yml
    50                reg: person_object
    51  
    52            - name: printObj
    53              cmd: person_object
    54  
    55            - name: print
    56              cmd: 'my name is: {{.person_object.person.name}}'
    57  
    58            - name: toObj
    59              cmd:
    60                fromkey: '{{.name_to_convert}}'
    61                reg: '{{.name_to_reg}}'
    62  
    63            - name: printObj
    64              cmd: '{{.name_to_reg}}'
    65  
    66            - name: toObj
    67              desc:
    68                use src content directly
    69              cmd:
    70                src: |
    71                  person:
    72                    name: {{.person}}
    73                    age: 53
    74                reg: '{{.name_to_reg}}'
    75  
    76            - name: printObj
    77              cmd: '{{.name_to_reg}}'
    78