ammeter
ammeter copied to clipboard
Passing options to a generator
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.
I invoke it with run_generator["foo", "--sql bar"] but inside the generator options[:bar] is nil
Shouldn't that be options[:sql]
?
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 https://github.com/alexrothenberg/ammeter/issues/41#issuecomment-52022701 .
I believe it works if you separate the name and value like
run_generator["foo", "--sql", "bar"]