Puppet Function: simplib::hash_to_opts
- Defined in:
- functions/hash_to_opts.pp
- Function type:
- Puppet Language
Overview
Turn a hash into a options string, for use in a shell command
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'functions/hash_to_opts.pp', line 25
function simplib::hash_to_opts (
Hash[String,Variant[Array,String,Numeric,Boolean,Undef]] $input,
Struct[{
Optional[connector] => String[1],
Optional[prefix] => String[1],
Optional[repeat] => Enum['comma','repeat'],
Optional[delimiter] => String[1],
}] $opts = {}
) {
$connector = pick($opts['connector'], '=')
$prefix = pick($opts['prefix'], '--')
$repeat = pick($opts['repeat'], 'comma')
$delimiter = pick($opts['delimiter'], ',')
$out = $input.map |$key, $val| {
case $val {
default: { "${prefix}${key}${connector}${String($val).shellquote}" }
Undef: { "${prefix}${key}" }
Array: {
# lint:ignore:case_without_default
case $repeat {
'comma': { "${prefix}${key}${connector}${val.join($delimiter).shellquote}" }
'repeat': { $val.prefix("${prefix}${key}${connector}").shellquote }
}
# lint:endignore
}
}
}
$out.join(' ')
}
|