Project

General

Profile

Actions

Feature #8460

open

PATCH: optparse: add `keep_unknown` option

Added by felipec (Felipe Contreras) over 11 years ago. Updated over 1 year ago.

Status:
Assigned
Target version:
-
[ruby-core:55195]

Description

Currently people have to do very convoluted tricks, essentially making
it impossible for optparse to keep unknown options.

The safest and cleanest way is to do it in the code itself.

[1] http://www.ruby-forum.com/topic/88081
[2] http://stackoverflow.com/questions/3642331/can-optparse-skip-unknown-options-to-be-processed-later-in-a-ruby-program


Files

0001-Add-keep_unknown-option.patch (2.79 KB) 0001-Add-keep_unknown-option.patch Add `keep_unknown` option felipec (Felipe Contreras), 04/02/2023 06:50 AM
0002-Move-dash-dash-handling-to-a-case.patch (1.28 KB) 0002-Move-dash-dash-handling-to-a-case.patch Move dash dash handling to a case felipec (Felipe Contreras), 04/02/2023 06:50 AM
0003-Properly-keep-dash-dash.patch (1.1 KB) 0003-Properly-keep-dash-dash.patch Properly keep dash dash felipec (Felipe Contreras), 04/02/2023 06:50 AM

Updated by zzak (zzak _) over 11 years ago

  • Status changed from Open to Assigned
  • Assignee set to nobu (Nobuyoshi Nakada)

Updated by drbrain (Eric Hodel) over 11 years ago

I like this patch, I could use this feature in RDoc's option parser which ignores arguments that were valid for previous versions.

Updated by prijutme4ty (Ilya Vorontsov) over 11 years ago

Can anyone please take a look at a bug http://bugs.ruby-lang.org/issues/7537#change-37695 considering command-line arguments containing negative numbers (which're erroneously treated ass options) and my patch for it.
I'm afraid that keeping unknown options will silently treat negative numbers (not an exception is raised) and possibly lose their ordering. So please before accepting unknown options patch, decide which behavior for such a case is right and make a specification about negative numbers in command line(as an example, they may became non-options and in such a case this proposal will work differently).
In my bug report and a patch I proposed some specs for optparse behavior in this case, but they weren't yet accepted or declined.

Updated by felipec (Felipe Contreras) over 11 years ago

Any update on this?

Updated by felipec (Felipe Contreras) over 3 years ago

  • File 0001-optparse-add-keep_unknown-option.patch added
  • File 0002-optparse-move-dash-dash-handling-to-a-case.patch added
  • File 0003-optparse-properly-keep-dash-dash.patch added

Nobody had requested any tests. It would have been much easier if 7 years ago you had written the two lines of code required to test this.

Anyway, I've rebased my changes on top of the latest master, and added some tests.

Actions #7

Updated by hsbt (Hiroshi SHIBATA) over 3 years ago

  • File deleted (delete.patch)

Updated by felipec (Felipe Contreras) over 1 year ago

Updated on top of master yet again.

Actions #9

Updated by felipec (Felipe Contreras) over 1 year ago

  • File deleted (0001-optparse-add-keep_unknown-option.patch)
Actions #10

Updated by felipec (Felipe Contreras) over 1 year ago

  • File deleted (0002-optparse-move-dash-dash-handling-to-a-case.patch)
Actions #11

Updated by felipec (Felipe Contreras) over 1 year ago

  • File deleted (0003-optparse-properly-keep-dash-dash.patch)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0