Commits

Doug Hellmann  committed 6456005

move mkproject argument processing into the shell function

  • Participants
  • Parent commits 84ec713

Comments (0)

Files changed (3)

File virtualenvwrapper/ChangeLog

+2011-09-04  Doug Hellmann  <dhellmann@racemi.com>
+
+	* project.sh (mkproject): Move argument parsing into the shell
+	function.
+
+	* project.py: Remove argument parsing functions.
+
 2010-04-23  Doug Hellmann  <dhellmann@racemi.com>
 
 	* project.sh (mkproject): Use our remembered version of python to

File virtualenvwrapper/project.py

 #
 [ -f "$VIRTUAL_ENV/.project" ] && cd "$(cat \"$VIRTUAL_ENV/.project\")"
 """
-
-def get_templates(args):
-    """Given a bunch of command line arguments, print the ones that
-    represent template names.
-    """
-    while args:
-        a = args.pop(0)
-        if a == '-t':
-            template = args.pop(0)
-            print template,
-    print
-    return
-
-def get_virtualenv_args(args):
-    """Given a bunch of command line arguments, print the ones that do
-    not represent template names.
-    """
-    while args:
-        a = args.pop(0)
-        if a == '-t':
-            template = args.pop(0)
-            continue
-        print a
-    

File virtualenvwrapper/project.sh

 }
 
 # Create a new project directory and its associated virtualenv.
-mkproject () {
-    for arg
+function mkproject {
+    typeset -a in_args
+    typeset -a out_args
+    typeset -i i
+    typeset tst
+    typeset a
+    typeset t
+    typeset templates
+
+    in_args=( "$@" )
+
+    if [ -n "$ZSH_VERSION" ]
+    then
+        i=1
+        tst="-le"
+    else
+        i=0
+        tst="-lt"
+    fi
+    while [ $i $tst $# ]
     do
-        if [ "$arg" = "-h" ]
-        then
-            echo 'mkproject help:'
-            echo
-            mkproject_help
-            echo
-            echo 'mkvirtualenv help:'
-            echo
-            mkvirtualenv -h
-            return
-        fi
+        a="${in_args[$i]}"
+        # echo "arg $i : $a"
+        case "$a" in
+            -h)
+                echo 'mkproject help:';
+                echo;
+                mkproject_help;
+                echo;
+                echo 'mkvirtualenv help:';
+                echo;
+                mkvirtualenv -h;
+                return;;
+            -t)
+                templates="$templates $a";
+                i=$(( $i + 1 ));;
+            *)
+                if [ ${#out_args} -gt 0 ]
+                then
+                    out_args=( "${out_args[@]-}" "$a" )
+                else
+                    out_args=( "$a" )
+                fi;;
+        esac
+        i=$(( $i + 1 ))
     done
-    templates=$("$VIRTUALENVWRAPPER_PYTHON" -m virtualenvwrapper.hook_loader \
-        -n get_templates project.parse_args $@)
-    RC=$?
-    if [ $RC -ne 0 ]
-    then
-        return $RC
-    fi
-    set -- $("$VIRTUALENVWRAPPER_PYTHON" -m virtualenvwrapper.hook_loader \
-        -n get_virtualenv_args project.parse_args $@)
-    RC=$?
-    if [ $RC -ne 0 ]
-    then
-        return $RC
-    fi
 
-#     echo "templates $templates"
-#     echo "remainder $@"
-#     return 0
+    set -- "${out_args[@]}"
 
-    eval "envname=\$$#"
+    # echo "templates $templates"
+    # echo "remainder $@"
+    # return 0
+
+    eval "typeset envname=\$$#"
     virtualenvwrapper_verify_project_home || return 1
 
     if [ -d "$PROJECT_HOME/$envname" ]