On Tue, 19 Dec 2006 17:36:43 +0900, Eric Hodel <drbrain / segment7.net>  
wrote:

> On Dec 18, 2006, at 23:49, Zev Blut wrote:
>> On Tue, 19 Dec 2006 16:31:48 +0900, Eric Hodel <drbrain / segment7.net>  
>> wrote:
>>> On Dec 18, 2006, at 22:34, Zev Blut wrote:

>>>> 2)
>>>> I was reading through the Programming Ruby book and found a part that
>>>> showed how to use rdoc to create usage messages.  I figured this might
>>>> be better than my normal technique so I used it in Saikuro.  This has
>>>> caused a number of problems actually.
>>>
>>> What does this technique look like?  I'm not familiar with it.
>>
>> http://ruby-doc.org/stdlib/libdoc/rdoc/rdoc/classes/RDoc.html#M001338
>>
>> It is something like this:
>>
>> -------------
>> #!/usr/bin/env ruby
>> # == Usage
>> # Some stuff on how to use a program.
>> # More stuff
>>
>> require 'rdoc/usage'
>>
>> RDoc.usage
>
> Since RDoc.usage uses #caller to figure out which file to read you  
> should be able to combine RDoc.usage with my method above, and the usage  
> will live in the library file.

I have done a quick refactoring to create something similar to your
suggestions.  The bin part works now, but the RDoc.usage still gives a
RubyGems message.

Just in case here is my ruby version
# ruby -v
ruby 1.8.5 (2006-08-25) [i686-linux]

I stuck some debugging puts in the RDoc.usage_no_exit method and this
is what I got:

# saikuro -?
/usr/bin/saikuro: invalid option -- ?
Caller main program file is /usr/bin/saikuro
Caller stack is
/usr/lib/ruby/1.8/rdoc/usage.rb:93:in `usage'
/usr/lib/ruby/gems/1.8/gems/Saikuro-1.0.0/bin/saikuro:175:in `run'
/usr/lib/ruby/gems/1.8/gems/Saikuro-1.0.0/bin/saikuro:200
/usr/bin/saikuro:18:in `load'
/usr/bin/saikuro:18
This file was generated by RubyGems.

The application 'Saikuro' is installed as part of a gem, and this file
is here to facilitate running it.


-----

Here is the specific piece of code in rdoc/usage usage_no_exit

  main_program_file = caller[-1].sub(/:\d+$/, '')

It appears that it assumes that the last caller on the stack is the
one who has the usage comments.  But, in this current RubyGems bin
case the line above should be something like this:

  main_program_file = caller[1].sub(/:\d+(:.*)?$/, '')

If you read the synopsis of RDoc/usage it states that it will always
take the usage from the main program file.  This appears to be in
conflict with RubyGems.  I suppose one could hack the method to look
at the caller stack and if it sees a RubyGems /bin/ in the caller
stack uses the first instance as the main_program_file ?

Thanks,
Zev