Browse Source

Fix argument processing

Alois Mahdal 10 years ago
parent
commit
ec7f77c9cb
1 changed files with 30 additions and 22 deletions
  1. 30
    22
      dotfiles/gittum/bin/sibling

+ 30
- 22
dotfiles/gittum/bin/sibling View File

@@ -23,13 +23,6 @@
23 23
 #     $ git remote add origin ssh://our_server/projects/FAKE
24 24
 
25 25
 
26
-## cfgz
27
-#
28
-
29
-origin_name="origin"
30
-sibling_conf=".gittum-sibling"
31
-
32
-
33 26
 ## funz
34 27
 #
35 28
 
@@ -39,7 +32,7 @@ die() {
39 32
 }
40 33
 
41 34
 usage() {
42
-    echo "usage: git $(basename $0) NEWPROJ [TEMPLATE]"
35
+    echo "usage: git $(basename $0) [-v] [-s SIBLING] [-r REMOTE] PROJECT"
43 36
     exit 0
44 37
 }
45 38
 
@@ -57,21 +50,36 @@ rewrite_uri_to () {
57 50
 ## initz
58 51
 #
59 52
 
60
-project=$1
61
-test -n "$project" || usage
62
-
63
-if [ -f $sibling_conf ];
64
-then
65
-    sibling=$(cat $sibling_conf);
66
-else
67
-    sibling=$(find -maxdepth 1 -type d -name "[^.]*" | sort | head -1)
68
-fi
53
+origin_name="origin"
54
+sibling_conf=".gittum-sibling"
55
+verbose=false
56
+sibling=$(find -maxdepth 1 -type d -name "[^.]*" | sort | head -1)
57
+test -f $sibling_conf && sibling=$(cat $sibling_conf)
58
+remote_name="origin"
59
+
60
+while true;
61
+do
62
+    case $1 in
63
+        -r|--remote-name)
64
+            remote_name=$2
65
+            shift 2
66
+            ;;
67
+        -s|--sibling)
68
+            sibling=$2
69
+            shift 2
70
+            ;;
71
+        "")
72
+            break
73
+            ;;
74
+        *)
75
+            project=$1
76
+            shift
77
+            ;;
78
+    esac
79
+done
69 80
 
70
-if [ -z "$sibling" ];
71
-then
72
-    echo "could not find older sibling" 1>&2
73
-    exit 1
74
-fi
81
+test -n "$project" || usage
82
+test -n "$sibling" || die "could not find older sibling"
75 83
 
76 84
 
77 85
 ## body