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

Overview

autoconf-like options.

Constant Summary

::OptionParser - Inherited

ArgumentStyle, COMPSYS_HEADER, DecimalInteger, DecimalNumeric, DefaultList, NoArgument, OctalInteger, Officious, OptionalArgument, RequiredArgument, SPLAT_PROC, Version

Class Method Summary

::OptionParser - Inherited

.accept

See #accept.

.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.

.show_version

Shows version string in packages if Version is defined.

.terminate
.top

Returns the global top option list.

.with

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

.each_const, .search_const

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.

#raise_unknown

Whether to raise at unknown option.

#release

Release code.

#release=

Release code.

#require_exact

Whether to require that options match exactly (disallows providing abbreviated long option as short option).

#summary_indent

Indentation for summary.

#summary_width

Width for option list portion of summary.

#version
#version=

Instance Method Summary

::OptionParser - Inherited

#abort

Shows message with the program name then aborts.

#accept

Directs to accept specified class t.

#additional_message

Returns additional info.

#base

Subject of #on_tail.

#candidate

Return candidates for word.

#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

See self.inc.

#load

Loads options from file names as filename.

#make_switch
#new

Pushes a new List.

#on
#on_head
#on_tail
#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

Shows warning message with the program name.

#add_officious, #compsys, #help_exit, #inspect, #pretty_print,
#callback!

Calls callback with val.

#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.

#parse_in_order,
#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)

This method is for internal use only.
[ GitHub ]

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

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

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

#_check_ac_args(name, block) (private)

This method is for internal use only.
[ GitHub ]

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

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)

Define --enable / --disable style option

Appears as --disable-name in help message.

[ GitHub ]

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

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

#ac_arg_enable(name, help_string, &block)

Define --enable / --disable style option

Appears as --enable-name in help message.

[ GitHub ]

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

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

#ac_arg_with(name, help_string, &block)

Define --with / --without style option

Appears as --with-name in help message.

[ GitHub ]

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

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