Project

General

Profile

Actions

Bug #19566

closed

OptionParser::on raises unsupported argument type: URI (ArgumentError) but shouldn't

Added by jgomo3 (Jesús Gómez) about 1 year ago. Updated about 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:113064]

Description

The documentation says

OptionParser comes with a few ready-to-use kinds of type coercion. They are
..

  • URI – Anything accepted by URI.parse

But when I try to use the class URI as a coercion class:

op = OptionParser.new
op.on("--uri URI", URI)

I get: unsupported argument type: URI (ArgumentError).

The workaround is to register it with accept:

op = OptionParser.new
op.accept(URI, &URI.method(:parse))
op.on("--uri URI", URI)

I attached 2 files, the first one ruby-op-uri-bug.rb displays the Error.

The second one, ruby-op-uri-workaround.rb show the proper output.


Files

ruby-op-uri-bug.rb (340 Bytes) ruby-op-uri-bug.rb jgomo3 (Jesús Gómez), 03/31/2023 10:56 PM
ruby-op-uri-bug-workaround.rb (377 Bytes) ruby-op-uri-bug-workaround.rb jgomo3 (Jesús Gómez), 03/31/2023 10:56 PM

Updated by luke-gru (Luke Gruber) about 1 year ago

You need to require "optparse/uri". The docs should probably mention that if they don't already.

Updated by jeremyevans0 (Jeremy Evans) about 1 year ago

I submitted a pull request to document the requires needed, not just for URI, but for Date/DateTime/Time/Shellwords as well: https://github.com/ruby/optparse/pull/54

Actions #3

Updated by jeremyevans (Jeremy Evans) about 1 year ago

  • Status changed from Open to Closed

Applied in changeset git|bb927acd3bd3a5a5797587bc4201724235ed26b5.


[ruby/optparse] Document requires needed for Date/DateTime/Time/URI/Shellwords support

Fixes [Bug #19566]

https://github.com/ruby/optparse/commit/fb91d97c10

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0