From: NISHIMATSU Takeshi Date: 2003-03-15T20:54:52+09:00 Subject: [ruby-list:37325] Re: optparse は使いやすいですか? 西松と申します。 > optparse というライブラリを使ってみようとしたものの、 getoptlong を使うのはどうでしょう. Cのrpm.orgにあるライブラリのpoptみたいで便利に使っています. > Hash オブジェクトを作ってくれればいいんじゃないか。 こんなかんじでしょうか: options = {'--format' => 'nameplate', # default values '--eps-file' => 'default.eps', 中略 '--address-mbchar-font' => 'GothicBBB-Medium-EUC-H'} require 'getoptlong' opt = GetoptLong.new(['--format' , '-f', GetoptLong::REQUIRED_ARGUMENT], ['--eps-file' , '-e', GetoptLong::REQUIRED_ARGUMENT], ['--rows' , '-r', GetoptLong::REQUIRED_ARGUMENT], ['--cols' , '-c', GetoptLong::REQUIRED_ARGUMENT], ['--height' , '-h', GetoptLong::REQUIRED_ARGUMENT], ['--width' , '-w', GetoptLong::REQUIRED_ARGUMENT], ['--left-margin' , '-l', GetoptLong::REQUIRED_ARGUMENT], ['--bottom-margin' , '-b', GetoptLong::REQUIRED_ARGUMENT], ['--name-font-size', GetoptLong::REQUIRED_ARGUMENT], ['--address-font-size', GetoptLong::REQUIRED_ARGUMENT], ['--name-font' , GetoptLong::REQUIRED_ARGUMENT], ['--address-font' , GetoptLong::REQUIRED_ARGUMENT], ['--name-mbchar-font', GetoptLong::REQUIRED_ARGUMENT], ['--address-mbchar-font', GetoptLong::REQUIRED_ARGUMENT], ['--version' , '-v', GetoptLong::NO_ARGUMENT]) opt.each_option do |name,arg| case name when '--format' options[name] = arg.downcase when '--eps-file', '--name-font', '--address-font', '--name-mbchar-font', '--address-mbchar-font' options[name] = arg when '--rows', '--cols' options[name] = arg.to_i when '--height', '--width', '--left-margin', '--bottom-margin', '--name-font-size', '--address-font-size' options[name] = arg.to_f when '--version' print NAMEPLATE_VERSION, "\n" exit else STDERR.printf("Illegal option: %s\n", name) end end -- love && peace && free_software NISHIMATSU Takeshi t-nissie@imr.edu OR t-nissie@imr.tohoku.ac.jp 西松 毅