Puppet Function: wmflib::argparse

Defined in:
modules/wmflib/functions/argparse.pp
Function type:
Puppet Language

Overview

wmflib::argparse(Hash[String[2], Variant[Boolean, String, Numeric, Array[Variant[String, Numeric]]]] $args, String $prefix = '')String

Examples:

wmflib::argparse({hostname => 'foo.example.org', port => 8080, ssl => true}) =>
 '--hostname foo.example.org --port 8080 --ssl'

Parameters:

  • args (Hash[String[2], Variant[Boolean, String, Numeric, Array[Variant[String, Numeric]]]])
  • prefix (String) (defaults to: '')

Returns:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'modules/wmflib/functions/argparse.pp', line 6

function wmflib::argparse (
    Hash[String[2], Variant[Boolean, String, Numeric, Array[Variant[String, Numeric]]]] $args,
    String                                                                              $prefix = '',
) >> String {
    $args.reduce($prefix) |$memo, $value| {
        $args_str = $value[1] ? {
            Boolean => $value[1].bool2str(" --${value[0]}", ''),
            Array   => " --${value[0]} ${value[1].join(',').shell_escape}",
            # handle spaces, double quotes, etc.
            default => " --${value[0]} ${value[1].shell_escape}",
        }
        "${memo}${args_str}".strip
    }
}