Class: Git::Trac::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/git/trac/runner.rb,
lib/git/trac/runner/help.rb,
lib/git/trac/runner/push.rb,
lib/git/trac/runner/show.rb,
lib/git/trac/runner/apply.rb,
lib/git/trac/runner/fetch.rb,
lib/git/trac/runner/cleanup.rb,
lib/git/trac/runner/checkout.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Fetchable Classes: Apply, Base, Checkout, Cleanup, Fetch, Help, Push, Show

Constant Summary collapse

UploadPatch =
Push

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Runner

Returns a new instance of Runner.



58
59
60
61
62
63
64
65
66
# File 'lib/git/trac/runner.rb', line 58

def initialize(argv)
  @argv = argv.dup
  run
rescue Git::Trac::Error
  $stderr.puts "Error: " + $!.message
  exit 1
rescue Interrupt
  $stderr.puts "Interrupted!"
end

Class Method Details

.commandsObject



23
24
25
# File 'lib/git/trac/runner.rb', line 23

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

.for_command(command) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/git/trac/runner.rb', line 13

def self.for_command(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 klass < Base
      return klass
    end
  end
end

Instance Method Details

#abort(message) ⇒ Object

Raises:



68
69
70
# File 'lib/git/trac/runner.rb', line 68

def abort(message)
  raise Git::Trac::Error, message
end

#general_usageObject



72
73
74
75
76
77
78
# File 'lib/git/trac/runner.rb', line 72

def general_usage
  $stderr.puts <<-EOS
Usage: git-trac <command> [options] [arguments]
See `git-trac help` for details.
  EOS
  exit 1
end

#runObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/git/trac/runner.rb', line 80

def run

  command = @argv.shift unless %w(-v --version).include?(@argv.first)
  repo = nil
  if command == "--repository"
    repo, command = @argv.shift, @argv.shift
  end
  command = "help" if %w(-h --help).include?(command)

  if klass = Runner.for_command(command || "help")
    return klass.new(@argv, repo)
  end

  general_usage

end