github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0047.yml (about) 1 doc_meta: | 2 folder: design-patterns 3 title: basic cli skeleton 4 head: | 5 This showcases: 6 * A typical cli application with user input 7 * It taskes 2 envionrment vars and use default value if they are empty 8 * Prepare the dynamic script(data) to be executed 9 * Use a shell func to execute the final prepared script 10 11 sections: 12 - title: Demo 13 log: yes 14 15 notes: 16 goal: 17 - showcase the bare minimal entry point is just a named task only 18 - showcase how to gracefully manage the env vars 19 - continue of c0046 20 21 storys: 22 - a cli script requires 2 input from env vars 23 - it should take the env var from current bash/shell environment 24 - the env vars: 25 student_name: | 26 if it can not find it, it fails fast and execution stops 27 ref to f0045 for the failed case 28 student_age: if it can not find it, defaul it to 18 29 30 scopes: 31 32 - name: global 33 dvars: 34 - name: student_name 35 value: '{{ env "STUDENT_NAME" |default "Tom Hanks" }}' 36 - name: student_age 37 value: '{{ env "STUDENT_AGE" |default 28 }}' 38 39 dvars: 40 - name: cli 41 desc: | 42 you can offload this lengthy value to a ref file instead 43 eventually the file will become a template file 44 value: | 45 echo """ 46 student details: 47 name: {{.student_name}} 48 age: {{.student_age}} 49 """ 50 51 tasks: 52 53 - 54 name: task 55 task: 56 - func: shell 57 do: 58 - '{{.cli}}'