# OptParse bug?

**URL:** <https://www.ruby-forum.com/t/optparse-bug/159119>\
**Category:** Ruby\
**Created:** [January 31, 2009, 9:03pm UTC](https://www.ruby-forum.com/t/optparse-bug/159119 "2009-01-31T21:03:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [January 31, 2009, 9:03pm UTC](https://www.ruby-forum.com/t/optparse-bug/159119/1 "2009-01-31T21:03:15Z")

</div>

With this file:

C:\dev\thesis\_p2pwebcode\src\>cat example.rb  
require ‘optparse’

OptionParser.new do |opts|

```
opts.on('-p', '--do_multiples_with_variant=NAME', 'multiples variant

```

ex: ') do |name|  
end  
end.parse!

I get the following output:  
Usage: example [options]  
-p=NAME multiples variant ex:  
–do\_multiples\_with\_variant

however it doesn’t actually accept -p=NAME  
it accepts -pNAME

Anybody know if this is expected?  
Thanks!  
-=r

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [January 31, 2009, 9:41pm UTC](https://www.ruby-forum.com/t/optparse-bug/159119/2 "2009-01-31T21:41:26Z")

</div>

Roger P. wrote:

> end.parse!
> 
> Anybody know if this is expected?  
> Thanks!  
> -=r

Seems to be a unix standard:

[http://www.faqs.org/docs/artu/ch10s05.html](http://www.faqs.org/docs/artu/ch10s05.html)

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [January 31, 2009, 11:34pm UTC](https://www.ruby-forum.com/t/optparse-bug/159119/3 "2009-01-31T23:34:52Z")

</div>

> Seems to be a unix standard:
> 
> [http://www.faqs.org/docs/artu/ch10s05.html](http://www.faqs.org/docs/artu/ch10s05.html)

So were you saying that having help output like  
“-p=NAME” is standard when the input is actually “-pNAME” in use?

OptParse typically outputs  
“-p --long=NAME”

but in this case it seems to output  
“-p=NAME --long”

for some reason.

Thoughts?  
-=r

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [January 31, 2009, 11:55pm UTC](https://www.ruby-forum.com/t/optparse-bug/159119/4 "2009-01-31T23:55:43Z")

</div>

Roger P. wrote:

> but in this case it seems to output  
> “-p=NAME --long”
> 
> for some reason.
> 
> Thoughts?  
> -=r

So, both of the following are issues, right?

1. parser doesn’t accept syntax “-p=NAME”, but only “-pNAME”

2. generated help text suggests otherwise, that the former is accepted

IMO, #1 is standard, but #2 is possibly the wrong behavior.

What is causing the difference between typical output and this case? Do  
you see the “-p --long=NAME” variant for other options in the same  
program? Looking at comparable output in my own use of optparse, the  
format tends to look like this:

```
 -r, --read-options [FILE] Read options from file [stdin]
```

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [February 1, 2009, 12:40am UTC](https://www.ruby-forum.com/t/optparse-bug/159119/5 "2009-02-01T00:40:51Z")

</div>

Le 31 janvier 2009 à 23:55, Joel VanderWerf a écrit :

> What is causing the difference between typical output and this case? Do  
> you see the “-p --long=NAME” variant for other options in the same  
> program? Looking at comparable output in my own use of optparse, the  
> format tends to look like this:
> 
> ```
> -r, --read-options [FILE] Read options from file [stdin]
> 
> ```

It seems to be the length of the option name :

0:33 fred@ardberg:/data/ruby/blackops% irb

> > require ‘optparse’ ; OptionParser.new do |o|  
> > ?\> o.on(’-p’, ‘–12345678901234567890=NAME’,  
> > ?\> 'multiples variant ex: ') {}
> 
> > end.parse([’-h’])  
> > Usage: irb [options]  
> > -p, --12345678901234567890=NAME multiples variant ex:

> > require ‘optparse’ ; OptionParser.new do |o|  
> > ?\> o.on(’-p’, ‘–123456789012345678901234567890=NAME’,  
> > ?\> 'multiples variant ex: ') {}
> 
> > end.parse([’-h’])  
> > Usage: irb [options]  
> > -p=NAME  
> > –123456789012345678901234567890  
> > multiples variant ex:

When short + long + value + description are too long to hold on a single  
line, optionparser tries to present it better, and it shows the bug.

Fred
