Issue #6787 has been updated by Daniel Pittman.

Status changed from Accepted to Merged - Pending Release
Target version changed from 2.7.x to 2.7.3

This is now supported; 
https://github.com/puppetlabs/puppet/commit/691554ce752b631ae09bb87762b7bb9fcbe68e68
 merges this into 2.7.x for the next release.

This only supports code-based defaults: pass a block to `default_to` and it 
will be invoked.  This puts any burden of mutability of the default value on 
the user of `default_to`, which seems a pile saner than trying to enforce it 
generically ourselves.  (It also means that if people want to, they can have 
stateful defaults, even if that is probably not a good idea.  Not that we 
really could have stopped them before and all...)

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

Author: Pieter van de Bruggen
Status: Merged - Pending Release
Priority: Normal
Assignee: Daniel Pittman
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-bugs?hl=en.

Reply via email to