Don't use / as separatar since it is common i branch names
[stgit] / stgit / main.py
index 49089e6..eb634b4 100644 (file)
@@ -22,6 +22,7 @@ import sys, os
 from optparse import OptionParser
 
 import stgit.commands
+from stgit.utils import out
 
 #
 # The commands map
@@ -36,14 +37,12 @@ class Commands(dict):
         candidates = [cmd for cmd in self.keys() if cmd.startswith(key)]
 
         if not candidates:
-            print >> sys.stderr, 'Unknown command: %s' % key
-            print >> sys.stderr, '  Try "%s help" for a list of ' \
-                  'supported commands' % prog
+            out.error('Unknown command: %s' % key,
+                      'Try "%s help" for a list of supported commands' % prog)
             sys.exit(1)
         elif len(candidates) > 1:
-            print >> sys.stderr, 'Ambiguous command: %s' % key
-            print >> sys.stderr, '  Candidates are: %s' \
-                  % ', '.join(candidates)
+            out.error('Ambiguous command: %s' % key,
+                      'Candidates are: %s' % ', '.join(candidates))
             sys.exit(1)
 
         return candidates[0]
@@ -68,6 +67,7 @@ commands = Commands({
     'clean':            'clean',
     'clone':            'clone',
     'commit':           'commit',
+    'cp':              'copy',
     'export':           'export',
     'files':            'files',
     'float':            'float',
@@ -92,6 +92,7 @@ commands = Commands({
     'rm':               'rm',
     'series':           'series',
     'show':             'show',
+    'sink':             'sink',
     'status':           'status',
     'sync':             'sync',
     'top':              'top',
@@ -102,28 +103,30 @@ commands = Commands({
 
 # classification: repository, stack, patch, working copy
 repocommands = (
-    'branch',
     'clone',
     'id',
-    'pull'
     )
 stackcommands = (
     'applied',
     'assimilate',
+    'branch',
     'clean',
     'commit',
     'float',
     'goto',
     'hide',
     'init',
+    'patches',
     'pop',
+    'pull',
     'push',
     'rebase',
     'series',
+    'sink',
     'top',
     'unapplied',
     'uncommit',
-    'unhide'
+    'unhide',
     )
 patchcommands = (
     'delete',
@@ -138,15 +141,15 @@ patchcommands = (
     'refresh',
     'rename',
     'show',
-    'sync'
+    'sync',
     )
 wccommands = (
     'add',
+    'cp',
     'diff',
-    'patches',
     'resolved',
     'rm',
-    'status'
+    'status',
     )
 
 def _print_helpstring(cmd):
@@ -216,8 +219,7 @@ def main():
         if len(sys.argv) == 3 and not sys.argv[2] in ['-h', '--help']:
             cmd = commands.canonical_cmd(sys.argv[2])
             if not cmd in commands:
-                print >> sys.stderr, '%s help: "%s" command unknown' \
-                      % (prog, cmd)
+                out.error('%s help: "%s" command unknown' % (prog, cmd))
                 sys.exit(1)
 
             sys.argv[0] += ' %s' % cmd
@@ -256,6 +258,15 @@ def main():
     from stgit.git import GitException
     from stgit.commands.common import CmdException
     from stgit.gitmergeonefile import GitMergeException
+    from stgit.utils import EditorException
+
+    try:
+        debug_level = int(os.environ['STGIT_DEBUG_LEVEL'])
+    except KeyError:
+        debug_level = 0
+    except ValueError:
+        out.error('Invalid STGIT_DEBUG_LEVEL environment variable')
+        sys.exit(1)
 
     try:
         config_setup()
@@ -271,9 +282,13 @@ def main():
 
         command.func(parser, options, args)
     except (IOError, ParsingError, NoSectionError, CmdException,
-            StackException, GitException, GitMergeException), err:
+            StackException, GitException, GitMergeException,
+            EditorException), err:
         print >> sys.stderr, '%s %s: %s' % (prog, cmd, err)
-        sys.exit(2)
+        if debug_level:
+            raise
+        else:
+            sys.exit(2)
     except KeyboardInterrupt:
         sys.exit(1)