123456789_123456789_123456789_123456789_123456789_

Class: OptionParser::AC

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: OptionParser
Defined in: lib/optparse/ac.rb

Constant Summary

::OptionParser - Inherited

DecimalInteger, DecimalNumeric, OctalInteger

Class Method Summary

::OptionParser - Inherited

.accept

See #accept.

.each_const,
.getopts
.inc

Returns an incremented value of default according to arg.

.new

Initializes the instance and yields itself if called with a block.

.reject

See #reject.

.search_const, .show_version, .terminate, .top,
.with

Initializes a new instance and evaluates the optional block in context of the instance.

Instance Attribute Summary

::OptionParser - Inherited

#banner

Heading banner preceding summary.

#banner=

Heading banner preceding summary.

#default_argv

Strings to be parsed in default.

#program_name

Program name to be emitted in error message and default banner, defaults to $0.

#program_name=

Program name to be emitted in error message and default banner, defaults to $0.

#release

Release code.

#release=

Release code.

#summary_indent

Indentation for summary.

#summary_width

Width for option list portion of summary.

#version

Version.

#version=

Version.

Instance Method Summary

::OptionParser - Inherited

#abort,
#accept

Directs to accept specified class t.

#base

Subject of #on_tail.

#candidate,
#def_head_option

Alias for #define_head.

#def_option

Alias for #define.

#def_tail_option

Alias for #define_tail.

#define, #define_by_keywords, #define_head, #define_tail,
#environment

Parses environment variable env or its uppercase with splitting like a shell.

#getopts

Wrapper method for getopts.rb.

#help

Returns option summary string.

#inc,
#load

Loads options from file names as filename.

#make_switch

Creates an Switch from the parameters.

#new

Pushes a new List.

#on

Add option switch and handler.

#on_head

Add option switch like with #on, but at head of summary.

#on_tail

Add option switch like with #on, but at tail of summary.

#order

Parses command line arguments argv in order.

#order!

Same as #order, but removes switches destructively.

#parse

Parses command line arguments argv in order when environment variable POSIXLY_CORRECT is set, and in permutation mode otherwise.

#parse!

Same as #parse, but removes switches destructively.

#permute

Parses command line arguments argv in permutation mode and returns list of non-option arguments.

#permute!

Same as #permute, but removes switches destructively.

#reject

Directs to reject specified class argument.

#remove

Removes the last List.

#separator

Add separator in summary.

#summarize

Puts option summary into to and returns to.

#terminate

Terminates option parsing.

#to_a

Returns option summary list.

#to_s

Alias for #help.

#top

Subject of #on / #on_head, #accept / #reject

#ver

Returns version string from program_name, version and release.

#warn,
#complete

Completes shortened long style option switch and returns pair of canonical switch and switch descriptor Switch.

#notwice

Checks if an argument is given twice, in which case an ArgumentError is raised.

#search

Searches key in @stack for id hash and returns or yields the result.

#visit

Traverses @stack, sending each element method id with args and block.

Constructor Details

This class inherits a constructor from OptionParser

Instance Method Details

#_ac_arg_enable(prefix, name, help_string, block) (private)

[ GitHub ]

  
# File 'lib/optparse/ac.rb', line 16

def _ac_arg_enable(prefix, name, help_string, block)
  _check_ac_args(name, block)

  sdesc = []
  ldesc = ["--#{prefix}-#{name}"]
  desc = [help_string]
  q = name.downcase
  enable = Switch::NoArgument.new(nil, proc {true}, sdesc, ldesc, nil, desc, block)
  disable = Switch::NoArgument.new(nil, proc {false}, sdesc, ldesc, nil, desc, block)
  top.append(enable, [], ["enable-" + q], disable, ['disable-' + q])
  enable
end

#_check_ac_args(name, block) (private)

[ GitHub ]

  
# File 'lib/optparse/ac.rb', line 7

def _check_ac_args(name, block)
  unless /\A\w[-\w]*\z/ =~ name
    raise ArgumentError, name
  end
  unless block
    raise ArgumentError, "no block given", ParseError.filter_backtrace(caller)
  end
end

#ac_arg_disable(name, help_string, &block)

[ GitHub ]

  
# File 'lib/optparse/ac.rb', line 35

def ac_arg_disable(name, help_string, &block)
  _ac_arg_enable("disable", name, help_string, block)
end

#ac_arg_enable(name, help_string, &block)

[ GitHub ]

  
# File 'lib/optparse/ac.rb', line 31

def ac_arg_enable(name, help_string, &block)
  _ac_arg_enable("enable", name, help_string, block)
end

#ac_arg_with(name, help_string, &block)

[ GitHub ]

  
# File 'lib/optparse/ac.rb', line 39

def ac_arg_with(name, help_string, &block)
  _check_ac_args(name, block)

  sdesc = []
  ldesc = ["--with-#{name}"]
  desc = [help_string]
  q = name.downcase
  with = Switch::PlacedArgument.new(*search(:atype, String), sdesc, ldesc, nil, desc, block)
  without = Switch::NoArgument.new(nil, proc {}, sdesc, ldesc, nil, desc, block)
  top.append(with, [], ["with-" + q], without, ['without-' + q])
  with
end