class Dopstick::CLI

Public Class Methods

exit_on_failure?() click to toggle source
# File lib/dopstick/cli.rb, line 8
def self.exit_on_failure?
  true
end

Public Instance Methods

dup_options() click to toggle source
# File lib/dopstick/cli.rb, line 106
        def dup_options
  options.each_with_object({}) do |(key, value), buffer|
    buffer[key.to_sym] = value
  end
end
expand_gem_name_and_namespace(path) click to toggle source
# File lib/dopstick/cli.rb, line 112
        def expand_gem_name_and_namespace(path)
  if options[:name].presence && options[:namespace].presence
    [options[:name], options[:namespace]]
  elsif options[:name].presence
    [options[:name], options[:name].camelize]
  elsif options[:namespace].presence
    [options[:namespace].underscore("-"), options[:namespace]]
  else
    [File.basename(path), File.basename(path).camelize]
  end
end
interrupt_with_error(message) click to toggle source
# File lib/dopstick/cli.rb, line 101
        def interrupt_with_error(message)
  shell.say "ERROR: #{message}", :red
  exit 1
end
interrupt_with_help(command) click to toggle source
# File lib/dopstick/cli.rb, line 96
        def interrupt_with_help(command)
  help(command)
  exit
end
new(path = nil) click to toggle source
# File lib/dopstick/cli.rb, line 68
def new(path = nil)
  interrupt_with_help(:new) if options[:help] || path.to_s.strip.empty?

  unless Generator.registered.include?(options[:type])
    interrupt_with_error(
      "--type must be one of #{Generator.registered.keys.inspect}"
    )
  end

  package_name, namespace = expand_gem_name_and_namespace(path)

  generator_module = Generator.registered[options[:type]]
  generator_class = generator_module.const_get(:Generator)
  options_class = generator_module.const_get(:Options)
  generator = generator_class.new
  generator.destination_root = File.expand_path(path)
  generator.options = options_class.new(
    dup_options.merge(
      package_name: package_name,
      namespace: namespace,
      entry_path: namespace.underscore("/")
    )
  )

  generator.invoke_all
end