Skip to content

Latest commit

 

History

History
67 lines (41 loc) · 2.51 KB

README.md

File metadata and controls

67 lines (41 loc) · 2.51 KB

mktpl

mktpl は YAML データと text/template の記法に従ったテンプレートを使ってテキストを標準出力にレンダリングするコマンドラインツールです。

Description

  • コマンドオプションで YAML 形式のデータファイルと text/template スタイルのテンプレートファイルのパスを指定すると、テキストが標準出力にレンダリングされる。
  • YAML データファイルではハッシュの値にキーを指定することができる。
  • 独自のテンプレート関数を実装している。
  • Masterminds/sprig: Useful template functions for Go templates. も使える。

Demonstration

demo

Motivation

  • ロジックレスでシンプルなテンプレートエンジンの、mustache というものがある。
  • Bash で実装された CLI もあるが、データの受け渡しがシェル変数または環境変数としてしか渡せず、データが増えてくるとつらい。
  • ロジックレスなテンプレートが売りだが、やっぱり多少はロジックを含めたい。

Installation

Releases ページからダウンロードしてください。

Usage

$ mktpl --help
mktpl is a tool to render Golang text/template with template and YAML data files.

Usage:
  mktpl flags

Flags (* is mandatory):
  -d, --data string       path to the YAML data file (*)
  -t, --template string   path to the template file (*)

  -h, --help              help for mktpl
  -v, --version           show program's version information and exit

Template Functions

{{ implode list separator }}

Same as strings.Join function.

{{ exec command [flags] [args] }}

Execute single external command and return it's stdout output.
Single means that no pipe (|), no redirection (>), no command connection (&, &&, ;, ||).
Arbitrary commands can be executed. Be very careful when using it.

{{ exclude list string... }}

Return a new list which is excluded specified strings from the elements in specified list.

License

The MIT License (MIT)

Author

Yuta MASANO