/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-12 13:03:11 UTC
  • Revision ID: tim@ed.am-20140412130311-kwednshmt07i1a26
remove ambiguous argument parsing (the first argument should be the command,
because we can't reliably parse-away options, which may have argument, e.g.,
"stdhome -r test status")

Show diffs side-by-side

added added

removed removed

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
 
 
142
126
        def run( self ):
143
127
                # make an initial attempt to parse the command line, looking only for
144
128
                # --help and --version, so that they have the chance to run without a
164
148
                # read program configuration
165
149
                self.read_config()
166
150
 
167
 
                # find the first non-option argument (the command)
168
 
                the.command = self.get_command_argument( sys.argv[ 1: ] )
 
151
                # the first argument should be the command
 
152
                the.command = sys.argv[ 1 ] if len( sys.argv ) > 1 else None
169
153
                if the.command == None:
170
154
                        self.print_usage( "missing command" )
171
155