The purpose of this project is to generate config overrides so that we can keep a template up to date, and populate values on the fly with ease at build time.
Grab a binary for your OS from the latest release, and put it somewhere in your PATH.
brew tap cvent/tap
brew install hogan
curl -LSfs https://japaric.github.io/trust/install.sh | sh -s -- --git cvent/hogan --target x86_64-unknown-linux-gnu --to /usr/local/bin
You can run the tests via cargo test
. The tests should always pass and all new behavior should be tested.
Once you have installed hogan, you can execute it as hogan
.
Some of the arguments are described below:
environments-filter
: Regex specifying which environment(s) to update.templates
: The directory to use for searching for template files (recursively).configs
: The directory where hogan-formatted config files can be found (These are config.ENVIRONMENT.json files)
hogan transform --environments-filter ENVIRONMENT --templates . --configs ./Configs
You can also create an alias of the above command and add to bash_profile
hg() { hogan transform --configs ~/cventcode/hogan-configs/configs/ --templates . --templates-filter "$1" --environments-filter "$2"; }
and then use the alisa to generate config like
hg tempate.yaml prod
this will generate the config for prod environment using template.yaml as template file.
The following custom handlers exist
Allows an array of objects to be turned into a comma separated list by passing in an array:
// Given a config of:
let config = json!({
"Memcache": {
"Servers": [
{
"Endpoint": "192.168.1.100",
"Port": "1122"
},
{
"Endpoint": "192.168.1.101",
"Port": "1122"
},
{
"Endpoint": "192.168.1.102",
"Port": "1122"
}
]
}
});
// and a template of:
let template = "{{#comma-list Memcache.Servers}}{{Endpoint}}:{{Port}}{{/comma-list}}";
// The helper will transform it into:
let transformed = "192.168.1.100:1122,192.168.1.101:1122,192.168.1.102:1122";
Like if
, but compares the two arguments provided for equality:
// Given a config of:
let config = json!({
"Region": {
"Key": "TEST"
}
});
// and a template of:
let template = r#"{{#equal Region.Key "TEST"}}True{{else}}False{{/equal}}"#;
// The helper will transform it into:
let transformed = "True";
Logical OR two parameters:
// Given a config of:
let config = json!({
"Region": {
"Key": "TEST"
}
});
// and a template of:
let template = r#"{{#or (eq Region.Key "TEST") (eq Region.Key "TEST2")}}True{{else}}False{{/or}}"#;
// The helper will transform it into:
let transformed = "True";
Escapes a string for valid injection into a Yaml file:
// Given a config of:
let config = json!({
"app": {
"path": "C:\\Program Files\\My App"
}
});
// and a template of:
let template = r#"windows:
path: "{{yaml-string app.path}}""#;
// The helper will transform it into:
let transformed = r#"windows:
path: "C:\\Program Files\\My App""#;
Removes the trailing slash on an endpoint:
// Given a config of:
let config = json!({
"SlashService": {
"endpoint": "https://slash.com/"
}
});
// and a template of:
let template = "{{url-rm-slash SlashService.endpoint}}";
// The helper will transform it into:
let transformed = "https://slash.com";
Adds the trailing slashes on an endpoint:
// Given a config of:
let config = json!({
"NonSlashService": {
"endpoint": "https://nonslash.com"
}
});
// and a template of:
let template = "{{url-add-slash NonSlashService.endpoint}}";
// The helper will transform it into:
let transformed = "https://nonslash.com/";
Removes the last slash plus content to the end of the string:
// Given a config of:
let config = json!({
"PathService": {
"endpoint": "https://path.com/path/remove-this"
}
});
// and a template of:
let template = "{{url-rm-path PathService.endpoint}}";
// The helper will transform it into:
let transformed = "https://path.com/path";