]> thyrsus.com Git - src.git/commitdiff
src init.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 6 Nov 2014 16:39:39 +0000 (11:39 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 6 Nov 2014 16:39:39 +0000 (11:39 -0500)
src

diff --git a/src b/src
index 6ac8ca32542785e75a79846a9b37fec1e2edd01f..cb270be2602de75267a4978330134a70057bdb55 100755 (executable)
--- a/src
+++ b/src
@@ -2,11 +2,15 @@
 #
 # src - simple revision control.
 #
-import sys
+import sys, os
 
 version = 0.1
 
+def complain(msg):
+    sys.stderr.write("src: " + msg + "\n")
+
 def help(*args):
+    "Summarize src commands, or (with argument) show help for a single command."
     print"""
 src help [command]
    Displays help for commands.
@@ -36,9 +40,25 @@ src fast-export ['file'...]
    Export one or more projects as a git fast-import stream.
 """
 
+def init(*args):
+    "Create a .src directory if none already exists."
+    if not os.path.exists(".src"):
+        try:
+            os.mkdir(".src")
+        except OSError:
+            complain(".src/ creation failed, check directory permissions.")
+    elif os.path.isdir(".src"):
+        complain(".src/ already exists.")
+    else:
+        complain(".src/ exists but is not a directory.")
+
 if __name__ == "__main__":
     command = sys.argv[1:]
     if not command:
         help()
     else:
-        eval(command[0])(*command[1:])
+        try:
+            eval(command[0])(*command[1:])
+        except NameError:
+            sys.stderr.write("src: no such command as '%s'.  Try 'src help'\n" \
+                           % command[0])