+ def canonical_cmd(self, key):
+ """Return the canonical name for a possibly-shortenned
+ command name.
+ """
+ candidates = [cmd for cmd in self.keys() if cmd.startswith(key)]
+
+ if not candidates:
+ out.error('Unknown command: %s' % key,
+ 'Try "%s help" for a list of supported commands' % prog)
+ sys.exit(utils.STGIT_GENERAL_ERROR)
+ elif len(candidates) > 1:
+ out.error('Ambiguous command: %s' % key,
+ 'Candidates are: %s' % ', '.join(candidates))
+ sys.exit(utils.STGIT_GENERAL_ERROR)
+
+ return candidates[0]
+