Re: --help option: sys.exit or return?
Greg Ward <[email protected]> Tue, 19 Oct 2004 20:45:56 -0400
| Newsgroups | gmane.comp.python.optik.user |
|---|---|
| Message-ID | <[email protected]> |
On 19 October 2004, Miguel A Figueroa-Villanneva said:
> Both methods provide a way to get around this, although not optimal as you
> mention. I was looking at the 'getargs' package for reference (I'll stick
> with Optik though) and noticed that they implement an exception system;
> where they propagate exceptions: HelpQuery, VersionQuery, UsageError,
> KeyError, and ValueError. This of course, means that it is up to the user
> to catch these exceptions to exit from the system.
>
> I'm thinking this is a nice solution, although I can think of reasons why
> not to go that direction as well. For example, the user has to write more
> code and always implement these exceptions...
>
> Are there any more fundamental reasons why this approach wouldn't be a
> good one to follow?
For me, 100% of scripts that use Optik are of the "parse command-line
args and exit on error or help/version query". I don't want to write
duplicate logic in every single one of those scripts to handle the "exit
on error or help/version query" bit -- that would get tiresome very
quickly. So I have Optik do it for me.
I suspect that at least 90% of scripts in the wild that use Optik are of
the same pattern. Optik 1.5 has a minor refactoring where I pulled out
an exit() method that should address the small minority of cases where
exiting immediately is not the right thing to do. Case closed, as far
as I am concerned.
Greg
--
Greg Ward <[email protected]> http://www.gerg.ca/
MTV -- get off the air!
-- Dead Kennedys
-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl