--- /dev/null
+### utility to match command-line args to names
+class Candidates:
+ def __init__ (self, names):
+ self.names=names
+ # is an input string acceptable for one of the known names?
+ @staticmethod
+ def fits (input, name):
+ return name.find(input)==0
+ # returns one of the names if the input name has a unique match
+ # or None otherwise
+ def only_match (self, input):
+ matches=[ name for name in self.names if Candidates.fits(input,name) ]
+ if len(matches)==1: return matches[0]
+ else: return None
+
from sfa.trust.hierarchy import Hierarchy
from sfa.trust.gid import GID
+from sfa.client.candidates import Candidates
+
pprinter = PrettyPrinter(indent=4)
try:
return func
return _decorator
-### utility to match command-line args to names
-class Candidates:
- def __init__ (self, names):
- self.names=names
- # is an input string acceptable for one of the known names?
- @staticmethod
- def fits (input, name):
- return name.find(input)==0
- # returns one of the names if the input name has a unique match
- # or None otherwise
- def only_match (self, input):
- matches=[ name for name in self.names if Candidates.fits(input,name) ]
- if len(matches)==1: return matches[0]
- else: return None
-
class Commands(object):
def _get_commands(self):
command_names = []
from sfa.client.sfaserverproxy import SfaServerProxy, ServerException
from sfa.client.client_helper import pg_users_arg, sfa_users_arg
from sfa.client.return_value import ReturnValue
+from sfa.client.candidates import Candidates
CM_PORT=12346
self.print_command_help(options)
return -1
- command = args[0]
+ # complete / find unique match with command set
+ command_candidates = Candidates (self.available_names)
+ input = args[0]
+ command = command_candidates.only_match(input)
+ if not command:
+ self.print_command_help(options)
+ sys.exit(1)
+ # second pass options parsing
self.command_parser = self.create_command_parser(command)
(command_options, command_args) = self.command_parser.parse_args(args[1:])
self.command_options = command_options