You want to display the usage info for your code both in the comments at the top of the source file and have it printed out when given the -h or –help command line option. The problem with this is that it is hard to keep the two in sync - one is embedded in the code the other is just a comment. NOT ANY MORE. RDoc::usage parses the comments at the top of the file and uses that for printing the usage message:
#!/usr/bin/ruby
#==Usage
# usage: test.rb
require 'rubygems'
require 'rdoc/usage'
RDoc::usage
There are some problems though:
- Stub /bin files. If you want to use a ruby gem format of putting your bin files in /bin and the bulk of your code in /lib then there is a problem because RDoc::usage on only looks at the comments from the first file (which would be the stub bin file)
No comments:
Post a Comment