Skip to content

Commit e288950

Browse files
author
PoTe
committed
CLI simplification
1 parent 06f6a15 commit e288950

File tree

3 files changed

+18
-61
lines changed

3 files changed

+18
-61
lines changed

README.md

+4-8
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,15 @@ $ make install
3131
Since `gvp` is a script and runs in a child environment of your shell, the latter will not take the env changes unless you `source` them.
3232

3333
```shell
34-
$ gvp init
35-
$ source gvp in
36-
$ source gvp out
34+
$ source gvp
3735
```
3836

3937
### Commands
4038

4139
```shell
42-
init Creates the .godeps directory
43-
in Modifies GOPATH, GOBIN and PATH to use the .godeps
44-
out Restores the previous GOPATH, GOBIN and PATH.
45-
version outputs version information.
46-
help prints this message.
40+
source gvp Modifies GOPATH, GOBIN and PATH to use the .godeps directory.
41+
gvp version Outputs version information.
42+
gvp help Prints this message.
4743
```
4844

4945
### PLugins

bin/gvp

+9-45
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
23
usage() {
34
cat << EOF
45
usage: gvp [COMMAND]
@@ -16,70 +17,33 @@ SYNOPSIS
1617
USAGE
1718
Since gvp is a script, env changes will not happen unless you source them.
1819
19-
$ gvp init
20-
$ source gvp in
21-
$ source gvp out
20+
$ source gvp
2221
2322
COMMANDS
24-
init Creates the .godeps directory.
25-
in Modifies GOPATH and GOBIN to use the .godeps directory and sets the GVP_NAME variable.
26-
This can also be used to execute a comand in the environment without sourcing it.
27-
For example: "gvp in go build"
28-
out Restores the previous GOPATH and GOBIN and unsets GVP_NAME.
29-
version outputs version information.
30-
help prints this message.
23+
source gvp Modifies GOPATH and GOBIN to use the .godeps directory.
24+
gvp version Outputs version information.
25+
gvp help Prints this message.
3126
EOF
3227
}
3328

34-
if [[ "$1" != "in" && "$#" -ne 1 ]]; then
35-
usage
36-
exit 1
37-
fi
38-
39-
case "$1" in
29+
case "${1:-"in"}" in
4030
"init")
31+
echo ">> This command is deprecated, just run 'source gvp'."
4132
mkdir -p .godeps/{src,pkg,bin}
4233
;;
4334
"version")
4435
echo ">> gvp v0.1.0"
4536
;;
4637
"in")
47-
if [[ -n $GVP_NAME ]]; then kill -INT $$; fi
38+
mkdir -p .godeps/{src,pkg,bin}
4839

4940
GVP_DIR="$(pwd)/.godeps"
50-
51-
if [[ ! -d $GVP_DIR ]]; then
52-
echo '>> Directory .godeps not found. Run `gvp init` first.'
53-
kill -INT $$
54-
fi
55-
56-
GVP_OLD_GOPATH=$GOPATH
57-
GVP_OLD_GOBIN=$GOBIN
58-
GVP_OLD_PATH=$PATH
59-
export GVP_OLD_GOPATH GVP_OLD_GOBIN PATH
60-
61-
GVP_NAME=$(basename $(pwd))
6241
GOBIN="$GVP_DIR/bin"
6342
GOPATH="$GVP_DIR:$PWD"
6443
PATH="$GOBIN:$PATH"
6544

6645
export GOBIN GOPATH GVP_NAME PATH
6746
echo ">> Local GOPATH set."
68-
69-
if [[ -n $2 ]]; then
70-
eval ${@:2}
71-
fi
72-
;;
73-
"out")
74-
if [[ -z $GVP_NAME ]]; then kill -INT $$; fi
75-
76-
GOBIN=$GVP_OLD_GOBIN
77-
GOPATH=$GVP_OLD_GOPATH
78-
PATH=$GVP_OLD_PATH
79-
80-
export PATH GOPATH GOBIN
81-
unset GVP_OLD_GOPATH GVP_OLD_GOBIN GVP_OLD_PATH GVP_NAME
82-
echo ">> Reverted to system GOPATH."
8347
;;
8448
"help")
8549
usage
@@ -93,8 +57,8 @@ case "$1" in
9357
gvp-$plugin $@ &&
9458
exit
9559
else
60+
echo ">> Unknown command."
9661
usage && exit 1
9762
fi
9863
;;
99-
10064
esac

test/init_in_and_out_test.sh

+5-8
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,23 @@ GVP=../bin/gvp
55
## gvp init should create a .godeps/ directory.
66
assert_raises "$GVP init"
77
assert_raises "[ -d .godeps ]"
8+
## Cleanup
9+
rm -rf .godeps
810

9-
## source gvp in should change the original GOPATH and associated Env variables.
11+
## source gvp in should change the original GOPATH and associated Env variables
12+
## as well as creating a .godeps directory
1013
ORIGINAL_GOPATH=$GOPATH
1114
ORIGINAL_GOBIN=$GOBIN
1215
ORIGINAL_PATH=$PATH
1316

1417
source $GVP in
1518

19+
assert_raises "[ -d .godeps ]"
1620
assert "echo $GOPATH" "$PWD/.godeps:$PWD"
1721
assert "echo $GOBIN" "$PWD/.godeps/bin"
1822
assert "echo $PATH" "$PWD/.godeps/bin:$ORIGINAL_PATH"
1923

2024

21-
### source gvp out should return env variables back to original values.
22-
source $GVP out
23-
24-
assert "echo $GOPATH" "$ORIGINAL_GOPATH"
25-
assert "echo $GOBIN" "$ORIGINAL_GOBIN"
26-
assert "echo $PATH" "$ORIGINAL_PATH"
27-
2825
## Cleanup
2926
rm -rf .godeps
3027

0 commit comments

Comments
 (0)