Class: Simple::CLI::Runner::CommandHelp
- Inherits:
-
Object
- Object
- Simple::CLI::Runner::CommandHelp
- Defined in:
- lib/simple/cli/runner/command_help.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#full ⇒ Object
Full help as read from the method comments.
-
#head ⇒ Object
First line of the help as read from the method comments.
-
#initialize(mod, method) ⇒ CommandHelp
constructor
A new instance of CommandHelp.
-
#interface(binary_name, command_name) ⇒ Object
A help string constructed from the commands method signature.
- #option_names ⇒ Object
Constructor Details
#initialize(mod, method) ⇒ CommandHelp
Returns a new instance of CommandHelp.
8 9 10 |
# File 'lib/simple/cli/runner/command_help.rb', line 8 def initialize(mod, method) @mod, @method = mod, method end |
Class Method Details
.option_names(app, subcommand) ⇒ Object
2 3 4 5 6 |
# File 'lib/simple/cli/runner/command_help.rb', line 2 def self.option_names(app, subcommand) new(app, subcommand).option_names rescue NameError [] end |
Instance Method Details
#full ⇒ Object
Full help as read from the method comments
18 19 20 |
# File 'lib/simple/cli/runner/command_help.rb', line 18 def full comments.join("\n") if comments.first end |
#head ⇒ Object
First line of the help as read from the method comments.
13 14 15 |
# File 'lib/simple/cli/runner/command_help.rb', line 13 def head comments.first end |
#interface(binary_name, command_name) ⇒ Object
A help string constructed from the commands method signature.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/simple/cli/runner/command_help.rb', line 36 def interface(binary_name, command_name) method = @mod.instance_method(@method) = [] args = [] method.parameters.each do |mode, name| case mode when :req then args << "<#{name}>" when :key then << "[ --#{name}[=<#{name}>] ]" when :keyreq then << "--#{name}[=<#{name}>]" when :opt then args << "[ <#{name}> ]" when :rest then args << "[ <#{name}> .. ]" end end help = "#{binary_name} #{command_name}" help << " #{.join(' ')}" unless .empty? help << " #{args.join(' ')}" unless args.empty? help end |
#option_names ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/simple/cli/runner/command_help.rb', line 22 def option_names method = @mod.instance_method(@method) method.parameters.map do |mode, name| case mode when :key then name when :keyreq then name end end.compact.map do |name| [ "--#{name}", "--#{name}=" ] end.flatten.uniq end |