Sha256: 467dc37c1d64ade2988fbb453df645c4b142b38967fc6abd122332252931acda

Contents?: true

Size: 1.01 KB

Versions: 5

Compression:

Stored size: 1.01 KB

Contents

# ~*~ encoding: utf-8 ~*~
require 'aladdin/version'

Signal.trap('INT') { puts; exit(1) }

module Aladdin

  # Parses the command line arguments and invokes the relevant command.
  # @example Adding a command
  #   Commands.register do
  #     def new
  #       # do stuff
  #     end
  #   end
  module Commands

    # Path to USAGE file.
    USAGE = File.join File.dirname(__FILE__), *%w(commands/USAGE)

    # Registers a new command.
    def register(&block)
      extend Module.new(&block)
    end

    # Parses the command line arguments.
    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

    extend self

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
aladdin-0.2 lib/aladdin/commands.rb
aladdin-0.1.0.pre.1 lib/aladdin/commands.rb
aladdin-0.1.0.pre lib/aladdin/commands.rb
aladdin-0.0.8 lib/aladdin/commands.rb
aladdin-0.0.7 lib/aladdin/commands.rb