toObj

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

Difference from toObj in dvar

toObj in dvar is limited and can not inherit the loopitem unless you register the loopitem to another var

Relavant

toObj in dvar

references

Demo

source

Main task yaml file
    tasks:
    - name: task
      task:
      - func: cmd
        vars:
          person_yml: |
            person:
              name: tom
              age: 23
          name_to_convert: person_yml
          name_to_reg: person_dyna_object
          person: jason
        do:
        - name: toObj
          desc: |
            the key is pointing to a var name and use its content as yml content
          cmd:
            fromkey: person_yml
            reg: person_object
        - name: printObj
          cmd: person_object
        - name: print
          cmd: 'my name is: {{.person_object.person.name}}'
        - name: toObj
          cmd:
            fromkey: '{{.name_to_convert}}'
            reg: '{{.name_to_reg}}'
        - name: printObj
          cmd: '{{.name_to_reg}}'
        - name: toObj
          desc: use src content directly
          cmd:
            src: |
              person:
                name: {{.person}}
                age: 53
            reg: '{{.name_to_reg}}'
        - name: printObj
          cmd: '{{.name_to_reg}}'
    
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 -> c0095
                 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/c0095
    module: [self], instance id: [dev], exec profile: []
    profile -  envVars:
    
    (*core.Cache)({
    })
    
    Task1: [task ==> task:  ]
    -Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "name_to_reg": "person_dyna_object",
      "person": "jason",
      "person_yml": "person:\n  name: tom\n  age: 23\n",
      "name_to_convert": "person_yml",
      "up_runtime_task_layer_number": 0
    })
    
    ~SubStep1: [toObj: the key is pointing to a var name and use its content as yml content
     ]
    ~SubStep2: [printObj:  ]
    object:
     person_object: {
      "person": {
        "age": 23,
        "name": "tom"
      }
    }
    
    ~SubStep3: [print:  ]
    my name is: tom
    ~SubStep4: [toObj:  ]
    ~SubStep5: [printObj:  ]
    object:
     person_dyna_object: {
      "person": {
        "name": "tom",
        "age": 23
      }
    }
    
    ~SubStep6: [toObj: use src content directly ]
    ~SubStep7: [printObj:  ]
    object:
     person_dyna_object: {
      "person": {
        "name": "jason",
        "age": 53
      }
    }
    
    
Logs with different verbose level
Raw logs with different verbose level