Re: optparse question: how to warn of missing positional arguments

Robert Klemme <[email protected]>
Newsgroups gmane.comp.lang.ruby.general
Message-ID <CAM9pMnN_1ZJg_CWgcfX3EsMTGJ_zW-zQVuAJp+Y9QYbG1EJ88A@mail.gmail.com>
On Fri, Mar 22, 2019 at 8:49 PM Artie Ziff <[email protected]> wrote:

> My goal is to force a display of the banner (usage string) when a positional parameter is not present; in the sense of ARGV[1] == nil

I do not think it is possible to ever get into that situation except
for messing with ARGV in the ruby program. If you do not do that there
will never be Nil in ARGV. Or are you talking about ARGV being too
short? In that case, there are two situations

1. a mandatory arg is missing for an option, then OptionParser will
flag this anyway.
2. a mandatory non option argument is missing, then you just check for
empty ARGV (or generally the length of ARGV) and flag this as error
outside of OptionParser processing.

Kind regards

robert

-- 
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.