Skip to content

Commit 3250275

Browse files
feat: improve CLI error handling and docker-compose execution
1 parent 398f7b6 commit 3250275

File tree

3 files changed

+36
-26
lines changed

3 files changed

+36
-26
lines changed

bin/cli

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,19 @@
33
# CLI script is a inferface to executes commands on the CLI service.
44
# The CLI service contains a set of commands to manage users, namesapces and members.
55

6+
exit_with_error() {
7+
echo "ERROR: ShellHub is not running. Exiting."
8+
exit 1
9+
}
10+
611
. "$(dirname "$0")/utils"
712

13+
cd $(dirname $(readlink_f $0))/../
14+
815
DOCKER_COMPOSE=$(evaluate_docker_compose)
16+
SERVICES=$($DOCKER_COMPOSE ps --format '{{.Service}}' | tr '\n' ' ')
17+
18+
[ -z "$SERVICES" ] && exit_with_error
19+
echo -n "$SERVICES" | awk '!(/mongo/ && /redis/ && /api/) { exit 1; }' || exit_with_error
920

10-
exec $DOCKER_COMPOSE run cli ./cli $@
21+
exec $DOCKER_COMPOSE exec cli ./cli $@

bin/docker-compose

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,7 @@
22

33
. "$(dirname "$0")/utils"
44

5-
readlink_f() {
6-
(if uname | grep -q 'Darwin'; then
7-
# Use greadlink if available, otherwise it behaves like "readlink -f" option
8-
if command -v greadlink >/dev/null 2>&1; then
9-
greadlink -f "$1"
10-
else
11-
target_file="$1"
12-
cd "$(dirname "$target_file")"
13-
target_file=$(basename "$target_file")
14-
15-
while [ -L "$target_file" ]
16-
do
17-
target_file=$(readlink "$target_file")
18-
cd "$(dirname "$target_file")"
19-
target_file=$(basename "$target_file")
20-
done
21-
22-
echo "$(pwd -P)/$target_file"
23-
fi
24-
else
25-
readlink -f "$1"
26-
fi)
27-
}
28-
295
DOCKER_COMPOSE=$(evaluate_docker_compose)
30-
316
WORKDIR=$(dirname $(readlink_f $0))/../
327

338
cd $WORKDIR

bin/utils

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,30 @@ evaluate_docker_compose() {
2323
echo "$COMPOSE_COMMAND"
2424
}
2525

26+
readlink_f() {
27+
(if uname | grep -q 'Darwin'; then
28+
# Use greadlink if available, otherwise it behaves like "readlink -f" option
29+
if command -v greadlink >/dev/null 2>&1; then
30+
greadlink -f "$1"
31+
else
32+
target_file="$1"
33+
cd "$(dirname "$target_file")"
34+
target_file=$(basename "$target_file")
35+
36+
while [ -L "$target_file" ]
37+
do
38+
target_file=$(readlink "$target_file")
39+
cd "$(dirname "$target_file")"
40+
target_file=$(basename "$target_file")
41+
done
42+
43+
echo "$(pwd -P)/$target_file"
44+
fi
45+
else
46+
readlink -f "$1"
47+
fi)
48+
}
49+
2650
set -o allexport
2751

2852
env_override=${ENV_OVERRIDE:-./.env.override}

0 commit comments

Comments
 (0)