[ruby-core:87371] [Ruby trunk Misc#14812][Closed] Question: Option Parser

From: nobu@...
Date: 2018-06-04 01:06:49 UTC
List: ruby-core #87371
Issue #14812 has been updated by nobu (Nobuyoshi Nakada).

Status changed from Open to Closed

Just `rescue OptionParser::InvalidOption`.
As it can't tell if an unknown option has its argument or not, I didn't add such methods.

```ruby
require 'optparse'

unknown = []
ARGV.options do |opt|
  opt.on("--foo=FOO") {|v| @foo = v}
  begin
    opt.order! {|arg| unknown << arg}
  rescue OptionParser::InvalidOption => e
    unknown.concat(e.args)
    redo
  end
end

p unknown
p @foo
```

----------------------------------------
Misc #14812: Question: Option Parser 
https://bugs.ruby-lang.org/issues/14812#change-72358

* Author: xz0r (xz0r xz0r)
* Status: Closed
* Priority: Normal
* Assignee: 
----------------------------------------
Hi,

Is there an option / way to ignore undeclared options and get them in a resultset so, I can handle them in a custom way?

Example scenario: Program A redirects unsupported arguments to another Program B called from inside program A.


Thanks. 



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next