Class: Pickler::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/pickler/runner.rb

Defined Under Namespace

Classes: Base

Constant Summary collapse

COLORS =
{
  :black   => 0,
  :red     => 1,
  :green   => 2,
  :yellow  => 3,
  :blue    => 4,
  :magenta => 5,
  :cyan    => 6,
  :white   => 7
}
STATE_COLORS =
{
  nil           => COLORS[:black],
  "rejected"    => COLORS[:red],
  "accepted"    => COLORS[:green],
  "delivered"   => COLORS[:yellow],
  "unscheduled" => COLORS[:white],
  "started"     => COLORS[:magenta],
  "finished"    => COLORS[:cyan],
  "unstarted"   => COLORS[:blue]
}
STATE_SYMBOLS =
{
  "unscheduled" => "  ",
  "unstarted"   => ":|",
  "started"     => ":/",
  "finished"    => ":)",
  "delivered"   => ";)",
  "rejected"    => ":(",
  "accepted"    => ":D"
}
TYPE_COLORS =
{
  'chore'   => COLORS[:blue],
  'feature' => COLORS[:magenta],
  'bug'     => COLORS[:red],
  'release' => COLORS[:cyan]
}
TYPE_SYMBOLS =
{
  "feature" => "*",
  "chore"   => "%",
  "release" => "!",
  "bug"     => "/"
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Runner

Returns a new instance of Runner.



441
442
443
# File 'lib/pickler/runner.rb', line 441

def initialize(argv)
  @argv = argv
end

Class Method Details

.[](command) ⇒ Object



182
183
184
185
186
187
188
189
190
# File 'lib/pickler/runner.rb', line 182

def self.[](command)
  klass_name = command.to_s.capitalize.gsub(/[-_](.)/) { $1.upcase }
  if klass_name =~ /^[A-Z]\w*$/ && const_defined?(klass_name)
    klass = const_get(klass_name)
    if Class === klass && klass < Base
      return klass
    end
  end
end

.command(name, &block) ⇒ Object



196
197
198
# File 'lib/pickler/runner.rb', line 196

def self.command(name, &block)
  const_set(name.to_s.capitalize.gsub(/[-_](.)/) { $1.upcase },Class.new(Base,&block))
end

.commandsObject



192
193
194
# File 'lib/pickler/runner.rb', line 192

def self.commands
  constants.map {|c| Runner.const_get(c)}.select {|c| Class === c && c < Runner::Base}.sort_by {|r| r.command_name}.uniq
end

Instance Method Details

#runObject



491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
# File 'lib/pickler/runner.rb', line 491

def run
  command = @argv.shift
  if klass = self.class[command]
    result = klass.new(@argv).run
    exit result.respond_to?(:to_int) ? result.to_int : 0
  elsif ['help', '--help', '-h', '', nil].include?(command)
    puts "usage: pickler <command> [options] [arguments]"
    puts
    puts "Commands:"
    self.class.commands.each do |command|
      puts "    %-19s %s" % [command.command_name, command.summary]
    end
    puts
    puts "Run pickler <command> --help for help with a given command"
  else
    raise Error, "Unknown pickler command #{command}"
  end
rescue Pickler::Error
  $stderr.puts "#$!"
  exit 1
rescue Interrupt
  $stderr.puts "Interrupted!"
  exit 130
end