Rubyã®OptionParserã®åºåãç¥ã
- ã³ãã³ãã¯ã以ä¸ã®ãããªæ¸å¼ã§ãªãã·ã§ã³ã¨å¼æ°ãè¨å®ãã¦ãå®è¡ããä»çµã¿ã«ãªã£ã¦ããã
ä¾ï¼
ã³ãã³ãå | ãªãã·ã§ã³ | ãªãã·ã§ã³ | ãªãã·ã§ã³å¼æ° | ãªãã·ã§ã³ | ã³ãã³ãå¼æ° |
optparser_test.rb | -a | -b | VALUE | --foo | FILE_PATH |
- å®éã«ã³ãã³ããä½ããã¨ããã¨ããªãã·ã§ã³ã®è§£æã«ã¯æéããããã¨æ°ä»ãã
- ãã®ãããå¤ãã®è¨èªç°å¢ã«ã¯ãªãã·ã§ã³è§£æç¨ã®ã©ã¤ãã©ãªãç¨æããã¦ããã
- Rubyã®optparserã«ã¤ãã¦ãåºæ¬çãªä½¿ãæ¹ã¯ç¥ã£ã¦ããã¤ããã ã£ãã...
- ã¡ãã£ã¨æ°ã®å©ããã³ãã³ãã«ãããã¨ããã¨ããã®ä½¿ãæ¹ã¯è¬ã ããã«ãªã£ãã
ã©ããããè¦å´æå°éã§ãªãã·ã§ã³ã解æã§ããã®ãã調ã¹ã¦ã¿ãã
åºæ¬
require 'optparse' OptionParser.new do |opt| opt.parse!(ARGV) end
- ãªãã·ã§ã³å®ç¾©ãä½ããªãç¶æ ã§ããopt.parse!(ARGV)ããå®è¡ãã¦ããã°ã-hã¨--helpãªãã·ã§ã³ãå©ç¨ã§ããã
$ ruby optparse_test.rb -h Usage: optparse_test [options] $ ruby optparse_test.rb --help Usage: optparse_test [options]
1æåãªãã·ã§ã³
- onã¡ã½ããï¼opt.onï¼ã§ãªãã·ã§ã³ãå®ç¾©ããã
- ãªãã·ã§ã³å®ç¾©ã¨ãªãã·ã§ã³èª¬æãå¼æ°ã«è¨å®ããã
- 1æåãªãã·ã§ã³ã¯ã-ã§å§ã¾ã1æåã®ãªãã·ã§ã³åã
- ãªãã·ã§ã³å¼æ°ãããå ´åã¯ãç¶ãã¦ãªãã·ã§ã³å¼æ°ã象徴ããä»»æã®å¤æ°å*1ãæ¸ãã
- [å¤æ°å]ã®ããã«[]ã§å²ãã¨ããªãã·ã§ã³å¼æ°ã¯çç¥å¯è½ã«ãªãã
require 'optparse' option={} OptionParser.new do |opt| opt.on('-a', '1æåãªãã·ã§ã³ å¼æ°ãªã') {|v| option[:a] = v} opt.on('-b VALUE', '1æåãªãã·ã§ã³ å¼æ°ããï¼å¿ é ï¼') {|v| option[:b] = v} opt.on('-c [VALUE]', '1æåãªãã·ã§ã³ å¼æ°ããï¼çç¥å¯è½ï¼'){|v| option[:c] = v} opt.parse!(ARGV) end p option
- ãã«ã表示ã¨ãªãã·ã§ã³ã®è§£æçµæã¯ã以ä¸ã®ããã«ãªã£ãã
$ ruby optparse_test.rb -h Usage: optparse_test [options] -a 1æåãªãã·ã§ã³ å¼æ°ãªã -b VALUE 1æåãªãã·ã§ã³ å¼æ°ããï¼å¿ é ï¼ -c [VALUE] 1æåãªãã·ã§ã³ å¼æ°ããï¼çç¥å¯è½ï¼ $ ruby optparse_test.rb -a -b å¿ é -c {:a=>true, :b=>"å¿ é ", :c=>nil}
ãã³ã°ãªãã·ã§ã³
- ãã³ã°ãªãã·ã§ã³ã¯ã--ã§å§ã¾ã2æå以ä¸ã®ãªãã·ã§ã³åã
- å®ç¾©ã®ä»æ¹ã¯ãåºæ¬çã«1æåãªãã·ã§ã³ã¨åããªã®ã ãã
- ãªãã·ã§ã³åã¨å¤æ°åãã¹ãã¼ã¹ãï¼ã§åºåã£ã¦ããå¿
è¦ãããã
- ã©ãã¾ã§ããªãã·ã§ã³åã§ãã©ããããå¤æ°åããæ示ããã®ã ã
- 以ä¸ã®ä¾ã§ã¯ãæ £ä¾ã«ç¿ã£ã¦ï¼ã§åºåã£ã¦å®ç¾©ãã¦ã¿ãã
require 'optparse' option={} OptionParser.new do |opt| opt.on('--along', '1æåãªãã·ã§ã³ å¼æ°ãªã') {|v| option[:along] = v} opt.on('--blong=VALUE', '1æåãªãã·ã§ã³ å¼æ°ããï¼å¿ é ï¼') {|v| option[:blong] = v} opt.on('--clong=[VALUE]', '1æåãªãã·ã§ã³ å¼æ°ããï¼çç¥å¯è½ï¼'){|v| option[:clong] = v} opt.parse!(ARGV) end p option
- ãã«ã表示ãã¦ã¿ãã
$ ruby optparse_test.rb -h Usage: optparse_test [options] --along 1æåãªãã·ã§ã³ å¼æ°ãªã --blong=VALUE 1æåãªãã·ã§ã³ å¼æ°ããï¼å¿ é ï¼ --clong=[VALUE] 1æåãªãã·ã§ã³ å¼æ°ããï¼çç¥å¯è½ï¼
- ã³ãã³ãå¼æ°ã=ã§åºåã£ã¦å®ç¾©ãã¦ããã³ãã³ãå®è¡æã«ã¯ã¹ãã¼ã¹åºåãã使ããã
$ ruby optparse_test.rb --along --blong=å¿ é --clong {:along=>true, :blong=>"å¿ é ", :clong=>nil} $ ruby optparse_test.rb --along --blong å¿ é --clong {:along=>true, :blong=>"å¿ é ", :clong=>nil}
- ãã³ã°ãªãã·ã§ã³ã¯å¿ è¦æå°éã®å ¥åã§æå®å¯è½ã ã
- ãã®ä»ã®ãªãã·ã§ã³åã¨åºå¥å¯è½ã§ããã°1æåã§ãOKã
$ ruby optparse_test.rb --a --b=å¿ é --c {:along=>true, :blong=>"å¿ é ", :clong=>nil}
1æåãªãã·ã§ã³ã¨ãã³ã°ãªãã·ã§ã³
- ããããã³ãã³ãã¤ã³ã¿ãã§ã¼ã¹ã¨ãã¦ããã³ã°ãªãã·ã§ã³ã«å¯¾å¿ãã1æåãªãã·ã§ã³ãç¨æããã¦ãããã¨ãããã
- ãã³ã°ãªãã·ã§ã³ã®ã·ã§ã¼ãã«ããçãªå½¹å²ã®1æåãªãã·ã§ã³ãå®ç¾©ãããã
- ãã®ãããªå ´åããã³ã°ãªãã·ã§ã³ã¨1æåãªãã·ã§ã³ã¯ãåæã«å®ç¾©ã§ããã
require 'optparse' option={} OptionParser.new do |opt| opt.on('-a', '--along', '1æåãªãã·ã§ã³ å¼æ°ãªã') {|v| option[:along] = v} opt.on('-b', '--blong=VALUE', '1æåãªãã·ã§ã³ å¼æ°ããï¼å¿ é ï¼') {|v| option[:blong] = v} opt.on('-c', '--clong=[VALUE]', '1æåãªãã·ã§ã³ å¼æ°ããï¼çç¥å¯è½ï¼'){|v| option[:clong] = v} opt.parse!(ARGV) end p option
- ãã«ã表示ãã¦ã¿ãã
$ ruby optparse_test.rb -h Usage: optparse_test [options] -a, --along 1æåãªãã·ã§ã³ å¼æ°ãªã -b, --blong=VALUE 1æåãªãã·ã§ã³ å¼æ°ããï¼å¿ é ï¼ -c, --clong=[VALUE] 1æåãªãã·ã§ã³ å¼æ°ããï¼çç¥å¯è½ï¼
- ãã³ã°ãªãã·ã§ã³ã1æåãªãã·ã§ã³ããåé¡ãªã使ããã
- ãªãã·ã§ã³å¼æ°ãæå®ããæã
- ãã³ã°ãªãã·ã§ã³ã§ã¯ãã¹ãã¼ã¹ãï¼ã§åºåãå¿ è¦ãããã
- 1æåãªãã·ã§ã³ã§ã¯ãåºåããªãããããã¯ã¹ãã¼ã¹ã§åºåãã
$ ruby optparse_test.rb --along --blong=å¿ é --clong {:along=>true, :blong=>"å¿ é ", :clong=>nil} $ ruby optparse_test.rb -a -b å¿ é -c {:along=>true, :blong=>"å¿ é ", :clong=>nil} $ ruby optparse_test.rb -a -bå¿ é -c {:along=>true, :blong=>"å¿ é ", :clong=>nil}
- 1æåãªãã·ã§ã³ã§ã¯ãï¼ã§åºåã£ã¦ãªãã·ã§ã³å¼æ°ãæå®ãã¦ãã¾ãã¨NGã
- ï¼ãå«ãã æååãæå®ãããã¨ã«ãªã£ã¦ãã¾ãã
$ ruby optparse_test.rb -a -b=å¿ é -c {:along=>true, :blong=>"=å¿ é ", :clong=>nil}
noãªãã·ã§ã³
- no-ã§å§ã¾ããã³ã°ãªãã·ã§ã³åã¯ãfalseãè¿ãã
- [no-]ã¨æ¬å¼§ã§å²ãã¨ãno-ãçç¥ãããã³ã°ãªãã·ã§ã³åãå¯è½ã«ãªãã
require 'optparse' option={} OptionParser.new do |opt| opt.on('--no-only', 'onlyã¯ç¡å¹'){|v| option[:only] = v} opt.on('--[no-]both', 'bothãæå¹'){|v| option[:both] = v} opt.parse!(ARGV) end p option
- ãã«ã表示ãã¦ã¿ãã
$ ruby optparse_test.rb -h
Usage: optparse_test [options]
--no-only onlyã¯ç¡å¹
--[no-]both bothãæå¹
- no-ã¯ãfalseãè¿ãã
$ ruby optparse_test.rb --no-only --no-both
{:only=>false, :both=>false}
- --[no-]bothã ã¨ã--bothãå¯è½ãtrueãè¿ãã
$ ruby optparse_test.rb --both
{:both=>true}
- --no-onlyã§ã¯ã--onlyã¯ã¨ã©ã¼ã«ãªãã
$ ruby optparse_test.rb --only optparse_test.rb:8:in `block in': invalid option: --only (OptionParser::InvalidOption) from optparse_test.rb:4:in `new' from optparse_test.rb:4:in ` '
ãªãã·ã§ã³å¼æ°ãæ°å¤ãé åã¨ãã¦åãåã
- é常ããªãã·ã§ã³å¼æ°ã«æå®ããå¤ã¯ãæååã¨ãã¦åãåãã
- ã¯ã©ã¹ãæå®ããã¨ããã®ã¯ã©ã¹ã«å¤æããããã®ãåãåãã
- æå®å¯è½ãªã¯ã©ã¹ã¯ãinstance method OptionParser#onã®ããã©ã«ãã§å©ç¨å¯è½ãªå¼æ°ã¯ã©ã¹ãåç §ã
require 'optparse' option={} OptionParser.new do |opt| opt.on('--long=V,V,...', 'é常ã®ãªãã·ã§ã³'){|v| option[:only] = v} opt.on('--long_array=V,V,...', Array, 'ã¯ã©ã¹æå®ãã'){|v| option[:long_array] = v} opt.parse!(ARGV) end p option
- ãã«ã表示ãã¦ã¿ãã
$ ruby optparse_test.rb -h
Usage: optparse_test [options]
--long=V,V,... é常ã®ãªãã·ã§ã³
--long_array=V,V,... ã¯ã©ã¹æå®ãã
- é常ã¯æååã¨ãã¦åãåãã
$ ruby optparse_test.rb --long=1,2,3
{:only=>"1,2,3"}
- Arrayãæå®ããã¨é åã«ãªãã
$ ruby optparse_test.rb --long_array=1,2,3
{:long_array=>["1", "2", "3"]}
ãªãã·ã§ã³å¼æ°ã®é¸æè¢
- ãªãã·ã§ã³å¼æ°ã«ãããã¤ãã®é¸æè¢ãè¨å®ãããå ´åãããã
- é¸æè¢ã®é åãããã·ã¥ãä¸ãã¦ããã¨ããããé¸æè¢ã¨ãªãã
require 'optparse' option={} OptionParser.new do |opt| opt.on('--long=VALUE', 'WHITESPACE_ONLY | SIMPLE_OPTIMIZATIONS | ADVANCED_OPTIMIZATIONS'){|v| option[:long] = v} opt.on('--long_array=VALUE', ['WHITESPACE_ONLY', 'SIMPLE_OPTIMIZATIONS', 'ADVANCED_OPTIMIZATIONS'], 'WHITESPACE_ONLY | SIMPLE_OPTIMIZATIONS | ADVANCED_OPTIMIZATIONS'){|v| option[:long_array] = v} opt.on('--long_hash=VALUE', {'1'=>'WHITESPACE_ONLY', '2'=>'SIMPLE_OPTIMIZATIONS', '3'=>'ADVANCED_OPTIMIZATIONS'}, '1 | 2 | 3'){|v| option[:long_hash] = v} opt.on('--long_both=VALUE', ['WHITESPACE_ONLY', 'SIMPLE_OPTIMIZATIONS', 'ADVANCED_OPTIMIZATIONS'], {'1'=>'WHITESPACE_ONLY', '2'=>'SIMPLE_OPTIMIZATIONS', '3'=>'ADVANCED_OPTIMIZATIONS'}, '1:WHITESPACE_ONLY | 2:SIMPLE_OPTIMIZATIONS | 3:ADVANCED_OPTIMIZATIONS'){|v| option[:long_both] = v} opt.parse!(ARGV) end p option
- ãã«ã表示ãã¦ã¿ãã
$ ruby optparse_test.rb -h Usage: optparse_test [options] --long=VALUE WHITESPACE_ONLY | SIMPLE_OPTIMIZATIONS | ADVANCED_OPTIMIZATIONS --long_array=VALUE WHITESPACE_ONLY | SIMPLE_OPTIMIZATIONS | ADVANCED_OPTIMIZATIONS --long_hash=VALUE 1 | 2 | 3 --long_both=VALUE 1:WHITESPACE_ONLY | 2:SIMPLE_OPTIMIZATIONS | 3:ADVANCED_OPTIMIZATIONS
- é åãããã·ã¥ãä¸ããªãã¨ãé¸æè¢ä»¥å¤ã®æå®ãå¯è½ã«ãªã£ã¦ãã¾ãã
$ ruby optparse_test.rb --long=WHITESPACE_ONLY {:long=>"WHITESPACE_ONLY"} $ ruby optparse_test.rb --long=ABC {:long=>"ABC"}
- é åãä¸ãã¦ããã¨ãé å以å¤ã®æååã§ã¯ã¨ã©ã¼ã«ãªãã
$ ruby optparse_test.rb --long_array=WHITESPACE_ONLY {:long_arrya=>"WHITESPACE_ONLY"} $ ruby optparse_test.rb --long_array=ABC optparse_test.rb:21:in `block in': invalid argument: --long_array=ABC (OptionParser::InvalidArgument) from optparse_test.rb:4:in `new' from optparse_test.rb:4:in ` '
- ããã«ãé¸æè¢ãåºå¥ã§ããå¿ è¦æå°éã®å ¥åã§ãæå®å¯è½ã«ãªãã
$ ruby optparse_test.rb --long_array=W
{:long_arrya_hash=>"WHITESPACE_ONLY"}
- ããã·ã¥ãä¸ãã¦ããã¨ãããã·ã¥ã®ãã¼ã§æå®å¯è½ã¨ãªãã
$ ruby optparse_test.rb --long_hash=1
{:long_hash=>"WHITESPACE_ONLY"}
- ããããããã·ã¥ã®å¤ã§ã¯ã¨ã©ã¼ã¨ãªãã
- ãã¡ãããåå¨ããªãããã·ã¥ã®ãã¼ã§ãã¨ã©ã¼ã¨ãªãã
$ ruby optparse_test.rb --long_hash=WHITESPACE_ONLY optparse_test.rb:21:in `block in': invalid argument: --long_hash=WHITESPACE_ONLY (OptionParser::InvalidArgument) from optparse_test.rb:4:in `new' from optparse_test.rb:4:in ` ' $ ruby optparse_test.rb --long_hash=4 optparse_test.rb:21:in `block in ': invalid argument: --long_hash=4 (OptionParser::InvalidArgument) from optparse_test.rb:4:in `new' from optparse_test.rb:4:in ` '
- é åã¨ããã·ã¥ä¸¡æ¹ãä¸ãã¦ããã¨ãé åã®å¤ã»ããã·ã¥ã®ãã¼ã§æå®å¯è½ã¨ãªãã
$ ruby optparse_test.rb --long_both=1 {:long_both=>"WHITESPACE_ONLY"} $ ruby optparse_test.rb --long_both=WHITESPACE_ONLY {:long_both=>"WHITESPACE_ONLY"}
ãªãã·ã§ã³å¼æ°ã®ãã¿ã¼ã³æå®
- ãªãã·ã§ã³å¼æ°ã«è¨±å¯ãããã¿ã¼ã³ãè¨å®ãã¦ãããã¨ãã§ããã
- æ£è¦è¡¨ç¾ãä¸ãããã¨ã§ããã®æ£è¦è¡¨ç¾ã«ãããããæååã®ã¿å
¥åå¯è½ã«ãªãã
- ãããããªãå ´åã¯ã¨ã©ã¼ã«ãªãã
- 試ãã«ã0ãã100ã¾ã§ã®æ°å¤ã®ã¿ã«ãããããæ£è¦è¡¨ç¾ãä¸ãã¦ã¿ãã¨...
require 'optparse' option={} OptionParser.new do |opt| opt.on('--rate=VALUE', /\A\d{1,2}\Z|\A100\Z/, '0-100 Percentage.'){|v| option[:rate] = v} opt.parse!(ARGV) end p option
- ãã«ã表示ãã¦ã¿ãã
$ ruby optparse_test.rb -h Usage: optparse_test [options] --rate=VALUE 0-100 Percentage.
- 0ãã100ã¾ã§ã¯æå®å¯è½ã
- 101以ä¸ã¯ã¨ã©ã¼ã«ãªãã
$ ruby optparse_test.rb --rate=0 {:rate=>"0"} $ ruby optparse_test.rb --rate=99 {:rate=>"99"} $ ruby optparse_test.rb --rate=100 {:rate=>"100"} $ ruby optparse_test.rb --rate=101 optparse_test.rb:7:in `block in': invalid argument: --rate=101 (OptionParser::InvalidArgument) from optparse_test.rb:4:in `new' from optparse_test.rb:4:in ` '
ãã«ã表示ããã¶ã¤ã³ãã
- 以ä¸ã®å¤æ°ãã¡ã½ãããæ´»ç¨ããªããããªãã·ã§ã³å®ç¾©ããªããããã«ã表示ããã¶ã¤ã³ããã®ã ã
- ã¤ã³ã¹ã¿ã³ã¹å¤æ°ã¨ããã©ã«ãå¤
- banner=nil, summary_width=32, summary_indent=' ' * 4, version=nil
- ã¤ã³ã¹ã¿ã³ã¹å¤æ°ã¯ãããã©ã«ãå¤ã§ã¯æºè¶³ã§ããªãæã ããå¿ è¦ã«å¿ãã¦è¨å®ããã°ããã
- ã¤ã³ã¹ã¿ã³ã¹ã¡ã½ãã
- on, on_head, on_tail, separator
- on, on_head, on_tailã¯ããã¹ã¦ã»ã¼åãæ©è½ãæã£ã¦ããã
- è¥å¹²ã®éãã¯ããã«ã表示ããæã®è¡¨ç¤ºé åºã®éãã
- ãã£ã¦ãon_headã¨on_tailã®ä¸ã«ã¯ãseparatorãå ¥ãããã¨ã¯åºæ¥ãªãã
require 'optparse' option={} OptionParser.new do |opt| opt.banner = 'Usage: banner' opt.summary_width = 32 opt.summary_indent = ' ' * 4 opt.version = '1.0.0' opt.on_head('on_head 1è¡ç® ããã©ã«ãå¤: banner = nil', 'on_head 2è¡ç® ããã©ã«ãå¤: indent = ' ' * 4', 'on_head 3è¡ç® ããã©ã«ãå¤: width = 32', 'on_head 4è¡ç® ããã©ã«ãå¤: version= nil') opt.separator('') opt.on('on 1è¡ç® ãªãã·ã§ã³å®ç¾©ãã¦ããonã¡ã½ããã¯ã以ä¸ã®indentã¨widthã§è¡¨ç¤ºããã', 'on 2è¡ç® indentã¨widthã®è¨å®ã¯ãèªç±ã«å¤æ´ã§ãã') opt.on('|ind| |') opt.on('|ent|width |description') opt.on('|<4>|<-------------32-------------->|') opt.on('-a', '--along', '1è¡ç®', '2è¡ç®', '3è¡ç®'){|v| option[:along] = v} opt.on('-b', '--blong', '1è¡ç®', '2è¡ç®', '3è¡ç®'){|v| option[:blong] = v} opt.separator('') opt.on('on 1è¡ç® ãªãã·ã§ã³å®ç¾©ããªãonã¡ã½ããã¯ãåæååãã¤ã³ãã³ããªãã§è¡¨ç¤ºããã', 'on 2è¡ç®', 'on 3è¡ç®') opt.separator('') opt.on_tail('on_tail 1è¡ç®', 'on_tail 2è¡ç®', 'on_tail 3è¡ç®') opt.parse!(ARGV) end p option
- ãã«ã表示ãã¦ã¿ãã
$ ruby optparse_test.rb -h # or --help Usage: banner on_head 1è¡ç® ããã©ã«ãå¤: banner = nil on_head 2è¡ç® ããã©ã«ãå¤: indent = * 4 on_head 3è¡ç® ããã©ã«ãå¤: width = 32 on_head 4è¡ç® ããã©ã«ãå¤: version= nil on 1è¡ç® ãªãã·ã§ã³å®ç¾©ãã¦ããonã¡ã½ããã¯ã以ä¸ã®indentã¨widthã§è¡¨ç¤ºããã on 2è¡ç® indentã¨widthã®è¨å®ã¯ãèªç±ã«å¤æ´ã§ãã |ind| | |ent|width |description |<4>|<-------------32-------------->| -a, --along 1è¡ç® 2è¡ç® 3è¡ç® -b, --blong 1è¡ç® 2è¡ç® 3è¡ç® on 1è¡ç® ãªãã·ã§ã³å®ç¾©ããªãonã¡ã½ããã¯ãåæååãã¤ã³ãã³ããªãã§è¡¨ç¤ºããã on 2è¡ç® on 3è¡ç® on_tail 1è¡ç® on_tail 2è¡ç® on_tail 3è¡ç®
- ãã¼ã¸ã§ã³è¡¨ç¤ºãã¦ã¿ãã
$ ruby optparse_test.rb -v # or --version optparse_test 1.0.0
- version=nilã§ã¯ãããªãã
$ ruby optparse_test.rb -v # or --version optparse_test: version unknown
ã·ã³ãã«ãªgetopts
- ãªãã·ã§ã³ãããã·ã¥ã«å¤æããã ãã§ç¨ã足ããæã¯ãgetoptsã便å©ã
- optparseãrequireããã¨ãARGVã«OptionParser::Arguableã®æ©è½ã追å ããããããã
ARGV.getopts('1æåãªãã·ã§ã³ç¾ å', 'ãã³ã°ãªãã·ã§ã³', 'ãã³ã°ãªãã·ã§ã³', ...)
- ãªãã·ã§ã³å¼æ°ãåãåãå ´åã¯ããªãã·ã§ã³åã®æ¬¡ã«:ãæ¸ãã¦ããã®ã ã
$ ruby -r optparse -e 'p ARGV.getopts("ab:cd:", "foo", "bar:")' {"a"=>false, "b"=>nil, "c"=>false, "d"=>nil, "foo"=>false, "bar"=>nil} $ ruby -r optparse -e 'p ARGV.getopts("ab:cd:", "foo", "bar:")' -- -a -b100 --foo --bar=abc {"a"=>true, "b"=>"100", "c"=>false, "d"=>nil, "foo"=>true, "bar"=>"abc"}
- ãã³ã°ãªãã·ã§ã³ã«ã¯ãããã©ã«ãå¤ãè¨å®ã§ããã
- æ®å¿µãªããã1æåãªãã·ã§ã³ã«ã¯è¨å®ã§ããªãã...ã
- ãªãã·ã§ã³å:ã«ç¶ãã¦ãããã©ã«ãå¤ãæ¸ãã°OKã
$ ruby -r optparse -e 'p ARGV.getopts("", "foo:", "bar:100")' {"foo"=>nil, "bar"=>"100"} $ ruby -r optparse -e 'p ARGV.getopts("", "foo:", "bar:100")' -- --bar=abc {"foo"=>nil, "bar"=>"abc"}
ããã¥ã¢ã«
*1:ãªãã·ã§ã³å¼æ°ã®å 容ãæ³åã§ããå¤æ°åãªãä½ã§ããããç®çã¯ä»£å ¥ããã®ã§ã¯ãªãã説æããããã§ããã