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