Class: Bourdain::Commands::GenerateCommand
- Defined in:
- lib/bourdain/resources/commands/generate.rb
Instance Attribute Summary
Attributes inherited from Resource
#opts, #raw_usage, #resource_name, #spec, #status
Instance Method Summary collapse
-
#initialize(argv) ⇒ GenerateCommand
constructor
A new instance of GenerateCommand.
Methods inherited from Resource
log=, raw_usage, resource_name, usage
Constructor Details
#initialize(argv) ⇒ GenerateCommand
Returns a new instance of GenerateCommand.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bourdain/resources/commands/generate.rb', line 11 def initialize argv generators = Bourdain::Registry.specs('generator') maybe_generator_position = generators.map { |c| argv.index c[:name].to_s }.compact.shift generator_position = maybe_generator_position.nil? ? argv.length : maybe_generator_position generator_name = argv[generator_position] = argv.slice(0, generator_position) argv = argv.slice(generator_position, argv.length) super generator = nil generator = argv.shift unless maybe_generator_position.nil? Trollop::die 'Invalid <generator> provided' if generator.nil? generator = Bourdain::Registry.klass('generator', generator_name) Trollop::die 'Invalid <generator> provided' if generator.nil? @status = generator.new(argv).status end |