Class: SubCmdOptParser::OptionParserForSubCmd
- Inherits:
-
OptionParser
- Object
- OptionParser
- SubCmdOptParser::OptionParserForSubCmd
- Defined in:
- lib/subcommand_optparse.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#example ⇒ Object
writeonly
Sets the attribute example.
-
#subcommand_name ⇒ Object
Returns the value of attribute subcommand_name.
-
#summary ⇒ Object
Returns the value of attribute summary.
- #usage ⇒ Object
Instance Method Summary collapse
- #banner ⇒ Object
- #help ⇒ Object (also: #to_s)
-
#initialize(subcmd, description, width, indent) ⇒ OptionParserForSubCmd
constructor
A new instance of OptionParserForSubCmd.
Constructor Details
#initialize(subcmd, description, width, indent) ⇒ OptionParserForSubCmd
Returns a new instance of OptionParserForSubCmd.
13 14 15 16 17 18 |
# File 'lib/subcommand_optparse.rb', line 13 def initialize(subcmd, description, width, indent) @subcommand_name = subcmd @description = description @summary = nil super(nil, width, indent) end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
8 9 10 |
# File 'lib/subcommand_optparse.rb', line 8 def description @description end |
#example=(value) ⇒ Object (writeonly)
Sets the attribute example
11 12 13 |
# File 'lib/subcommand_optparse.rb', line 11 def example=(value) @example = value end |
#subcommand_name ⇒ Object
Returns the value of attribute subcommand_name.
7 8 9 |
# File 'lib/subcommand_optparse.rb', line 7 def subcommand_name @subcommand_name end |
#summary ⇒ Object
Returns the value of attribute summary.
9 10 11 |
# File 'lib/subcommand_optparse.rb', line 9 def summary @summary end |
#usage ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/subcommand_optparse.rb', line 20 def usage usage_str = "Usage: " if @usage @usage.each_line.with_index do |line, ind| usage_str << " " if ind > 0 usage_str << line.sub(/\n?\z/, "\n") end else usage_str << "#{program_name} #{@subcommand_name || '<command>'} [options]\n" end usage_str end |
Instance Method Details
#banner ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/subcommand_optparse.rb', line 33 def unless @banner @banner = usage if @summary @banner << "\n#{@summary.sub(/\n?\z/, "\n")}" elsif @description @banner << "\n#{@description.sub(/\n?\z/, "\n")}" end if @example if @example.each_line.count == 1 @banner << "\nExample: #{@example.strip}" else @banner << "\nExamples:\n" @example.each_line do |line| @banner << " #{line.sub(/\n?\z/, "\n")}" end end end end @banner end |
#help ⇒ Object Also known as: to_s
55 56 57 58 59 60 61 62 |
# File 'lib/subcommand_optparse.rb', line 55 def help = "#{}".sub(/\n?\z/, "\n") str_summary = summarize("") if str_summary.size > 0 << "\nOptions:\n" end + str_summary end |