Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Make adding generators a bit easier #116

Closed
adamhjk opened this issue Jul 28, 2014 · 2 comments
Closed

Make adding generators a bit easier #116

adamhjk opened this issue Jul 28, 2014 · 2 comments
Labels
Type: Enhancement Adds new functionality.

Comments

@adamhjk
Copy link
Contributor

adamhjk commented Jul 28, 2014

When you create a new generator, you may wind up adding new command line functionality based on what the generator produces. For example, the 'chef repo' generator has a --policy-only flag, which probably only makes sense for that particular generator.

When you add them, you need to touch a couple of places:

  1. The option itself goes in the generator class
  2. The generator context needs to be added in lib/chef-dk/generator.rb
  3. The new context method needs to be proxied into the template helper.
  4. The value needs to be set in the new generator classes setup_context method

I propose we add some sugar to take the CLI options passed to the generator and automatically add them to the context and proxy via the global setup context. That way you can just map the option name to the context object.

Essentially, we add a bit of sugar to add methods to the Generator context and make sure they are proxied from the TemplateHelper, and then walk the config hash, adding items to the context dynamically.

@danielsdeleo
Copy link
Contributor

This all seems reasonable to me. In terms of the implementation (and I think this is what you were getting at), I'd prefer to stick with implementation choices that surface errors as quickly and clearly as possible. That's why I originally chose to use template helpers rather than variables; a misspelled instance variable is a warning (that you never see unless you run ruby -w) whereas a misspelled method name is an error. So something like:

class MySplendidGenerator < InheritsFromThing

  # really verbose method name for demonstration purposes
  option_that_threads_to_template_context :policy_only,
    # other mixlib-cli stuff
end

That could, I think, accomplish tasks 1-4 while still keeping the "rightness" or "wrongness" of your code as binary as possible (i.e., minimize opportunities for silent failures).

@danielsdeleo
Copy link
Contributor

I believe this is fixed via #118 please reopen if I'm wrong about that.

@jkeiser jkeiser removed the Discussion label Feb 9, 2016
@thommay thommay added Type: Enhancement Adds new functionality. and removed Enhancement labels Feb 1, 2017
@chef-boneyard chef-boneyard locked and limited conversation to collaborators Feb 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Enhancement Adds new functionality.
Development

No branches or pull requests

4 participants