optional arguments; compact reporting

Alexy Khrabrov <[email protected]> Fri, 2 Nov 2007 02:14:03 +0300
Newsgroups gmane.comp.python.optik.user
Message-ID <[email protected]>
I wonder how do you implement optional arguments to Optik.  I.e., you  
can have an option

-P [file]

-- the filename is optional, with a default "data,pikl".  It works as  
follows:

-- if no -P is given, no pickle is written
-- if -P is given without the filename following, a pickle file is  
written with the default name data.pikl
-- if -P filename is given, the pickle is written to filename

How do we do optional values in Optik, with nargs <= 1?

Another question I have it how can I output a docstring right from  
the parser.add_option() block?  I prefer to define all option-related  
things in the same block once.  I'd like to output the help value  
from the block, or append it to a report.

Here's example from my Ruby wrapper for Ruby's optparse:

     name = :divisor
     help = "show divisor"
     short = "-m"
     opt.on(short, "--#{name} [STR]", help) do |val|
     	hash[:show_divisor] = true
     	hash[:divisor] = val if val
     end
     report << [name,short,help]

-- notice that my report list is built with the exact values of all  
options, regardless of whether they're encountered or not.  The I  
simply walk through the report list to print a report for this run:

       report.each do |name,short,help|
         val = opts.name || "----"
         STDERR.printf "--%s (%s)\t\%s\t%s\n", o, short, val, help
       end if verbose

How can I group such reporting together with add_option in Optik?

Cheers,
Alexy

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/