/stdhome

To get this branch, use:
bzr branch http://bzr.ed.am/stdhome

« back to all changes in this revision

Viewing changes to lib/stdhome/program.py

  • Committer: Tim Marston
  • Date: 2014-09-09 19:13:33 UTC
  • Revision ID: tim@ed.am-20140909191333-0b7hrzonxce8mgy3
attempt to allow arguments before main command by treating the first thing that
doesn't look like an option as the command

Show diffs side-by-side

added added

removed removed

141
141
 
142
142
        def run( self ):
143
143
                # make an initial attempt to parse the command line, looking only for
144
 
                # --help, --version and --verbose, so that they have the chance to run
145
 
                # without a command being specified
 
144
                # --help and --version, so that they have the chance to run without a
 
145
                # command being specified
146
146
                try:
147
147
                        opts, args = getopt.gnu_getopt(
148
 
                                sys.argv[ 1: ], "v",
149
 
                                [ "verbose", "help", "version" ] )
 
148
                                sys.argv[ 1: ], "",
 
149
                                [ "help", "version" ] )
150
150
 
151
151
                        for opt, optarg in opts:
152
152
                                # we only show help if there are no non-option arguments (e.g.,
153
153
                                # a command) specified.  If a command has been specified it will
154
154
                                # have to be parsed and --help will be handled by it, instead)
155
 
                                if opt in [ '--verbose', '-v' ]:
156
 
                                        the.verbose += 1
157
 
                                elif opt == "--help" and len( args ) == 0:
 
155
                                if opt == "--help" and len( args ) == 0:
158
156
                                        self.print_help()
159
157
                                elif opt == "--version":
160
158
                                        self.print_version()