Issue #3300 has been updated by Nate Walck.

The solution presented here by Roman is much cleaner than what was provided.  
This type of functionality seems necessary if you are working with a command 
line tool that requires a list of arguments and you want the ability to 
optionally set some of these arguments.

Example:

/usr/bin/somecommand --mandatory1 some_option1 --mandatory2 some_option2 
--optional1 some_option3 --optional2 some_option4 --optional3 some_option5

Using the solution above, we would have to create a bunch of if else statements 
to account for each and every possible combination. On one command I need to 
puppetize (dsconfigad on os x), there are around 15 options, some mandatory and 
some default.  This would lead to an extremely unwieldy set of logic using the 
solution proposed above.  It seems more puppet-like to be able to check if the 
option is undef or not and then append it to the $commandline_options variable 
in the correct case.

If a variable cannot be appended in the scope in which it is defined, then what 
is the solution we should use for this?  I know this request is rather old, so 
perhaps there is something better that can be done today that did not exist 
when it was originally created.

Thanks!

----------------------------------------
Feature #3300: appending to variables already defined in this scope
https://projects.puppetlabs.com/issues/3300#change-96477

* Author: Xavier Delaruelle
* Status: Re-opened
* Priority: Normal
* Assignee: Nigel Kersten
* Category: parser
* Target version: 
* Affected Puppet version: 0.25.4
* Keywords: 
* Branch: 
----------------------------------------
Hello,

As mentioned in the doc, it is possible since 0.24.6 to append to variables 
already defined in a different scope. But when appending to a variable already 
defined in the scope, like in the following example:

<pre>
define foo ($val) {
    $bar = [ 'val1', 'val2' ]

    if $val != '' {
        $bar += [ $val ]
    }
}
</pre>

puppet returns the following error:
<pre>
Cannot append, variable bar is defined in this scope at /tmp/test.pp:8 on node 
host
</pre>
Appending to variables already defined in the scope could be useful when we 
want to adapt the behavior of a class or a define depending of variable values.



-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to