Skip to content

Commit 4c38bad

Browse files
committed
cli: use double brackets in conditions
1 parent ab922cb commit 4c38bad

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

codapi-cli

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ main() {
88
do_help
99
exit 0
1010
fi
11-
if [ "$#" -lt 2 ]; then
11+
if [[ "$#" -lt 2 ]]; then
1212
echo "Usage: $0 <resource> <command> [args...]"
1313
exit 1
1414
fi
@@ -53,7 +53,7 @@ do_sandbox_add() {
5353
# Command: codapi-cli sandbox add <path>
5454

5555
local path="$1"
56-
if [ -z "$path" ]; then
56+
if [[ -z "$path" ]]; then
5757
echo "Usage: $0 sandbox add <path>"
5858
exit 1
5959
fi
@@ -72,7 +72,7 @@ do_sandbox_add() {
7272

7373
# 2. Check if the sandbox already exists.
7474
local target_dir="$sandboxes_dir/$name"
75-
if [ -d "$target_dir" ]; then
75+
if [[ -d "$target_dir" ]]; then
7676
echo "ERROR: Sandbox '$name' already exists"
7777
echo "Remove it with 'codapi-cli sandbox rm $name' and try again"
7878
rm -f "$archive_path"
@@ -88,7 +88,7 @@ do_sandbox_add() {
8888
fi
8989
else
9090
echo "Copying local file $path..."
91-
if [ ! -f "$path" ]; then
91+
if [[ ! -f "$path" ]]; then
9292
echo "ERROR: File not found at $path"
9393
exit 1
9494
fi
@@ -111,31 +111,31 @@ do_sandbox_add() {
111111

112112
# 5. Run build.sh if it exists.
113113
local build_script="$target_dir/build.sh"
114-
if [ -f "$build_script" ]; then
114+
if [[ -f "$build_script" ]]; then
115115
echo "Running build script: $build_script"
116-
if [ ! -x "$build_script" ]; then
116+
if [[ ! -x "$build_script" ]]; then
117117
echo "Warning: $build_script is not executable, fixing..."
118118
chmod +x "$build_script"
119119
fi
120120
# Execute the script from within its directory
121121
(cd "$target_dir" && ./build.sh)
122-
if [ $? -ne 0 ]; then
122+
if [[ $? -ne 0 ]]; then
123123
echo "ERROR: build.sh failed for sandbox '$name'"
124124
exit 1
125125
fi
126126
fi
127127

128128
# 6. Run setup.sh if it exists.
129129
local setup_script="$target_dir/setup.sh"
130-
if [ -f "$setup_script" ]; then
130+
if [[ -f "$setup_script" ]]; then
131131
echo "Running setup script: $setup_script"
132-
if [ ! -x "$setup_script" ]; then
132+
if [[ ! -x "$setup_script" ]]; then
133133
echo "Warning: $setup_script is not executable, fixing..."
134134
chmod +x "$setup_script"
135135
fi
136136
# Execute the script from within its directory
137137
(cd "$target_dir" && ./setup.sh)
138-
if [ $? -ne 0 ]; then
138+
if [[ $? -ne 0 ]]; then
139139
echo "ERROR: setup.sh failed for sandbox '$name'"
140140
exit 1
141141
fi
@@ -149,13 +149,13 @@ do_sandbox_rm() {
149149
# Command: codapi-cli sandbox rm <name>
150150

151151
local name="$1"
152-
if [ -z "$name" ]; then
152+
if [[ -z "$name" ]]; then
153153
echo "Usage: $0 sandbox rm <name>"
154154
exit 1
155155
fi
156156

157157
local target_dir="$sandboxes_dir/$name"
158-
if [ ! -d "$target_dir" ]; then
158+
if [[ ! -d "$target_dir" ]]; then
159159
echo "ERROR: Sandbox '$name' does not exist"
160160
exit 1
161161
fi
@@ -178,13 +178,13 @@ do_sandbox_ls() {
178178
count=0
179179
echo "Available sandboxes:"
180180
for dir in "$sandboxes_dir"/*; do
181-
if [ -d "$dir" ]; then
181+
if [[ -d "$dir" ]]; then
182182
local name=$(basename "$dir")
183183
echo " - $name ($dir)"
184184
count=$((count + 1))
185185
fi
186186
done
187-
if [ $count -eq 0 ]; then
187+
if [[ $count -eq 0 ]]; then
188188
echo "(none)"
189189
else
190190
echo "($count total)"

0 commit comments

Comments
 (0)