Changeset 3312 for pykota

Show
Ignore:
Timestamp:
02/02/08 11:49:37 (17 years ago)
Author:
jerome
Message:

Now handles -v|--version automatically at parsing time.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/commandline/parser.py

    r3305 r3312  
    2222"""This modules defines a command line options parser for PyKota's command line tools.""" 
    2323 
     24import sys 
     25import os 
    2426import optparse 
    2527from gettext import gettext as _ 
     
    8991        """Adds an usage example.""" 
    9092        self.examples.append(("%prog " + command, doc)) 
     93         
     94    def parse_args(self, args=None, values=None) : 
     95        """Parses command line arguments, and handles -v|--version as well.""" 
     96        (options, arguments) = optparse.OptionParser.parse_args(self, args, values) 
     97        if options.version : 
     98            sys.stdout.write("%s (PyKota) %s\n" % (os.path.basename(sys.argv[0]), 
     99                                                   version.__version__)) 
     100            sys.exit(0) 
     101        return (options, arguments)