Class: Motoko::OptionParser
- Inherits:
-
Object
- Object
- Motoko::OptionParser
- Defined in:
- lib/motoko/option_parser.rb
Instance Attribute Summary collapse
-
#formatter ⇒ Object
Returns the value of attribute formatter.
Class Method Summary collapse
-
.add_inventory_options(parser, formatter) ⇒ Object
rubocop:disable Metrics/AbcSize.
- .add_shortcut_options(parser, formatter, local_options) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ OptionParser
constructor
A new instance of OptionParser.
- #parse {|@parser, @formatter| ... } ⇒ Object
Constructor Details
#initialize ⇒ OptionParser
7 8 9 10 |
# File 'lib/motoko/option_parser.rb', line 7 def initialize @parser = ::OptionParser.new @formatter = Formatter.new end |
Instance Attribute Details
#formatter ⇒ Object
Returns the value of attribute formatter.
5 6 7 |
# File 'lib/motoko/option_parser.rb', line 5 def formatter @formatter end |
Class Method Details
.add_inventory_options(parser, formatter) ⇒ Object
rubocop:disable Metrics/AbcSize
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/motoko/option_parser.rb', line 23 def self.(parser, formatter) parser.separator '' parser.separator 'Inventory Options' parser.on('-a', '--add-columns=COLUMNS', 'Add COLUMNS to the displayed column list', Array) do |columns| formatter.columns += columns end parser.on('--columns=COLUMNS', 'Set the displayed column list to COLUMNS', Array) do |columns| formatter.columns = columns end parser.on('--hw', 'Display hardware information') do formatter.columns += i[is_virtual cpu memory] end parser.on('--puppet', 'Display Puppet information') do formatter.columns += i[puppet] end parser.on('--sw', 'Display sodtware information') do formatter.columns += i[os kernel] end parser.on('--mono', 'Do not display a colored output') do formatter.mono = true end parser.on('-w', '--wide', 'Do not ellipsis long strings') do formatter.wide = true end parser.on('--[no-]count', 'Count values') do |count| formatter.count = count end parser.on('--sort-by=COLUMNS', 'Sort lines by COLUMS', Array) do |columns| formatter.sort_by = columns end end |
.add_shortcut_options(parser, formatter, local_options) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/motoko/option_parser.rb', line 64 def self.(parser, formatter, ) parser.separator '' parser.separator 'Shortcuts' formatter.shortcuts.each do |key, value| parser.on("--#{key}", value.delete('description')) do if value.key?('columns') formatter.columns.replace(value.delete('columns')) else formatter.columns.push(*value.delete('add_columns')) end [:with_class] ||= [] [:with_class].push(*value.delete('with_class')) [:with_fact] ||= [] [:with_fact].push(*value.delete('with_fact')) end end end |
Instance Method Details
#parse {|@parser, @formatter| ... } ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/motoko/option_parser.rb', line 12 def parse self.class.(@parser, @formatter) yield(@parser, @formatter) if block_given? @parser.parse! @formatter end |