Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9344616
flatten_to_argument_list.rb
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
flatten_to_argument_list.rb
View Options
require
'shellwords'
Puppet
::
Functions
.
create_function
(
:flatten_to_argument_list
)
do
dispatch
:flatten_to_argument_list
do
param
'Hash'
,
:variable
optional_param
'String'
,
:escaping_type
optional_param
'String'
,
:prefix
return_type
'Array[String]'
end
def
flatten_to_argument_list
(
variable
,
escaping_type
=
'systemd'
,
prefix
=
'--'
)
ret
=
[]
variable
.
each
do
|
key
,
value
|
arg
=
"
#{
prefix
}#{
key
}
"
.
gsub
(
'_'
,
'-'
)
if
Hash
===
value
ret
+=
flatten_to_argument_list
(
value
,
escaping_type
,
"
#{
arg
}
."
)
else
if
value
==
true
ret
.
push
(
arg
)
else
if
escaping_type
==
'systemd'
# This replaces every backslash with four backslashes to please
# systemd's EnvironmentFile escaping. Yes, gsub needs four
# backslashes per output backslash.
value
.
gsub!
(
'
\\
'
,
'
\\\\\\\\\\\\\\\\
'
)
elsif
escaping_type
==
'shell'
value
=
Shellwords
.
escape
(
value
)
end
ret
.
push
(
"
#{
arg
}
=
#{
value
}
"
)
end
end
end
ret
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Fri, Jul 4, 2:37 PM (3 d, 14 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3241890
Attached To
rSPPROF puppet-swh-profile
Event Timeline
Log In to Comment