1 ### utility to match command-line args to names
3 def __init__ (self, names):
5 # is an input string acceptable for one of the known names?
7 def fits (input, name):
8 return name.find(input)==0
9 # returns one of the names if the input name has a unique match
11 def only_match (self, input):
12 if input in self.names: return input
13 matches=[ name for name in self.names if Candidates.fits(input,name) ]
14 if len(matches)==1: return matches[0]
17 #################### minimal test
19 ('create delete reset resources slices start status stop version create_gid',
34 ('create_','create_gid'),
35 ('create_g','create_gid'),
36 ('create_gi','create_gid'),
37 ('create_gid','create_gid'),
41 def test_candidates ():
42 for (names, tuples) in candidates_specs:
44 for (input,expected) in tuples:
45 got=Candidates(names).only_match(input)
46 if got==expected: print '.',
47 else: print 'X FAIL','names[',names,'] input',input,'expected',expected,'got',got
49 if __name__ == '__main__':