[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Helo on optparse

Newb Newb

4/27/2009 4:28:00 AM

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..
--
Posted via http://www.ruby-....

23 Answers

Robert Klemme

4/27/2009 6:21:00 AM

0

On 27.04.2009 06:28, Newb Newb wrote:
> 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...

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

Newb Newb

4/27/2009 6:39:00 AM

0

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





--
Posted via http://www.ruby-....

Newb Newb

4/27/2009 6:42:00 AM

0


>>
>> 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
--
Posted via http://www.ruby-....

7stud --

4/27/2009 10:07:00 AM

0

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.



--
Posted via http://www.ruby-....

Nobuyoshi Nakada

4/27/2009 10:32:00 AM

0

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

--
Nobu Nakada

mdiam

4/27/2009 12:22:00 PM

0

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

Robert Klemme

4/27/2009 12:48:00 PM

0

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 IMH=
O.

> =A0Anyone 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


--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestprac...

Robert Klemme

4/27/2009 1:02:00 PM

0

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


--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestprac...

Jason Roelofs

4/27/2009 1:12:00 PM

0

On Mon, Apr 27, 2009 at 8:25 AM, mdiam <Maurice.Diamantini@gmail.com> wrote:
> 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
>
>
>


OptParse already handles this and has for some time.

Jason

mdiam

5/2/2009 10:55:00 AM

0

> > 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.rub...
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/rdoc/classes/OptionP...
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