複数の設定ファイルを一気に生成したい
複数の設定ファイルを一気に生成したかった。zenmaiにその機能を持たせても良かったのだけれど。そうするとdictに対するtransformer的な意味合いとは異なった何かになってしまう。
単純にyamlを受け取って、その値を特定のディレクトリ上に転写するコマンドを作れば良い事に気づいた。 そんなわけで、nejimaki というパッケージを作った。 こういう感じで使う。
$ zenmai data.yaml | nejimaki --position=foo/bar
詳細
./
で始まるものをディレクトリとして認識する。例えば以下のようなファイルの場合
# data.yaml ./conf: ./base: base.json: logging: asctime: 2013-04-10 15:39:26,014 created: 1365604766.014612 levelname: INFO message: test message name: logger_name dev.json: debug: true $inherits: "./base/base.json" staging.json: debug: false $inherits: "./base/base.json" production.json: $inherits: "./staging.json"
以下の様に転写される。
$ nejimaki examples/readme/data.yaml --position=examples/readme INFO nejimaki emit:conf/base/base.json INFO nejimaki emit:conf/dev.json INFO nejimaki emit:conf/staging.json INFO nejimaki emit:conf/production.json $ tree examples/readme/conf examples/readme/conf ├── base │ └── base.json ├── dev.json ├── production.json └── staging.json 1 directory, 4 files
$ cat examples/readme/conf/base/base.json { "logging": { "asctime": "2013-04-10 15:39:26,014", "created": 1365604766.014612, "levelname": "INFO", "message": "test message", "name": "logger_name" } }