Class: OptionParser

Inherits:
Object
  • Object
show all
Defined in:
lib/cmdparse.rb

Overview

Extension for OptionParser objects to allow access to some internals.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#stackObject (readonly)

Access the option list stack.



20
21
22
# File 'lib/cmdparse.rb', line 20

def stack
  @stack
end

Instance Method Details

#banner?Boolean

Returns true if a banner has been set.

Returns:

  • (Boolean)


37
38
39
# File 'lib/cmdparse.rb', line 37

def banner?
  !@banner.nil?
end

#options_defined?Boolean

Returns true if at least one local option is defined.

The zeroth stack element is not respected when doing the query because it contains either the OptionParser::DefaultList or a CmdParse::MultiList with the global options of the CmdParse::CommandParser.

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
# File 'lib/cmdparse.rb', line 27

def options_defined?
  stack[1..-1].each do |list|
    list.each_option do |switch|
      return true if switch.kind_of?(OptionParser::Switch) && (switch.short || switch.long)
    end
  end
  false
end