class Swamp::CLI

Attributes

app_name[R]
commands[R]
version[RW]

Public Class Methods

new(app_name, options = {}) click to toggle source
# File lib/swamp/cli.rb, line 15
def initialize(app_name, options = {})
  @app_name = app_name
  @version = options[:version]
  @commands = {}
end

Public Instance Methods

add(command) click to toggle source
# File lib/swamp/cli.rb, line 21
def add(command)
  @commands[command.name.to_sym] = command
end
command(name) click to toggle source
# File lib/swamp/cli.rb, line 25
def command(name)
  @commands[name.to_sym]
end
dispatch(argv, *additional_args) click to toggle source
# File lib/swamp/cli.rb, line 29
def dispatch(argv, *additional_args)
  command_name = argv.shift
  if command_name && command = command(command_name)
    context = Context.new(self)
    context.options = command.parse_options(argv)
    context.args = argv

    command.action.call(context, *additional_args)
  else
    raise Error, "Command not found"
  end
end
load_from_directory(path) click to toggle source
# File lib/swamp/cli.rb, line 42
def load_from_directory(path)
  unless File.directory?(path)
    raise Error, "No commands directory at #{path}"
  end

  Dir[File.join(path, '**', '*.rb')].each do |path|
    CLIDSL.new(self).instance_eval(File.read(path), path)
  end
end