Class: Trace2::OptionParser

Inherits:
OptionParser
  • Object
show all
Defined in:
lib/trace2/option_parser.rb

Overview

Class that parses the options that will be used by trace2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(banner = nil, width = 32, indent = ' ' * 4) ⇒ OptionParser

Returns a new instance of OptionParser.



11
12
13
14
# File 'lib/trace2/option_parser.rb', line 11

def initialize(banner = nil, width = 32, indent = ' ' * 4)
  @options_keys = {}
  super(banner, width, indent)
end

Instance Attribute Details

#options_keysObject (readonly)

Returns the value of attribute options_keys.



9
10
11
# File 'lib/trace2/option_parser.rb', line 9

def options_keys
  @options_keys
end

Instance Method Details

#add_option(short: nil, long: nil, description: []) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/trace2/option_parser.rb', line 16

def add_option(short: nil, long: nil, description: [])
  @options_keys.merge!(**option_hash(short), **option_hash(long))
  options = [short, long].compact
  on(*options, *description) do |option_value|
    yield option_value
  end
end

#split_executables(args) ⇒ Object



24
25
26
27
28
# File 'lib/trace2/option_parser.rb', line 24

def split_executables(args)
  second_executable = second_executable_arguments(args)

  [args.shift(args.length - second_executable.length), second_executable]
end