Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing options to a generator #41

Open
derekprior opened this issue Aug 8, 2014 · 3 comments
Open

Passing options to a generator #41

derekprior opened this issue Aug 8, 2014 · 3 comments

Comments

@derekprior
Copy link

I have a generator that inherits from NamedBase and defines a --sql class_option.

I invoke it with run_generator["foo", "--sql bar"] but inside the generator options[:bar] is nil. I looked at the implementation of run_generator and generator and saw that it's using Thor to parse the options. I verified that Thor::Options.splt works as expected on the array I'm passing to run_generator... and yet, still the option in nil in the generatornd it seems that indeed args and opts are getting set correctly. And yet, the option is still nil in my tests.

Compounding the problem (and limiting my normal debug tools) is that it seems pry does not work inside the generator. It works in my non-generator spec and even works when I run the generator from the command line, outside of my tests. But in my generator specs, pry opens but no statements return anything. I can call methods, non-existent methods, pry method -- none of them do anything.

The generator runs as expected when I try it from the command line so the problem is indeed limited to the specs.

@d4rky-pl
Copy link
Collaborator

I invoke it with run_generator["foo", "--sql bar"] but inside the generator options[:bar] is nil

Shouldn't that be options[:sql] ?

@derekprior
Copy link
Author

Yes. That was a typo in the issue. Still seems to be a problem.

On Wednesday, August 13, 2014, Michał Matyas [email protected]
wrote:

I invoke it with run_generator["foo", "--sql bar"] but inside the
generator options[:bar] is nil

Shouldn't that be options[:sql] ?


Reply to this email directly or view it on GitHub
#41 (comment)
.

@alexrothenberg
Copy link
Owner

I believe it works if you separate the name and value like

run_generator["foo", "--sql", "bar"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants