/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-04-05 22:30:23 UTC
  • Revision ID: tim@ed.am-20140405223023-3co87mbvnxwk1l65
added revert command

Show diffs side-by-side

added added

removed removed

Lines of Context:
123
123
                return None
124
124
 
125
125
 
 
126
        def get_command_argument( self, args ):
 
127
                """
 
128
                Find the first program argument what isn't an option argument.
 
129
 
 
130
        Arguments:
 
131
        - `args`: the program arguments
 
132
        """
 
133
                while args:
 
134
                        if args[ 0 ] == '--':
 
135
                                return args[ 1 ] if len( args ) > 1 else None
 
136
                        if args[ 0 ][ 0 : 1 ] != '-':
 
137
                                return args[ 0 ]
 
138
                        args = args[ 1 : ]
 
139
                return None
 
140
 
 
141
 
126
142
        def run( self ):
127
143
                # make an initial attempt to parse the command line, looking only for
128
144
                # --help and --version, so that they have the chance to run without a
148
164
                # read program configuration
149
165
                self.read_config()
150
166
 
151
 
                # the first argument should be the command
152
 
                the.command = sys.argv[ 1 ] if len( sys.argv ) > 1 else None
 
167
                # find the first non-option argument (the command)
 
168
                the.command = self.get_command_argument( sys.argv[ 1: ] )
153
169
                if the.command == None:
154
170
                        self.print_usage( "missing command" )
155
171