Issue #6787 has been updated by Daniel Pittman.

Assignee deleted (Daniel Pittman)

----------------------------------------
Feature #6787: Introduce option defaulting behavior
https://projects.puppetlabs.com/issues/6787#change-92323

* Author: Pieter van de Bruggen
* Status: Closed
* Priority: Normal
* Assignee: 
* Category: Faces
* Target version: 2.7.3
* Affected Puppet version: 2.7.0rc1
* Keywords: 
* Branch: 
----------------------------------------
Actions should be able to specify the default values to use for unspecified 
options.

Additionally, since an interface may wish to specify a default for options for 
all included actions, defaults should be providable at this level as well.

Certain options (like `--format`) additionally seem like they would benefit 
from a "global" default.

Setting defaults should require extended option declarations; no shorthand:

<pre>
option "--foo BAR" do
    default_to 12
end
</pre>

If `default_to` gets a lambda, it should call it with no arguments if a default 
value is needed, and use the return value as the setting, as if we wrote:

<pre>
options[:foo] ||= lambda { … }.call
</pre>

We should totally support blocks for that, so this syntax works:

<pre>
option "--foo" do
  default_to do
    "whatever you want"
  end
end
</pre>

Supporting literal objects as default values is possible, but if you provide a 
literal object, it should be impossible to mutate that.  If we use `freeze` to 
manage this, we should make that a "deep" freeze: no mutation of contained 
objects.  eg: this should fail:

<pre>
  default = { 1 => ["one"] }.freeze
  default[1] << "two"
</pre>

Duplication of the data is acceptable, if desired, to return mutable but 
independent defaults, provided that this is a deep clone.

Users should be encouraged to provide a lambda, and if they need mutable 
defaults to use that to provide them.  I am generally in favour of a solution 
that starts with *only* supporting blocks, and then adds literals later, as the 
minimum viable version of this.


-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to