-commands = {
- 'add': stgit.commands.add,
- 'applied': stgit.commands.applied,
- 'delete': stgit.commands.delete,
- 'diff': stgit.commands.diff,
- 'clean': stgit.commands.clean,
- 'export': stgit.commands.export,
- 'files': stgit.commands.files,
- 'import': stgit.commands.imprt,
- 'init': stgit.commands.init,
- 'mail': stgit.commands.mail,
- 'new': stgit.commands.new,
- 'pop': stgit.commands.pop,
- 'pull': stgit.commands.pull,
- 'push': stgit.commands.push,
- 'refresh': stgit.commands.refresh,
- 'rename': stgit.commands.rename,
- 'resolved': stgit.commands.resolved,
- 'rm': stgit.commands.rm,
- 'series': stgit.commands.series,
- 'status': stgit.commands.status,
- 'top': stgit.commands.top,
- 'unapplied':stgit.commands.unapplied,
- }
+class Commands(dict):
+ """Commands class. It performs on-demand module loading
+ """
+ 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]
+
+ def __getitem__(self, key):
+ """Return the command python module name based.
+ """
+ global prog
+
+ cmd_mod = self.get(key) or self.get(self.canonical_cmd(key))
+
+ __import__('stgit.commands.' + cmd_mod)
+ return getattr(stgit.commands, cmd_mod)
+
+commands = Commands({
+ 'add': 'add',
+ 'applied': 'applied',
+ 'branch': 'branch',
+ 'delete': 'delete',
+ 'diff': 'diff',
+ 'clean': 'clean',
+ 'clone': 'clone',
+ 'commit': 'commit',
+ 'cp': 'copy',
+ 'edit': 'edit',
+ 'export': 'export',
+ 'files': 'files',
+ 'float': 'float',
+ 'fold': 'fold',
+ 'goto': 'goto',
+ 'hide': 'hide',
+ 'id': 'id',
+ 'import': 'imprt',
+ 'init': 'init',
+ 'log': 'log',
+ 'mail': 'mail',
+ 'new': 'new',
+ 'patches': 'patches',
+ 'pick': 'pick',
+ 'pop': 'pop',
+ 'pull': 'pull',
+ 'push': 'push',
+ 'rebase': 'rebase',
+ 'refresh': 'refresh',
+ 'rename': 'rename',
+ 'repair': 'repair',
+ 'resolved': 'resolved',
+ 'rm': 'rm',
+ 'series': 'series',
+ 'show': 'show',
+ 'sink': 'sink',
+ 'status': 'status',
+ 'sync': 'sync',
+ 'top': 'top',
+ 'unapplied': 'unapplied',
+ 'uncommit': 'uncommit',
+ 'unhide': 'unhide'
+ })
+
+# classification: repository, stack, patch, working copy
+repocommands = (
+ 'clone',
+ 'id',
+ )
+stackcommands = (
+ 'applied',
+ 'branch',
+ 'clean',
+ 'commit',
+ 'float',
+ 'goto',
+ 'hide',
+ 'init',
+ 'patches',
+ 'pop',
+ 'pull',
+ 'push',
+ 'rebase',
+ 'repair',
+ 'series',
+ 'sink',
+ 'top',
+ 'unapplied',
+ 'uncommit',
+ 'unhide',
+ )
+patchcommands = (
+ 'delete',
+ 'edit',
+ 'export',
+ 'files',
+ 'fold',
+ 'import',
+ 'log',
+ 'mail',
+ 'new',
+ 'pick',
+ 'refresh',
+ 'rename',
+ 'show',
+ 'sync',
+ )
+wccommands = (
+ 'add',
+ 'cp',
+ 'diff',
+ 'resolved',
+ 'rm',
+ 'status',
+ )