Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
ruby / usr / share / ri / 2.2.0 / system / OptionParser / cdesc-OptionParser.ri
Size: Mime:
U:RDoc::NormalClass[iI"
OptParse:EFI"OptionParser;TI"Object;To:RDoc::Markup::Document:@parts[o;;[$S:RDoc::Markup::Heading:
leveli:	textI"OptionParser;To:RDoc::Markup::BlankLineS;	;
i;I"Introduction;T@o:RDoc::Markup::Paragraph;[I"POptionParser is a class for command-line option analysis.  It is much more ;TI"Tadvanced, yet also easier to use, than GetoptLong, and is a more Ruby-oriented ;TI"solution.;T@S;	;
i;I"
Features;T@o:RDoc::Markup::List:
@type:NUMBER:@items[
o:RDoc::Markup::ListItem:@label0;[o;
;[I"MThe argument specification and the code to handle it are written in the ;TI"same place.;To;;0;[o;
;[I"MIt can output an option summary; you don't need to maintain this string ;TI"separately.;To;;0;[o;
;[I"DOptional and mandatory arguments are specified very gracefully.;To;;0;[o;
;[I"CArguments can be automatically converted to a specified class.;To;;0;[o;
;[I"2Arguments can be restricted to a certain set.;T@o;
;[I"HAll of these features are demonstrated in the examples below.  See ;TI")#make_switch for full documentation.;T@S;	;
i;I"Minimal example;T@o:RDoc::Markup::Verbatim;[I"require 'optparse'
;TI"
;TI"options = {}
;TI" OptionParser.new do |opts|
;TI"3  opts.banner = "Usage: example.rb [options]"
;TI"
;TI"?  opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
;TI"    options[:verbose] = v
;TI"  end
;TI"end.parse!
;TI"
;TI"p options
;TI"p ARGV
;T:@format0S;	;
i;I"Generating Help;T@o;
;[I"ROptionParser can be used to automatically generate help for the commands you ;TI"write:;T@o;;[$I"require 'optparse'
;TI"
;TI"!Options = Struct.new(:name)
;TI"
;TI"class Parser
;TI"  def self.parse(options)
;TI"%    args = Options.new("world")
;TI"
;TI"1    opt_parser = OptionParser.new do |opts|
;TI"7      opts.banner = "Usage: example.rb [options]"
;TI"
;TI"K      opts.on("-nNAME", "--name=NAME", "Name to say hello to") do |n|
;TI"        args.name = n
;TI"      end
;TI"
;TI":      opts.on("-h", "--help", "Prints this help") do
;TI"        puts opts
;TI"        exit
;TI"      end
;TI"
    end
;TI"
;TI"$    opt_parser.parse!(options)
;TI"    return args
;TI"  end
;TI"	end
;TI"'options = Parser.parse %w[--help]
;TI"
;TI"	#=>
;TI"&   # Usage: example.rb [options]
;TI"D   #     -n, --name=NAME                  Name to say hello to
;TI"A   #     -h, --help                       Prints this help#
;T;0S;	;
i;I"Complete example;T@o;
;[I"SThe following example is a complete Ruby program.  You can run it and see the ;TI"Seffect of specifying various options.  This is probably the best way to learn ;TI" the features of +optparse+.;T@o;;[tI"require 'optparse'
;TI"require 'optparse/time'
;TI"require 'ostruct'
;TI"require 'pp'
;TI"
;TI"class OptparseExample
;TI"
;TI"<  CODES = %w[iso-2022-jp shift_jis euc-jp utf8 binary]
;TI"H  CODE_ALIASES = { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
;TI"
;TI"	  #
;TI"4  # Return a structure describing the options.
;TI"	  #
;TI"  def self.parse(args)
;TI"U    # The options specified on the command line will be collected in *options*.
;TI"'    # We set default values here.
;TI""    options = OpenStruct.new
;TI"    options.library = []
;TI"!    options.inplace = false
;TI"#    options.encoding = "utf8"
;TI"'    options.transfer_type = :auto
;TI"!    options.verbose = false
;TI"
;TI"1    opt_parser = OptionParser.new do |opts|
;TI"7      opts.banner = "Usage: example.rb [options]"
;TI"
;TI"      opts.separator ""
;TI".      opts.separator "Specific options:"
;TI"
;TI"!      # Mandatory argument.
;TI".      opts.on("-r", "--require LIBRARY",
;TI"P              "Require the LIBRARY before executing your script") do |lib|
;TI"$        options.library << lib
;TI"      end
;TI"
;TI"8      # Optional argument; multi-line description.
;TI"2      opts.on("-i", "--inplace [EXTENSION]",
;TI"/              "Edit ARGV files in place",
;TI"E              "  (make backup if EXTENSION supplied)") do |ext|
;TI"$        options.inplace = true
;TI"+        options.extension = ext || ''
;TI"\        options.extension.sub!(/\A\.?(?=.)/, ".")  # Ensure extension begins with dot.
;TI"      end
;TI"
;TI"/      # Cast 'delay' argument to a Float.
;TI"R      opts.on("--delay N", Float, "Delay N seconds before executing") do |n|
;TI"        options.delay = n
;TI"      end
;TI"
;TI"4      # Cast 'time' argument to a Time object.
;TI"[      opts.on("-t", "--time [TIME]", Time, "Begin execution at given time") do |time|
;TI"!        options.time = time
;TI"      end
;TI"
;TI"$      # Cast to octal integer.
;TI"F      opts.on("-F", "--irs [OCTAL]", OptionParser::OctalInteger,
;TI"E              "Specify record separator (default \\0)") do |rs|
;TI"+        options.record_separator = rs
;TI"      end
;TI"
;TI"       # List of arguments.
;TI"S      opts.on("--list x,y,z", Array, "Example 'list' of arguments") do |list|
;TI"!        options.list = list
;TI"      end
;TI"
;TI"W      # Keyword completion.  We are specifying a specific set of arguments (CODES
;TI"W      # and CODE_ALIASES - notice the latter is a Hash), and the user may provide
;TI",      # the shortest unambiguous text.
;TI"=      code_list = (CODE_ALIASES.keys + CODES).join(',')
;TI"J      opts.on("--code CODE", CODES, CODE_ALIASES, "Select encoding",
;TI"5              "  (#{code_list})") do |encoding|
;TI")        options.encoding = encoding
;TI"      end
;TI"
;TI"8      # Optional argument with keyword completion.
;TI"=      opts.on("--type [TYPE]", [:text, :binary, :auto],
;TI"G              "Select transfer type (text, binary, auto)") do |t|
;TI"'        options.transfer_type = t
;TI"      end
;TI"
;TI"      # Boolean switch.
;TI"C      opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
;TI"!        options.verbose = v
;TI"      end
;TI"
;TI"      opts.separator ""
;TI",      opts.separator "Common options:"
;TI"
;TI"N      # No argument, shows at tail.  This will print an options summary.
;TI"      # Try it and see!
;TI"@      opts.on_tail("-h", "--help", "Show this message") do
;TI"        puts opts
;TI"        exit
;TI"      end
;TI"
;TI":      # Another typical switch to print the version.
;TI"8      opts.on_tail("--version", "Show version") do
;TI"&        puts ::Version.join('.')
;TI"        exit
;TI"      end
;TI"
    end
;TI"
;TI"!    opt_parser.parse!(args)
;TI"    options
;TI"  end  # parse()
;TI"
;TI""end  # class OptparseExample
;TI"
;TI"+options = OptparseExample.parse(ARGV)
;TI"pp options
;TI"
pp ARGV
;T;0S;	;
i;I"Shell Completion;T@o;
;[I"AFor modern shells (e.g. bash, zsh, etc.), you can use shell ;TI")completion for command line options.;T@S;	;
i;I"Further documentation;T@o;
;[I"QThe above examples should be enough to learn how to use this class.  If you ;TI"Dhave any questions, file a ticket at http://bugs.ruby-lang.org.;T:
@fileI"lib/optparse.rb;T:0@omit_headings_from_table_of_contents_below0;0;0[[
I"banner;TI"W;T:publicFI"lib/optparse.rb;T[
I"default_argv;TI"RW;T;F@÷[
I"program_name;TI"W;T;F@÷[
I"release;TI"W;T;F@÷[
I"set_banner;F@ö;F@÷[
I"set_program_name;F@ý;F@÷[
I"set_summary_indent;FI"RW;T;F@÷[
I"set_summary_width;FI"RW;T;F@÷[
I"summary_indent;TI"RW;T;F@÷[
I"summary_width;TI"RW;T;F@÷[
I"version;TI"W;T;F@÷[U:RDoc::Constant[iI"DecimalInteger;FI"!OptionParser::DecimalInteger;T00o;;[o;
;[I"8Decimal integer format, to be converted to Integer.;T;@ò;0@ò@cRDoc::NormalClass0U;[iI"OctalInteger;FI"OptionParser::OctalInteger;T00o;;[o;
;[I"MRuby/C like octal/hexadecimal/binary integer format, to be converted to ;TI"
Integer.;T;@ò;0@ò@@0U;[iI"DecimalNumeric;FI"!OptionParser::DecimalNumeric;T00o;;[o;
;[I"IDecimal integer/float number format, to be converted to Integer for ;TI",integer format, Float for float format.;T;@ò;0@ò@@0[[[I"
class;T[[;[[I"accept;F@÷[I"each_const;FI"lib/optparse/version.rb;T[I"getopts;F@÷[I"inc;F@÷[I"new;T@÷[I"reject;F@÷[I"search_const;F@>[I"show_version;F@>[I"terminate;F@÷[I"top;F@÷[I"	with;F@÷[:protected[[:private[[I"
instance;T[[;[-[I"
abort;F@÷[I"accept;F@÷[I"banner;F@÷[I"	base;F@÷[I"candidate;F@÷[I"def_head_option;F@÷[I"def_option;F@÷[I"def_tail_option;F@÷[I"define;F@÷[I"define_head;F@÷[I"define_tail;F@÷[I"environment;F@÷[I"getopts;F@÷[I"	help;F@÷[I"inc;F@÷[I"	load;F@÷[I"make_switch;F@÷[I"new;F@÷[I"on;F@÷[I"on_head;F@÷[I"on_tail;F@÷[I"
order;F@÷[I"order!;F@÷[I"
parse;F@÷[I"parse!;F@÷[I"permute;F@÷[I"
permute!;F@÷[I"program_name;F@÷[I"reject;F@÷[I"release;F@÷[I"remove;F@÷[I"separator;F@÷[I"summarize;F@÷[I"terminate;F@÷[I"	to_a;F@÷[I"	to_s;F@÷[I"top;F@÷[I"ver;F@÷[I"version;F@÷[I"	warn;F@÷[;[[;[	[I"
complete;F@÷[I"notwice;F@÷[I"search;F@÷[I"
visit;F@÷[[U:RDoc::Context::Section[i0o;;[;0;0[@òI"lib/optparse/ac.rb;TI"lib/optparse/date.rb;TI"lib/optparse/time.rb;TI"lib/rdoc/options.rb;TI"lib/rdoc/ri/driver.rb;TI"*lib/rubygems/commands/cert_command.rb;TI"-lib/rubygems/commands/install_command.rb;TI",lib/rubygems/commands/server_command.rb;TI"/lib/rubygems/commands/uninstall_command.rb;TI"+lib/rubygems/install_update_options.rb;TI")lib/rubygems/local_remote_options.rb;T@òcRDoc::TopLevel