Class: Git::Trac::Runner::Help

Inherits:
Base
  • Object
show all
Defined in:
lib/git/trac/runner/help.rb

Overview

:nodoc:

Constant Summary collapse

TOPICS =
{}

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#abort, #add_local_option, command, #command, #each_attachment, #each_ticket_or_attachment, #fetch_or_abort, #fetch_unless_local, #initialize, #missing_argument, #one_attachment, #options, #parse_attachment, #repository, #system, #too_many_arguments

Constructor Details

This class inherits a constructor from Git::Trac::Runner::Base

Class Method Details

.summaryObject



7
8
9
# File 'lib/git/trac/runner/help.rb', line 7

def self.summary
  "Help for a command or topic"
end

Instance Method Details

#add_options(opts) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/git/trac/runner/help.rb', line 15

def add_options(opts)
  @options = {} # Don't try to read the repository config
  opts.on("--commands","list all commands") do |commands|
    options[:commands] = commands
  end
  opts.on("--topics","list all topics") do |topics|
    options[:topics] = topics
  end
end


11
12
13
# File 'lib/git/trac/runner/help.rb', line 11

def banner_arguments
  "[<command> | --commands | <topic> | --topics]"
end

#commandsObject



31
32
33
34
35
# File 'lib/git/trac/runner/help.rb', line 31

def commands
  Runner.commands.map do |runner|
    [runner.command, runner.summary]
  end
end

#defaultObject



62
63
64
65
66
67
68
69
# File 'lib/git/trac/runner/help.rb', line 62

def default
  out = "Usage: git-trac <command> [options] [arguments]\n"
  out << "\nCommands:\n"
  out << commands.map {|t| "        %-15s %s\n" % t}.join
  out << "\nHelp topics:\n"
  out << topics.map {|t| "        %-15s %s\n" % t}.join
  out << "\nUse git-trac help <command> or git-trac help <topic> for further information.\n"
end

#descriptionObject



25
26
27
28
29
# File 'lib/git/trac/runner/help.rb', line 25

def description
  <<-EOF
Show help for a given topic or command.
  EOF
end

#runObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/git/trac/runner/help.rb', line 43

def run
  topic = @argv.first
  if options[:commands]
    puts commands.map {|t| "%-15s %s\n" % t}.join
  elsif options[:topics]
    puts topics.map {|t| "%-15s %s\n" % t}.join
  elsif !topic
    Pager.new.page(default)
  elsif klass = Runner.for_command(topic)
    return klass.new(["--help"],nil)
  elsif TOPICS[topic]
    body = TOPICS[topic].last
    body = body.call(self) if body.respond_to?(:call)
    Pager.new.page(body)
  else
    abort "no such topic #{topic}"
  end
end

#topicsObject



37
38
39
40
41
# File 'lib/git/trac/runner/help.rb', line 37

def topics
  TOPICS.keys.compact.sort.map do |key|
    [key, TOPICS[key].first]
  end
end