H
Hunter Kelly
If I run the following:
#!/usr/bin/ruby -w
require 'optparse'
$host = "localhost"
$user = nil
$db = nil
opts = OptionParser.new
opts.on("-h", "--host", "=HOST", "hostname") { | h | $host = h }
opts.on("-u", "--user", "=USER", "username") { | u | $user = u }
opts.on("--db=DATABASE", "database") { | db | $db=db }
words=%w(--user --host=hostname --db=dbname blah blah blah)
rest = opts.parse(*words)
puts "user: #{$user} rest: #{rest.join(',')} host: #{$host} db:
#{$db}"
------
I get the following output:
user: --host=hostname ok: blah,blah,blah host: localhost db: dbname
I would think that this should generate some form of error: if an
option has a mandatory argument, it doesn't really make sense to me to
blithely assign the next argument - particularly in this case, where it
is obviously another option.
Am I correct in my thinking here, or did I miss something, or is this
just something that OptionParser doesn't support?
Thanks,
Hunter
#!/usr/bin/ruby -w
require 'optparse'
$host = "localhost"
$user = nil
$db = nil
opts = OptionParser.new
opts.on("-h", "--host", "=HOST", "hostname") { | h | $host = h }
opts.on("-u", "--user", "=USER", "username") { | u | $user = u }
opts.on("--db=DATABASE", "database") { | db | $db=db }
words=%w(--user --host=hostname --db=dbname blah blah blah)
rest = opts.parse(*words)
puts "user: #{$user} rest: #{rest.join(',')} host: #{$host} db:
#{$db}"
------
I get the following output:
user: --host=hostname ok: blah,blah,blah host: localhost db: dbname
I would think that this should generate some form of error: if an
option has a mandatory argument, it doesn't really make sense to me to
blithely assign the next argument - particularly in this case, where it
is obviously another option.
Am I correct in my thinking here, or did I miss something, or is this
just something that OptionParser doesn't support?
Thanks,
Hunter