Adds templating options to stream and file

This commit is contained in:
Bruno Tavares 2014-03-14 14:51:08 -03:00
parent 27c4ce0aa0
commit 3382c92952
5 changed files with 46 additions and 0 deletions

View File

@ -12,6 +12,7 @@
* [kickstart.download.stream](kickstart/download/stream)
* [kickstart.file.contains](kickstart/file/contains)
* [kickstart.file.link](kickstart/file/link)
* [kickstart.file.template](kickstart/file/template)
* [kickstart.group.create](kickstart/group/create)
* [kickstart.module.apply_recipe](kickstart/module/apply_recipe)
* [kickstart.module.apply_role](kickstart/module/apply_role)
@ -36,6 +37,7 @@
* [kickstart.service.start](kickstart/service/start)
* [kickstart.service.stop](kickstart/service/stop)
* [kickstart.stream.contains](kickstart/stream/contains)
* [kickstart.stream.template](kickstart/stream/template)
* [kickstart.user.add_group](kickstart/user/add_group)
* [kickstart.user.create](kickstart/user/create)
* [kickstart.user.exec](kickstart/user/exec)

View File

@ -0,0 +1,18 @@
# kickstart.file.template file [positional arguments...]
Receives a file for templating, eval the arguments and return it.
It evals the file under the current environement, with the variables and functions available.
### Example
```bash
$ cat file
\$argument is $argument
$ argument=awesome kickstart.file.template file
$argument is awesome
$ cat file
$1, $2 and $3
$ kickstart.file.template file Alice Bob Eve
Alice, Bob and Eve
```

View File

@ -0,0 +1,16 @@
# kickstart.stream.template [positional arguments...]
Receives from stdin the template string, eval the arguments and return it.
It evals the stream under the current environement, with the variables and functions available.
### Example
```bash
$ echo '\$argument is $argument' | \
argument=awesome kickstart.stream.template
$argument is awesome
$ echo '$1, $2 and $3' | \
kickstart.stream.template Alice Bob Eve
Alice, Bob and Eve
```

View File

@ -6,3 +6,9 @@ kickstart.file.link() {
kickstart.file.contains() {
grep -q "$2" $1 2>/dev/null
}
kickstart.file.template() {
file=$1
shift
kickstart.stream.template "$@" < $file
}

View File

@ -1,3 +1,7 @@
kickstart.stream.contains() {
grep -q "$1" 2>/dev/null
}
kickstart.stream.template() {
eval "echo -e \"`cat`\""
}