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.



464
465
466
# File 'lib/pickler/runner.rb', line 464

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



514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'lib/pickler/runner.rb', line 514

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