Class: PLOptionParser
- Inherits:
-
OptionParser
- Object
- OptionParser
- PLOptionParser
- Defined in:
- lib/plplot.rb
Overview
The PLOptionParser is an OptionParser subclass for use with PLplot. It adds long and short options, --help
and -h
, for displaying the OptionParser help text and long and short options, --plopt
and -P
for setting PLplot options. The short option for setting PLplot options can be changed from the default (see #new for details).
Class Method Summary collapse
-
.parse! ⇒ Object
For scripts using PLplot, but no custom options, PLOptionParser.parse! will create an instance of PLOptionParser and call its #parse! method.
Instance Method Summary collapse
-
#initialize(*args) ⇒ PLOptionParser
constructor
call-seq: new(banner = nil, width = 32, indent = ‘ ’ * 4[, opts]) {|self if block_given?| …}.
-
#separator_tail(s = '') ⇒ Object
:nodoc:.
Constructor Details
#initialize(*args) ⇒ PLOptionParser
call-seq:
new(banner = nil, width = 32, indent = ' ' * 4[, opts]) {|self if block_given?| ...}
Initializes the instance and yields itself if called with a block. If last arument is a Hash
, it provides options for this instance (see below). Remaining arguments are passed to OptionParser#new
:
banner
-
Banner message.
width
-
Summary width.
indent
-
Summary indent.
The following key is recognized in the opts
Hash
(if given):
:short_plopt
-
Short version of
--plopt
Defaults to-P
Set tonil
orfalse
to have no short version
If #new is invoked with a block, the help text for the --help
and --plopt
options will be at the end of the help text, otherwise they will be at the beginning.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/plplot.rb', line 52 def initialize(*args) opts = { :short_plopt => '-P', } opts.merge!(args.pop) if Hash === args[-1] # Set banner if not given. This differs slightly from OptionParser's # default banner in that any extension on $0 is preserved. args[0] ||= "Usage: #{File.basename($0)} [options]" super(*args) do |op| program_name = File.basename($0) separator = :separator on = :on if block_given? yield op separator = :separator_tail on = :on_tail end op.send(separator, '') op.send(separator, 'PLplot options:') op.send(on, '-h', '--help', 'Print out this message') do puts op.help exit end op.send(on, opts[:short_plopt]||true, '--plopt OPT[=ARG][,...]', 'Set PLplot options', %Q{For short help use: "#{opts[:short_plopt]||'--plopt '}-"}, %Q{For long help use: "#{opts[:short_plopt]||'--plopt '}h"} ) do |o| o.gsub!('\,', "\e") plopts = o.split(/,(?=\D)/).map! do |kv| kv.gsub!("\e", ',') kv.split('=', 2) end plopts.flatten! plopts.compact! PLplot.plsetopt(plopts, true) end end end |
Class Method Details
.parse! ⇒ Object
For scripts using PLplot, but no custom options, PLOptionParser.parse! will create an instance of PLOptionParser and call its #parse! method.
98 99 100 |
# File 'lib/plplot.rb', line 98 def self.parse! PLOptionParser.new.parse! end |
Instance Method Details
#separator_tail(s = '') ⇒ Object
:nodoc:
27 28 29 |
# File 'lib/plplot.rb', line 27 def separator_tail(s='') # :nodoc: base.append(s, nil, nil) end |