Helo on optparse


#1

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…


#2

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


#3

Robert K. wrote:

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


#4

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


#5

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


#6

Hi,

At Mon, 27 Apr 2009 15:38:44 +0900,
Newb N. 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


#7

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


#8

2009/4/27 7stud – removed_email_address@domain.invalid:

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


#9

On Mon, Apr 27, 2009 at 8:25 AM, mdiam removed_email_address@domain.invalid
wrote:

OptParse already handles this and has for some time.

Jason


#10

2009/4/27 mdiam removed_email_address@domain.invalid:

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


#11

Hi,

At Sat, 2 May 2009 19:55:05 +0900,
mdiam wrote in [ruby-talk:335648]:

They are different. At least, the latter is being maintained.


#12

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://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