Eugene Ventimiglia
2007-Dec-24 16:32 UTC
Build a cmdline for exec from optional parameters
How can I do this?: foo { name: $bar => "frob" } define foo( $bar = false, $baz = false ) { if #$bar and $baz both defined $cmd = "frobnicate --bar=$bar --baz=$baz ${name}" else if #$bar defined $cmd = "frobnicate --bar=$bar ${name}" else if #$baz defined $cmd = "frobnicate --baz=$baz ${name}" else $cmd = "frobnicate ${name}" } This works for 2 optional parameters, but doesn''t scale Thanks --e Eugene Ventimiglia Director of Systems GridApp Systems e: eventi@gridapp.com o: 646 452 4081 _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
On Dec 24, 2007, at 10:32 AM, Eugene Ventimiglia wrote:> How can I do this?: > > foo { name: > $bar => "frob" > } > > define foo( $bar = false, $baz = false ) { > if #$bar and $baz both defined > $cmd = "frobnicate --bar=$bar --baz=$baz ${name}" > else if #$bar defined > $cmd = "frobnicate --bar=$bar ${name}" > else if #$baz defined > $cmd = "frobnicate --baz=$baz ${name}" > else > $cmd = "frobnicate ${name}" > } >Hrm. The only real options are to make a new string variable for every parameter (just extending it with "" when no value is provided) or use a custom function to concatenate them all. -- A motion to adjourn is always in order. --Robert Heinlein --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
Eugene Ventimiglia
2007-Dec-28 13:23 UTC
Re: Build a cmdline for exec from optional parameters
That''s what I wound up doing: $kickstart_opt = $kickstart ? { false => '''', default => " --kickstart=/var/lib/cobbler/kickstarts/${kickstart}" } $kickstart_test = $kickstart ? { false => "grep \"kickstart\\s*: <<inherit>>\"", default => "grep \"kickstart\\s*: /var/lib/cobbler/kickstarts/${kickstart}\"" } $ip_opt = $ip ? { false => '''', default => " --ip=${ip}" } $ip_test = $ip ? { false => "grep \"ip address\\s*:\\s*$\"", default => "grep \"ip address\\s*: ${ip}\"" } $hostname_opt = $hostname ? { false => " --hostname=${name}", default => " --hostname=${hostname}" } $hostname_test = $hostname ? { false => "grep \"hostname\\s*: ${name}\"", default => "grep \"hostname\\s*: ${hostname}\"" } $addcmd = "cobbler system add --name=${name} --profile=${profile} --mac=${mac} \ ${kickstart_opt}${ip_opt}${hostname_opt}" $editcmd = "cobbler system edit --name=${name} --profile=${profile} --mac=${mac} \ ${kickstart_opt}${ip_opt}${hostname_opt}" -----Original Message----- From: puppet-users-bounces@madstop.com [mailto:puppet-users-bounces@madstop.com] On Behalf Of Luke Kanies Sent: Thursday, December 27, 2007 8:21 PM To: Puppet User Discussion Subject: Re: [Puppet-users] Build a cmdline for exec from optional parameters On Dec 24, 2007, at 10:32 AM, Eugene Ventimiglia wrote:> How can I do this?: > > foo { name: > $bar => "frob" > } > > define foo( $bar = false, $baz = false ) { > if #$bar and $baz both defined > $cmd = "frobnicate --bar=$bar --baz=$baz ${name}" > else if #$bar defined > $cmd = "frobnicate --bar=$bar ${name}" > else if #$baz defined > $cmd = "frobnicate --baz=$baz ${name}" > else > $cmd = "frobnicate ${name}" > } >Hrm. The only real options are to make a new string variable for every parameter (just extending it with "" when no value is provided) or use a custom function to concatenate them all. -- A motion to adjourn is always in order. --Robert Heinlein --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users