class Ella::CLI

The code for handling command-line arguments was getting complicated and ugly, so now it is a class. This is the least-integral part of Ella, and everything here should be replaceable without having to change the non-static classes.

Public Class Methods

new(args) click to toggle source
# File lib/ella/cli.rb, line 9
def initialize(args)
  @args = args
  @errors = []

  try_no_args
  try_help
  try_new_project
  try_mvc
  try_destroy
  try_server
  try_test

  exit_with_help('Ella does not understand your command.')
end

Private Instance Methods

exit_with_help(message) click to toggle source
# File lib/ella/cli.rb, line 76
def exit_with_help(message)
  Log.error(message) if message
  print_help
  exit
end
print_help() click to toggle source
try_destroy() click to toggle source
# File lib/ella/cli.rb, line 55
def try_destroy
  return unless ['d', 'destroy'].include?(@args[0])

  Destroyer.new(directory: @args[1]).run
  exit
end
try_help() click to toggle source
# File lib/ella/cli.rb, line 32
def try_help
  return unless ['h', 'help', '?'].include?(@args[0])

  exit_with_help(nil)
end
try_mvc() click to toggle source
# File lib/ella/cli.rb, line 46
def try_mvc
  return unless @args[0] =~ /^[mvc]*$/

  ModelGenerator.new(directory: @args[1]).run if @args[0] =~ /m/
  ViewGenerator.new(directory: @args[1], files: @args[2..-1]).run if @args[0] =~ /v/
  ControllerGenerator.new(directory: @args[1], files: @args[2..-1]).run if @args[0] =~ /c/
  exit
end
try_new_project() click to toggle source
# File lib/ella/cli.rb, line 38
def try_new_project
  return unless ['n', 'new'].include?(@args[0])

  exit_with_help('You need to give your project a name.') if @args[1].nil?
  ProjectGenerator.new(directory: @args[1]).run
  exit
end
try_no_args() click to toggle source
# File lib/ella/cli.rb, line 26
def try_no_args
  return unless @args[0].nil?

  exit_with_help('No arguments given.')
end
try_server() click to toggle source
# File lib/ella/cli.rb, line 62
def try_server
  return unless ['s', 'server', 'r', 'run'].include?(@args[0])

  Server.new(mode: @args[1] || 'development', port: @args[2]).run
  exit
end
try_test() click to toggle source
# File lib/ella/cli.rb, line 69
def try_test
  return unless ['t', 'test'].include?(@args[0])

  Test.run
  exit
end