2 个版本
| 0.0.2 | 2021年1月15日 |
|---|---|
| 0.0.1 | 2021年1月15日 |
#440 在 模板引擎
11KB
101 行
hbsenvsubst
替换环境变量的值,但使用handlebars。
关于
基本上,hbsenvsubst 的想法与 envsubst 类似,但它使用 handlebars 而不是 shell 语法。
请注意,目前,hbsenvsubst 应被视为一个快速构建的原型,用于实验这个想法,所以您的体验可能会有所不同。
用法
hbsenvsubst < some-file-in > some-file-out
示例
一个类似这样的handlebars输入示例
#!/bin/bash
echo "hello {{env.USER}}"
在 USER 环境变量为 "foo" 的情况下,应生成 hello foo。
功能
目前handlebars中有三个可访问的对象
env- 环境变量mem-
free- 系统空闲内存
-
total- 系统总内存
-
used- 系统已用内存
cpu-
logical- 物理CPU的数量
-
physical- 逻辑CPU的数量
此外,还有一些额外的助手函数
add- 加法-
{{add 2 2}}生成4
div- 除法-
{{div 4 2}}生成2
mod- 取模-
{{mod 4 3}}生成1
mul- 乘法-
{{mul 3 3}}生成9
sub- 减法-
{{sub 8 5}}得到3
rust-handlebars 包还包含一些内置助手函数
ifunlesslogeachwitheqnegtgteltlteandornot
许可证
MIT 许可证
依赖项
~10–23MB
~316K SLoC