Class: SolidRuby::ProjectCli

Inherits:
Thor
  • Object
show all
Defined in:
lib/solidruby/project_cli.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/solidruby/project_cli.rb', line 5

def method_missing(method, *args, &block)
  # Split args that look like options (i.e start with - or --) into a separate array
  _, opts = Thor::Options.split(args)
  # add all parameter options
  yml = SolidRuby::Parameters::Parameters.load_yml
  yml_options = { "--variant" => Thor::Option.new("--variant") }
  yml.each do |_, params|
    params.each do |name, _|
      yml_options["--#{name.gsub('_', '-')}"] = Thor::Option.new("--#{name.gsub('_', '-')}")
    end
  end

  parser = Thor::Options.new(yml_options)

  # The options hash is frozen in #initialize so you need to merge and re-assign
  self.options = options.merge(parser.parse(opts)).freeze

  # Dispatch the command
  send(:dynamic_params, options)
end