Helo on optparse

N

Newb Newb

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..
 
R

Robert Klemme

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
 
N

Newb Newb

Robert said:
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
 
7

7stud --

Newb said:
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.
 
N

Nobuyoshi Nakada

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]
 
M

mdiam

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
 
R

Robert Klemme

2009/4/27 7stud -- said:
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.rubybestpractices.com/
 
R

Robert Klemme

2009/4/27 mdiam said:
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
 
J

Jason Roelofs

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
 
M

mdiam

How can we add the classical "--" pseudo-option which says not
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/rdoc/classes/OptionParser.html
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
 
N

Nobuyoshi Nakada

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top