Forum: Ruby Helo on optparse

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3083ca8f0496edaac2fa10c20630d0bc?d=identicon&s=25 Newb Newb (newb)
on 2009-04-27 06:28
hi i m using optparse.

in that for copying i have implemented like below

opts.on('-r', '--recursive RECURSIVE',
         "specify for recursive copy" ) do | r|

  options.recursive = true

end

opts.on('-o', '--overwrite OVERWRITE',
         "specify to copy files overwriting the previous ones" ) do | o|

options.overwrite = true

end


if i use -r it does recursive copy without deleteing existing folders.

and if i use -o it does overwritting of given files..

is it possible to use both command at once...

if so ...pls advice on this regard...

pls help

thank you..
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2009-04-27 08:25
(Received via mailing list)
On 27.04.2009 06:28, Newb Newb wrote:
>
> and if i use -o it does overwritting of given files..
>
> is it possible to use both command at once...

That actually seems to be not a question about OptionParser but rather
your implementation, which we cannot see.  With OptionParser you can
have both options on the command line.  Your code just needs to react
properly (i.e. in your intended sense) on those options.

Kind regards

  robert
3083ca8f0496edaac2fa10c20630d0bc?d=identicon&s=25 Newb Newb (newb)
on 2009-04-27 08:38
Robert Klemme wrote:
> On 27.04.2009 06:28, Newb Newb wrote:
>>
>> and if i use -o it does overwritting of given files..
>>
>> is it possible to use both command at once...
>
> That actually seems to be not a question about OptionParser but rather
> your implementation, which we cannot see.  With OptionParser you can
> have both options on the command line.  Your code just needs to react
> properly (i.e. in your intended sense) on those options.
>
> Kind regards
>
>   robert

thanks for the reply...

 what is the use of opts.separator"" in Option Parser
3083ca8f0496edaac2fa10c20630d0bc?d=identicon&s=25 Newb Newb (newb)
on 2009-04-27 08:42
>>
>> That actually seems to be not a question about OptionParser but rather
>> your implementation, which we cannot see.  With OptionParser you can
>> have both options on the command line.  Your code just needs to react
>> properly (i.e. in your intended sense) on those options.
>>
>> Kind regards
>>
>>   robert
>
> thanks for the reply...
>
>  what is the use of opts.separator"" in Option Parser

pls reply...i may sound dump
54404bcac0f45bf1c8e8b827cd9bb709?d=identicon&s=25 7stud -- (7stud)
on 2009-04-27 12:07
Newb Newb wrote:

> pls reply...i may sound dump

The OptionParser module is so poorly documented it should be stricken
from ruby.  Anyone who would let that piece of junk be part of their
programming language needs to have their head examined.
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2009-04-27 12:33
(Received via mailing list)
Hi,

At Mon, 27 Apr 2009 15:38:44 +0900,
Newb Newb wrote in [ruby-talk:335121]:
>  what is the use of opts.separator"" in Option Parser

$ ruby -roptparse -e 'ARGV.options{|opts|opts.separator
"---";opts.separator "appears as is";opts.parse!}' -- -h
Usage: -e [options]
---
appears as is
7ece60b3b5bb235d1b6df89727ca6cf7?d=identicon&s=25 mdiam (Guest)
on 2009-04-27 14:25
(Received via mailing list)
Another question about OptionParser class:

How can we add the classical "--" pseudo-option which says not
to parse the following flags as in

rm -- -file_name_to_delete_with_a_dash_in_it

Thank you very much
-- Maurice
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2009-04-27 14:49
(Received via mailing list)
2009/4/27 7stud -- <bbxx789_05ss@yahoo.com>:
> The OptionParser module is so poorly documented it should be stricken
> from ruby.

While the documentation of OptionParser is not perfect it is sufficient
IMHO.

>  Anyone who would let that piece of junk be part of their
> programming language needs to have their head examined.

This is a completely inappropriate statement. If you don't like
OptionParser, then don't use it.  Apparently other people make good
use of it.

robert
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2009-04-27 15:02
(Received via mailing list)
2009/4/27 mdiam <Maurice.Diamantini@gmail.com>:
> Another question about OptionParser class:
>
> How can we add the classical "--" pseudo-option which says not
> to parse the following flags as in
>
> rm -- -file_name_to_delete_with_a_dash_in_it

Did you try it out?  This is default behavior of OptionParser:

15:00:10 Temp$ ruby19 x.rb -x a b
["-x", "a", "b"]
x found!
["a", "b"]
15:00:18 Temp$ ruby19 x.rb -- -x a b
["--", "-x", "a", "b"]
["-x", "a", "b"]
15:00:22 Temp$ cat x.rb
require 'optparse'

p ARGV

OptionParser.new do |o|
  o.on "-x" do
    puts "x found!"
  end
end.parse! ARGV

p ARGV

15:00:25 Temp$

Kind regards

robert
83ca41657a99b65d99889abe712ba5e2?d=identicon&s=25 Jason Roelofs (Guest)
on 2009-04-27 15:13
(Received via mailing list)
On Mon, Apr 27, 2009 at 8:25 AM, mdiam <Maurice.Diamantini@gmail.com>
wrote:
>
>


OptParse already handles this and has for some time.

Jason
7ece60b3b5bb235d1b6df89727ca6cf7?d=identicon&s=25 mdiam (Guest)
on 2009-05-02 12:55
(Received via mailing list)
> > How can we add the classical "--" pseudo-option which says not
> > to parse the following flags as in
>
> OptParsealready handles this and has for some time.

Thanks Jason and Robert, it works!
Yes as it was not mention in the documentation, I did just try it.
But I had a mistake in my code (using "opt.parse" instead of
"opt.parse!" ).
Now it works.

About the original subject (OptionParser bad documentation)
I agree that we miss a true reference documentation:

- http://optionparser.rubyforge.org
  give a very good reference (from Jim Freeze), but not sure it is
the
  same package, neither if it is still maintained

-
http://www.ruby-doc.org/stdlib/libdoc/optparse/rdo...
  seems to be to good package, but the documentation it's just an
  (good) exemple.

Perhaps the doc from first url should be include (and perhaps updated)
in the official documentation?

Nevertheless, OptinParser is a very usefull package and I use it!

-- Maurice
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2009-05-02 15:23
(Received via mailing list)
Hi,

At Sat, 2 May 2009 19:55:05 +0900,
mdiam wrote in [ruby-talk:335648]:
>
> - http://optionparser.rubyforge.org
>   give a very good reference (from Jim Freeze), but not sure it is the
>   same package, neither if it is still maintained
>
> - http://www.ruby-doc.org/stdlib/libdoc/optparse/rdo...
>   seems to be to good package, but the documentation it's just an
>   (good) exemple.

They are different.  At least, the latter is being maintained.
This topic is locked and can not be replied to.