cargogenerateusername-on-github/mytemplate
# is the same ascargogenerategh:username-on-github/mytemplate
# is the same ascargogenerate--githttps://github.com/username-on-github/mytemplate.git
# for gitlab.comcargogenerategl:username-on-gitlab/mytemplate
Liquid テンプレート言語を使ってテンプレートを記述する。 テンプレートの中で{{variable}}のように記述すると、cargo generateの実行時にユーザー入力を求めることができる。 また、{{variable}}.rsのようなファイルを作るとテンプレート生成時に入力値を適用したファイルが生成される。 if 分岐や for 文による繰り返しもでき、hooksでinit、pre、postのフックを設定できる。
[placeholders.hypervisor]type="string"prompt="What hypervisor to use?"choices=["uhyve","qemu"]default="qemu"[placeholders.network_enabled]type="bool"prompt="Want to enable network?"default=true
[package]# the usual stuff[dependencies]{%ifcrate_type== "bin"%}structopt="0.3.21"{%endif%}# other general dependencies{%ifcrate_type== "bin"%}[[bin]]path="src/main.rs"name="{{crate_name}}-cli"{%endif%}