return value

Showcase the return value from module

source

How does it work?

In this demo, the var b from module is returned to caller

Pleas note that the two vars used in Say_world will produce the result based on the input, the var a is passed in from external caller and overriden. This is a design pattern of IOC - inverse of controll, a feature to allow consumer code to inject data to module, and the module will focus on detailed implementation

config file - upconfig.yml

    
    version: 1.0.0
    Verbose: v
    MaxCallLayers: 8
    RefDir: .
    TaskFile: up.yml
    ConfigDir: .
    ConfigFile: upconfig.yml
    
    Modules:
    
       #if there is no repo, then it will use the dir as module and incorporate as module
      - dir: hello-module/
        alias: hello-module
    

up task - up.yml

    notes:
      - see if callers vars could be passed to module's func
    
    vars:
      a: caller-aaa
    
    tasks:
      -
        name: Main
        desc: main entry
        task:
    
          -
            func: call
            do: hello-module.Say_world
    
          -
            func: cmd
            do:
              -
                name: inspect
                cmd:
                  - exec_vars
                  - exec_base_vars
    
              - name: print
                cmd: |
                  back to main caller
                  a: {{.a}}
                  b: {{.b}}
    
              -
                name: assert
                des: |
                  var b is returned from module
                cmd:
                  - '{{eq .a "caller-aaa"}}'
                  - '{{eq .b "module-bbb"}}'
    

up module task - up.yml

    
    tasks:
      -
        name: Main
        desc: main entry
        task:
          -
            func: shell
            desc: main job
            do:
              - echo "hello "
    
      -
        name: Say_world
        task:
          -
            func: cmd
            vars:
              a: module-aaa
              b: module-bbb
            do:
              - name: print
                cmd: |
                  ... module world
                  a: {{.a}}
                  b: {{.b}}
    
              -
                name: assert
                cmd:
                  - '{{eq .a "caller-aaa"}}'
                  - '{{eq .b "module-bbb"}}'
    
              - name: return
                desc: |
                  var b should be return to caler
                cmd:
                  - b
    
    
Main log file
    loading [Config]:  ./tests/modtests/0003/upconfig.yml
    Main config:
                 Version -> 1.0.0
                  RefDir -> ./tests/modtests/0003
                 WorkDir -> refdir
              AbsWorkDir -> /up_project/up/tests/modtests/0003
                TaskFile -> up.yml
                 Verbose -> v
              ModuleName -> self
               ShellType -> /bin/sh
           MaxCallLayers -> 8
                 Timeout -> 3600000
     MaxModuelCallLayers -> 256
               EntryTask -> Main
      ModRepoUsernameRef -> 
      ModRepoPasswordRef -> 
    work dir: /up_project/up/tests/modtests/0003
    -exec task: Main
    loading [Task]:  ./up.yml
    module: [self], instance id: [dev], exec profile: []
    Task1: [Main ==> Main: main entry ]
    -Step1:
     WARN: [config file does not exist] - [use builtin defaults]
    loading [Task]:  ./up.yml
    module: [hello-module], instance id: [nonamed], exec profile: []
     WARN: [*be aware*] - [both instance id and exec profile are not set]
    =>call module: [hello-module] task: [Say_world]
    Task2: [TODO: Main Caller Taskname ==> Say_world:  ]
    -Step1:
    ~SubStep1: [print:  ]
    ... module world
    a: caller-aaa
    b: module-bbb
    
    ~SubStep2: [assert:  ]
     1 ASSERT OK:     [{{eq .a "caller-aaa"}}]
     2 ASSERT OK:     [{{eq .b "module-bbb"}}]
    ~SubStep3: [return: var b should be return to caler
     ]
    -Step2:
    ~SubStep1: [inspect:  ]
     1: inspect[exec_vars]
    (*core.Cache)({
      "a": "caller-aaa",
      "b": "module-bbb",
      "up_runtime_tasker_layer_number": 2,
      "up_runtime_task_layer_number": 0
    })
    
     2: inspect[exec_base_vars]
    {
      "b": "module-bbb",
      "a": "caller-aaa"
    }
    
    ~SubStep2: [print:  ]
    back to main caller
    a: caller-aaa
    b: module-bbb
    
    ~SubStep3: [assert:  ]
     1 ASSERT OK:     [{{eq .a "caller-aaa"}}]
     2 ASSERT OK:     [{{eq .b "module-bbb"}}]
    
Logs with different verbose level
Raw logs with different verbose level