Project

General

Profile

Misc #14692

Question: Ruby stdlib's Option Parser

Added by xz0r (xz0r xz0r) over 1 year ago. Updated over 1 year ago.

Status:
Open
Priority:
Normal
[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.

History

Updated by xz0r (xz0r xz0r) over 1 year 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 1 year ago

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

Updated by xz0r (xz0r xz0r) over 1 year 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..

Also available in: Atom PDF