Module: Aladdin::Commands

Extended by:
Commands
Included in:
Commands
Defined in:
lib/aladdin/commands.rb,
lib/aladdin/commands/new.rb,
lib/aladdin/commands/server.rb

Overview

Parses the command line arguments and invokes the relevant command.

Examples:

Adding a command

Commands.register do
  def new
    # do stuff
  end
end

Defined Under Namespace

Modules: New, Server

Constant Summary collapse

USAGE =

Path to USAGE file.

File.join File.dirname(__FILE__), *%w(commands/USAGE)

Instance Method Summary collapse

Instance Method Details

#parse!(argv = ARGV, opts = {}) ⇒ Object

Parses the command line arguments.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/aladdin/commands.rb', line 26

def parse!(argv=ARGV, opts={})
  command = argv.shift
  case command
  when '--version', '-v'
    puts "Aladdin #{Aladdin::VERSION}"
    exit 0
  when nil, '--help', '-h'
    puts File.read USAGE
    exit 0
  else
    require_relative 'commands/new'
    require_relative 'commands/server'
    send command, argv, opts
  end
rescue => e
  puts e.message
  puts File.read USAGE
  exit 1
end

#register(&block) ⇒ Object

Registers a new command.



21
22
23
# File 'lib/aladdin/commands.rb', line 21

def register(&block)
  extend Module.new(&block)
end