Project

General

Profile

Actions

Misc #14692

open

Question: Ruby stdlib's Option Parser

Added by xz0r (xz0r xz0r) over 6 years ago. Updated 8 months ago.

Status:
Assigned
[ruby-core:86563]

Description

Hi,

The documentation of OptionParser says for further I can ask questions here.

Is there way to disable command/option completion ? I don't want a short "-f" option defined automatically if I declare "--file-name" , I have searched the internet and couldn't find a solution.

Updated by xz0r (xz0r xz0r) over 6 years ago

Hi,

The documentation of OptionParser says for further I can ask questions here.

Is there way to disable command/option completion ? I don't want a short "-f" option defined automatically if I declare "--file-name" , I have searched the internet and couldn't find a solution.

Any suggestions/work arounds would help me a lot, thanks !

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

Currently, it is not able.
A possible workaround is to define an option which raise OptionParser::InvalidOption.

Updated by xz0r (xz0r xz0r) over 6 years ago

nobu (Nobuyoshi Nakada) wrote:

Currently, it is not able.
A possible workaround is to define an option which raise OptionParser::InvalidOption.

Can you please show me an example code on how to achieve this ?

I see the issue is in parser_in_order method

              begin
                sw, = complete(:short, opt)
                # short option matched.
                val = arg.sub(/\A-/, '')
                has_arg = true
              rescue InvalidOption
                # if no short options match, try completion with long
                # options.
                sw, = complete(:long, opt)
                eq ||= !rest
              end

where if no short options match, long options are matched. I want to suppress this behaviour and instead of rescue InvalidOption , I want to raise InvalidOption

Getoptlong doesn't have this behaviour of automatically matching long options, similar to Option Parsers in other standard libraries like that of python for example. It'd be great if its possible to have a functionality where users of OptionParser can suppress this behaviour..

Actions #4

Updated by hsbt (Hiroshi SHIBATA) 8 months ago

  • Status changed from Open to Assigned
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0