-
Notifications
You must be signed in to change notification settings - Fork 9
00 Getting Started
suntong edited this page Nov 11, 2023
·
9 revisions
Getting started with data-driven arbitrary text generation.
The data are provided in .YAML format. E.g., example.yaml
:
# individual variables
Name: html2md
ProgramName: html2md
PackageName: main
# nested individual variables
Colormaps:
ColorRed: red
ColorBlue: blue
ColorWhite: white
# Simple string, to demo the string `split` function
Colorlist: red blue white
# Array variable in normal way
Colors:
- red
- blue
- white
# Multi-dimension array variable
Cars:
- Make: Ford
Module: T1
- Make: GM
Module: T2
list0.tmpl from test cases
The colors are: {{range .Colors}}{{.}}, {{end}}.
The result is in list0.ref:
The colors are: red, blue, white, .
Testing the templates on the fly:
$ easygen -ts 'The color maps are: {{range $key, $value := .Colormaps}}{{$key}}={{$value}}, {{end}}.' example
The color maps are: ColorBlue=blue, ColorRed=red, ColorWhite=white, .
Also check the variation of such transforming:
-
list1.tmpl
to use quotes in the driving data
check result: list1.ref -
list1HTML.tmpl
to output above quotes in the driving data in html format
check result: list1HTML.ref -
listfunc1.tmpl
to eliminate the last comma ",
" before the end
check result: listfunc1.ref -
listfunc2.tmpl
to rename variables using different naming conventions via egVar builtin functions
check result: listfunc2.ref -
list0E.tmpl
to use environment variables in template
check result: list0E.ref
I'll document more of them when I have time...
The above listfunc1.tmpl example showcases using some basic easygen builtin functions. What else are the easygen builtin functions?
The full list of easygen builtin functions is available here.
To generate sgdisk.sh
like the following,
# format /dev/sdb as GPT, GUID Partition Table
sgdisk -Z /dev/sdb
sgdisk -n 0:0:+200M -t 0:ef02 -c 0:"bios_boot" /dev/sdb
sgdisk -n 0:0:+20G -t 0:8300 -c 0:"linux_boot" /dev/sdb
sgdisk -n 0:0:+30G -t 0:0700 -c 0:"windows" /dev/sdb
sgdisk -n 0:0:+10G -t 0:8200 -c 0:"linux_swap" /dev/sdb
sgdisk -n 0:0:+12G -t 0:8300 -c 0:"os1" /dev/sdb
sgdisk -n 0:0:+12G -t 0:8300 -c 0:"os2" /dev/sdb
sgdisk -n 0:0:+12G -t 0:8300 -c 0:"os3" /dev/sdb
sgdisk -n 0:0:0 -t 0:8300 -c 0:"data" /dev/sdb
sgdisk -p /dev/sdb
# inform the OS of partition table changes
partprobe /dev/sdb
fdisk -l /dev/sdb
check out its
driving data: sgdisk.yaml
Disk: /dev/sdb
Partitions:
- Name: bios_boot
Type: ef02
Size: +200M
- Name: linux_boot
Type: 8300
Size: +20G
- Name: windows
Type: "0700"
Size: +30G
- Name: linux_swap
Type: 8200
Size: +10G
- Name: os1
Type: 8300
Size: +12G
. . .
template: sgdisk.tmpl
# format {{.Disk}} as GPT, GUID Partition Table
sgdisk -Z {{.Disk}}
{{range .Partitions}}
sgdisk -n 0:0:{{.Size}} -t 0:{{.Type}} -c 0:"{{.Name}}" {{$.Disk}}{{end}}
sgdisk -p {{.Disk}}
# inform the OS of partition table changes
partprobe {{.Disk}}
fdisk -l {{.Disk}}
See Testing the templates on the fly
See How to include nested templates from other files
See