Class: Gerrit::Cli::Command::Help
- Inherits:
-
Base
- Object
- Base
- Gerrit::Cli::Command::Help
show all
- Defined in:
- lib/gerrit/cli/command/help.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#option_parser
Instance Method Summary
collapse
Methods inherited from Base
#name, #show_usage, #summary
Constructor Details
#initialize(logger, commands) ⇒ Help
Returns a new instance of Help.
9
10
11
12
13
14
15
16
17
|
# File 'lib/gerrit/cli/command/help.rb', line 9
def initialize(logger, commands)
super(logger)
@commands = commands.dup.merge(self.name => self)
rows = @commands.keys.sort.map {|k| [k, @commands[k].summary] }
@commands_summary = Gerrit::Cli::Util.render_table(rows,
:delimiter => ' ')
end
|
Instance Attribute Details
#commands_summary ⇒ Object
Returns the value of attribute commands_summary.
7
8
9
|
# File 'lib/gerrit/cli/command/help.rb', line 7
def commands_summary
@commands_summary
end
|
Instance Method Details
#run(argv) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/gerrit/cli/command/help.rb', line 33
def run(argv)
args = @option_parser.parse(argv)
case args.length
when 1
if command = @commands[args[0]]
command.show_usage
else
raise Gerrit::Cli::UsageError.new("Unknown command '#{args[0]}'")
end
when 0
show_usage
else
raise Gerrit::Cli::UsageError.new("Too many arguments")
end
end
|
#setup_option_parser ⇒ Object
19
20
21
22
23
24
|
# File 'lib/gerrit/cli/command/help.rb', line 19
def setup_option_parser
super
@option_parser.banner =
"Show a list of commands or display help for a specific command."
end
|
#usage ⇒ Object
26
27
28
29
30
31
|
# File 'lib/gerrit/cli/command/help.rb', line 26
def usage
"Usage: gerrit help [options] [<command>]\n\n" \
+ @option_parser.help \
+ "\nAvailable commands:\n" \
+ @commands_summary
end
|