-commands = {
- 'add': stgit.commands.add,
- 'applied': stgit.commands.applied,
- 'delete': stgit.commands.delete,
- 'diff': stgit.commands.diff,
- 'export': stgit.commands.export,
- 'files': stgit.commands.files,
- 'init': stgit.commands.init,
- 'new': stgit.commands.new,
- 'pop': stgit.commands.pop,
- 'push': stgit.commands.push,
- 'refresh': stgit.commands.refresh,
- '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 __getitem__(self, key):
+ cmd_mod = self.get(key)
+ __import__('stgit.commands.' + cmd_mod)
+ return getattr(stgit.commands, cmd_mod)
+
+commands = Commands({
+ 'add': 'add',
+ 'applied': 'applied',
+ 'assimilate': 'assimilate',
+ 'branch': 'branch',
+ 'delete': 'delete',
+ 'diff': 'diff',
+ 'clean': 'clean',
+ 'clone': 'clone',
+ 'commit': 'commit',
+ 'export': 'export',
+ 'files': 'files',
+ 'float': 'float',
+ 'fold': 'fold',
+ 'goto': 'goto',
+ 'id': 'id',
+ 'import': 'imprt',
+ 'init': 'init',
+ 'log': 'log',
+ 'mail': 'mail',
+ 'new': 'new',
+ 'patches': 'patches',
+ 'pick': 'pick',
+ 'pop': 'pop',
+ 'pull': 'pull',
+ 'push': 'push',
+ 'refresh': 'refresh',
+ 'rename': 'rename',
+ 'resolved': 'resolved',
+ 'rm': 'rm',
+ 'series': 'series',
+ 'show': 'show',
+ 'status': 'status',
+ 'top': 'top',
+ 'unapplied': 'unapplied',
+ 'uncommit': 'uncommit'
+ })
+
+# classification: repository, stack, patch, working copy
+repocommands = (
+ 'branch',
+ 'clone',
+ 'id',
+ 'pull'
+ )
+stackcommands = (
+ 'applied',
+ 'assimilate',
+ 'clean',
+ 'commit',
+ 'float',
+ 'goto',
+ 'init',
+ 'pop',
+ 'push',
+ 'series',
+ 'top',
+ 'unapplied',
+ 'uncommit'
+ )
+patchcommands = (
+ 'delete',
+ 'export',
+ 'files',
+ 'fold',
+ 'import',
+ 'log',
+ 'mail',
+ 'new',
+ 'pick',
+ 'refresh',
+ 'rename',
+ 'show'
+ )
+wccommands = (
+ 'add',
+ 'diff',
+ 'patches',
+ 'resolved',
+ 'rm',
+ 'status'
+ )
+
+def _print_helpstring(cmd):
+ print ' ' + cmd + ' ' * (12 - len(cmd)) + commands[cmd].help
+