Class: Simple::CLI::Runner::CommandHelp
- Inherits:
-
Object
- Object
- Simple::CLI::Runner::CommandHelp
- Defined in:
- lib/simple/cli/runner/command_help.rb
Overview
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/MethodLength
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.
12 13 14 15 16 |
# File 'lib/simple/cli/runner/command_help.rb', line 12 def initialize(mod, method) raise(ArgumentError, "#{method.inspect} should be a Symbol") unless method.is_a?(Symbol) @mod = mod @method = method end |
Class Method Details
.option_names(app, subcommand) ⇒ Object
6 7 8 9 10 |
# File 'lib/simple/cli/runner/command_help.rb', line 6 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
24 25 26 |
# File 'lib/simple/cli/runner/command_help.rb', line 24 def full comments.join("\n") if comments.first end |
#head ⇒ Object
First line of the help as read from the method comments.
19 20 21 |
# File 'lib/simple/cli/runner/command_help.rb', line 19 def head comments.first end |
#interface(binary_name, command_name) ⇒ Object
A help string constructed from the commands method signature.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/simple/cli/runner/command_help.rb', line 44 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_to_string(command_name)}" help << " #{.join(' ')}" unless .empty? help << " #{args.join(' ')}" unless args.empty? help end |
#option_names ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/simple/cli/runner/command_help.rb', line 28 def option_names method = @mod.instance_method(@method) option_names = method.parameters.map do |mode, name| case mode when :key then name when :keyreq then name end end.compact option_names.map do |name| ["--#{name}", "--#{name}="] end.flatten end |