[Twisted-Python] twisted.python.usage.Options Questions

Jp Calderone exarkun at intarweb.us
Fri May 16 14:14:53 EDT 2003

On Fri, May 16, 2003 at 07:05:47AM -0600, Justin Johnson wrote:
> Greetings,
> I'm using twisted.python.usage to handle command-line option parsing. 
> The script I have uses subcommands, so I can type:
> myscript.py subcommand -a 1 -b 2 ...
> I sub-classed BaseOptions as follows...
> [snip code]
> I have some questions though.
> 1)  Passing in the --help option displays usage info the way I'd want it,
> grabbing __doc__ from the top of the file and also displaying info about
> my subcommands.  
> [snip output]
> Is there a way to do that?

  Hmm, I don't believe so.  Usage could probably be patched to print
something slightly different for options with subcommands.

> 2)  When I just run the command without passing any options (not even a
> subcommand) I get the following error:
> [snip traceback, main() definition]
> Is there a particular test I should do on config before checking
> config.subCommand?

  Add "subCommand = None" or something similar to your Options subclass  fix
the exception you're getting.  Alternatively, just test hasattr(config,
'subCommand') before your conditional.  I often do this in postOptions and
raise a UsageError if a subcommand is required and none has been given.


"Pascal is Pascal is Pascal is dog meat."
                -- M. Devine and P. Larson, Computer Science 340
 up 14 days, 14:39, 0 users, load average: 0.01, 0.02, 0.00
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20030516/64ea0016/attachment.pgp 

More information about the Twisted-Python mailing list