77eef7d6d701ea0c8791b8011c7d70032578bc87
[sfa.git] / sfa / client / candidates.py
1 ### utility to match command-line args to names
2 class Candidates:
3     def __init__ (self, names):
4         self.names=names
5     # is an input string acceptable for one of the known names?
6     @staticmethod
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
10     # or None otherwise
11     def only_match (self, input):
12         matches=[ name for name in self.names if Candidates.fits(input,name) ]
13         if len(matches)==1: return matches[0]
14         else: return None
15