Skip to content

Commit 0a4fcd0

Browse files
committed
Add mkproject --force option
This allows `mkproject` to create a virtualenv for a project directory that already exists, which is something I frequently find the need to do.
1 parent 9555432 commit 0a4fcd0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

tests/test_project_mk.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ test_project_exists () {
6666
mkproject myproject4 >/dev/null 2>&1
6767
output=`mkproject myproject4 2>&1`
6868
assertTrue "Did not see expected message 'already exists' in: $output" "echo $output | grep 'already exists'"
69+
output=`mkproject -f myproject4 2>&1`
70+
assertFalse "Saw unexpected message 'already exists' in: $output" "echo $output | grep 'already exists'"
6971
}
7072

7173
test_same_workon_and_project_home () {

virtualenvwrapper.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,10 @@ function setvirtualenvproject {
974974

975975
# Show help for mkproject
976976
function virtualenvwrapper_mkproject_help {
977-
echo "Usage: mkproject [-t template] [virtualenv options] project_name"
977+
echo "Usage: mkproject [-f|--force] [-t template] [virtualenv options] project_name"
978+
echo
979+
echo "-f, --force Create the project even if the project directory"
980+
echo " already exists"
978981
echo
979982
echo "Multiple templates may be selected. They are applied in the order"
980983
echo "specified on the command line."
@@ -996,9 +999,11 @@ function mkproject {
996999
typeset tst
9971000
typeset a
9981001
typeset t
1002+
typeset force
9991003
typeset templates
10001004

10011005
in_args=( "$@" )
1006+
force=0
10021007

10031008
if [ -n "$ZSH_VERSION" ]
10041009
then
@@ -1015,6 +1020,8 @@ function mkproject {
10151020
-h|--help)
10161021
virtualenvwrapper_mkproject_help;
10171022
return;;
1023+
-f|--force)
1024+
force=1;;
10181025
-t)
10191026
i=$(( $i + 1 ));
10201027
templates="$templates ${in_args[$i]}";;
@@ -1038,7 +1045,7 @@ function mkproject {
10381045
eval "typeset envname=\$$#"
10391046
virtualenvwrapper_verify_project_home || return 1
10401047

1041-
if [ -d "$PROJECT_HOME/$envname" ]
1048+
if [ -d "$PROJECT_HOME/$envname" -a $force -eq 0 ]
10421049
then
10431050
echo "Project $envname already exists." >&2
10441051
return 1

0 commit comments

Comments
 (0)