On Thu, Apr 28, 2011 at 8:01 PM, Daniel Pittman <[email protected]> wrote: > Previously we would try and send `nil` to a class to render an unsupported > format, which was bad. Worse, we would only discover this *after* the fact, > when we tried to render, so the entire action had run and the result was lost > to the world. > > Instead, validate the parameter early and fail during option parsing. This > has less nice error reporting than we can get handling it later[1], but it > gets us a much better overall set of behaviour. > > [1] puppet/application.rb will print and exit, rather than raising, when the > option handler fails; this will improve when we unify face and application > options properly. > > Reviewed-By: Max Martin <[email protected]> > --- > lib/puppet/application/face_base.rb | 20 ++++++++++---------- > spec/unit/application/face_base_spec.rb | 13 +++++++++++++ > 2 files changed, 23 insertions(+), 10 deletions(-) > > diff --git a/lib/puppet/application/face_base.rb > b/lib/puppet/application/face_base.rb > index cc62257..d28a8af 100644 > --- a/lib/puppet/application/face_base.rb > +++ b/lib/puppet/application/face_base.rb > @@ -15,8 +15,14 @@ class Puppet::Application::FaceBase < Puppet::Application > Puppet::Util::Log.level = :info > end > > - option("--render-as FORMAT") do |arg| > - @render_as = arg.to_sym > + option("--render-as FORMAT") do |_arg| > + format = _arg.to_sym > + unless @render_method = Puppet::Network::FormatHandler.format(format) > + unless format == :for_humans or format == :json > + raise ArgumentError, "I don't know how to render '#{format}'" > + end > + end > + @render_as = format > end >
Out of curiosity, what's the reason for the rename from arg to _arg here? -- You received this message because you are subscribed to the Google Groups "Puppet Developers" 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-dev?hl=en.
