Skip to content

Commit 90a6ce0

Browse files
committed
fix shellcheck lint errors
FIX: - declare and assign separately to avoid masking return values - combine multiple echo redirects into single block
1 parent 6d04227 commit 90a6ce0

4 files changed

Lines changed: 259 additions & 237 deletions

File tree

cli.sh

Lines changed: 96 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2,91 +2,108 @@
22
# Licensed under the MIT License. See LICENSE file in the project root.
33

44
function cli {
5-
local cmd="$1"
6-
7-
# Collect scripts, Deno tasks, NPM tasks and Makefile tasks
8-
local scripts=()
9-
if [ -d "scripts" ]; then
10-
setopt local_options nullglob 2>/dev/null || shopt -s nullglob 2>/dev/null
11-
for f in scripts/*.ts scripts/*.sh; do
12-
[ -e "$f" ] && scripts+=("$(basename "$f")")
13-
done
14-
fi
5+
local cmd="$1"
156

16-
local deno_tasks=()
17-
if [ -f "deno.json" ]; then
18-
while IFS= read -r task; do
19-
[ -n "$task" ] && deno_tasks+=("$task")
20-
done < <(jq -r '.tasks // {} | keys | .[]' deno.json 2>/dev/null)
21-
fi
7+
# Collect scripts, Deno tasks, NPM tasks and Makefile tasks
8+
local scripts=()
9+
if [ -d "scripts" ]; then
10+
setopt local_options nullglob 2>/dev/null || shopt -s nullglob 2>/dev/null
11+
for f in scripts/*.ts scripts/*.sh; do
12+
[ -e "$f" ] && scripts+=("$(basename "$f")")
13+
done
14+
fi
2215

23-
local node_tasks=()
24-
if [ -f "package.json" ]; then
25-
while IFS= read -r task; do
26-
[ -n "$task" ] && node_tasks+=("$task")
27-
done < <(jq -r '.scripts // {} | keys | .[]' package.json 2>/dev/null)
28-
fi
29-
30-
local makefile_tasks=()
31-
if command -v make &>/dev/null && make -q 2>/dev/null; [ $? -ne 2 ]; then
32-
while IFS= read -r task; do
33-
[ -n "$task" ] && makefile_tasks+=("$task")
34-
done < <(make -p 2>/dev/null | grep -E '^[a-zA-Z0-9_-]+:' | sed 's/://')
35-
fi
16+
local deno_tasks=()
17+
if [ -f "deno.json" ]; then
18+
while IFS= read -r task; do
19+
[ -n "$task" ] && deno_tasks+=("$task")
20+
done < <(jq -r '.tasks // {} | keys | .[]' deno.json 2>/dev/null)
21+
fi
3622

37-
# Check if anything is available
38-
if [ ${#scripts[@]} -eq 0 ] && [ ${#deno_tasks[@]} -eq 0 ] && [ ${#node_tasks[@]} -eq 0 ] && [ ${#makefile_tasks[@]} -eq 0 ]; then
39-
echo "No deno.json, package.json, ./scripts/ folder or makefile found" >&2
40-
return 1
41-
fi
23+
local node_tasks=()
24+
if [ -f "package.json" ]; then
25+
while IFS= read -r task; do
26+
[ -n "$task" ] && node_tasks+=("$task")
27+
done < <(jq -r '.scripts // {} | keys | .[]' package.json 2>/dev/null)
28+
fi
4229

43-
# Show help
44-
if [ -z "$cmd" ] || [[ "$cmd" =~ ^(help|--help|-h)$ ]]; then
45-
echo "Available Commands:"
46-
for name in "${scripts[@]}"; do
47-
local base="${name%.*}"
48-
printf " cli %-12s (scripts/%s)\n" "$base" "$name"
49-
done
50-
for t in "${deno_tasks[@]}"; do
51-
printf " cli %-12s (deno.json)\n" "$t"
52-
done
53-
for t in "${node_tasks[@]}"; do
54-
printf " cli %-12s (package.json)\n" "$t"
55-
done
56-
for t in "${makefile_tasks[@]}"; do
57-
printf " cli %-12s (make)\n" "$t"
58-
done
59-
return 0
60-
fi
30+
local makefile_tasks=()
31+
if
32+
command -v make &>/dev/null && make -q 2>/dev/null
33+
[ $? -ne 2 ]
34+
then
35+
while IFS= read -r task; do
36+
[ -n "$task" ] && makefile_tasks+=("$task")
37+
done < <(make -p 2>/dev/null | grep -E '^[a-zA-Z0-9_-]+:' | sed 's/://')
38+
fi
6139

62-
# Try scripts first
63-
for ext in ts sh; do
64-
local script="scripts/${cmd}.${ext}"
65-
[ -f "$script" ] || continue
66-
shift
67-
if [ "$ext" = "sh" ]; then
68-
bash "$script" "$@"
69-
else
70-
local shebang=$(sed -n '1s/^#![[:space:]]*//p' "$script")
71-
shebang="${shebang#/usr/bin/env }"; shebang="${shebang#-S }"
72-
${shebang:-deno run -A} "$script" "$@"
73-
fi
74-
return $?
75-
done
40+
# Check if anything is available
41+
if [ ${#scripts[@]} -eq 0 ] && [ ${#deno_tasks[@]} -eq 0 ] && [ ${#node_tasks[@]} -eq 0 ] && [ ${#makefile_tasks[@]} -eq 0 ]; then
42+
echo "No deno.json, package.json, ./scripts/ folder or makefile found" >&2
43+
return 1
44+
fi
7645

77-
# Try Makefile tasks next
78-
for t in "${makefile_tasks[@]}"; do
79-
if [ "$cmd" = "$t" ]; then shift; make "$cmd" "$@"; return $?; fi
80-
done
46+
# Show help
47+
if [ -z "$cmd" ] || [[ "$cmd" =~ ^(help|--help|-h)$ ]]; then
48+
echo "Available Commands:"
49+
for name in "${scripts[@]}"; do
50+
local base="${name%.*}"
51+
printf " cli %-12s (scripts/%s)\n" "$base" "$name"
52+
done
53+
for t in "${deno_tasks[@]}"; do
54+
printf " cli %-12s (deno.json)\n" "$t"
55+
done
56+
for t in "${node_tasks[@]}"; do
57+
printf " cli %-12s (package.json)\n" "$t"
58+
done
59+
for t in "${makefile_tasks[@]}"; do
60+
printf " cli %-12s (make)\n" "$t"
61+
done
62+
return 0
63+
fi
8164

82-
# Try Deno/NPM tasks last
83-
for t in "${deno_tasks[@]}"; do
84-
if [ "$cmd" = "$t" ]; then shift; deno task "$cmd" "$@"; return $?; fi
85-
done
86-
for t in "${node_tasks[@]}"; do
87-
if [ "$cmd" = "$t" ]; then shift; npm run "$cmd" -- "$@"; return $?; fi
88-
done
65+
# Try scripts first
66+
for ext in ts sh; do
67+
local script="scripts/${cmd}.${ext}"
68+
[ -f "$script" ] || continue
69+
shift
70+
if [ "$ext" = "sh" ]; then
71+
bash "$script" "$@"
72+
else
73+
local shebang
74+
shebang=$(sed -n '1s/^#![[:space:]]*//p' "$script")
75+
shebang="${shebang#/usr/bin/env }"
76+
shebang="${shebang#-S }"
77+
${shebang:-deno run -A} "$script" "$@"
78+
fi
79+
return $?
80+
done
8981

90-
echo "Unknown command: $cmd (run 'cli' for help)" >&2
91-
return 1
82+
# Try Makefile tasks next
83+
for t in "${makefile_tasks[@]}"; do
84+
if [ "$cmd" = "$t" ]; then
85+
shift
86+
make "$cmd" "$@"
87+
return $?
88+
fi
89+
done
90+
91+
# Try Deno/NPM tasks last
92+
for t in "${deno_tasks[@]}"; do
93+
if [ "$cmd" = "$t" ]; then
94+
shift
95+
deno task "$cmd" "$@"
96+
return $?
97+
fi
98+
done
99+
for t in "${node_tasks[@]}"; do
100+
if [ "$cmd" = "$t" ]; then
101+
shift
102+
npm run "$cmd" -- "$@"
103+
return $?
104+
fi
105+
done
106+
107+
echo "Unknown command: $cmd (run 'cli' for help)" >&2
108+
return 1
92109
}

install.sh

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ NC='\033[0m' # No Color
1212

1313
info() { echo -e "${GREEN}[smplcli]${NC} $1"; }
1414
warn() { echo -e "${YELLOW}[smplcli]${NC} $1"; }
15-
error() { echo -e "${RED}[smplcli]${NC} $1" >&2; exit 1; }
15+
error() {
16+
echo -e "${RED}[smplcli]${NC} $1" >&2
17+
exit 1
18+
}
1619

1720
# Check for jq dependency
1821
if ! command -v jq &>/dev/null; then
19-
error "jq is required but not installed.
22+
error "jq is required but not installed.
2023
Install it with:
2124
macOS: brew install jq
2225
Ubuntu: sudo apt install jq
@@ -25,19 +28,19 @@ fi
2528

2629
# Check for curl
2730
if ! command -v curl &>/dev/null; then
28-
error "curl is required but not installed."
31+
error "curl is required but not installed."
2932
fi
3033

3134
# Get latest release tag from GitHub API
3235
info "Fetching latest release..."
3336
LATEST_TAG=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" 2>/dev/null | jq -r '.tag_name // empty')
3437

3538
if [ -z "$LATEST_TAG" ]; then
36-
warn "No releases found. Installing from main branch..."
37-
DOWNLOAD_URL="https://raw.githubusercontent.com/$REPO/main/cli.sh"
39+
warn "No releases found. Installing from main branch..."
40+
DOWNLOAD_URL="https://raw.githubusercontent.com/$REPO/main/cli.sh"
3841
else
39-
info "Found release: $LATEST_TAG"
40-
DOWNLOAD_URL="https://raw.githubusercontent.com/$REPO/$LATEST_TAG/cli.sh"
42+
info "Found release: $LATEST_TAG"
43+
DOWNLOAD_URL="https://raw.githubusercontent.com/$REPO/$LATEST_TAG/cli.sh"
4144
fi
4245

4346
# Create install directory
@@ -46,41 +49,43 @@ mkdir -p "$INSTALL_DIR"
4649
# Download cli.sh
4750
info "Downloading cli.sh..."
4851
if ! curl -fsSL "$DOWNLOAD_URL" -o "$INSTALL_DIR/cli.sh"; then
49-
error "Failed to download cli.sh"
52+
error "Failed to download cli.sh"
5053
fi
5154

5255
chmod +x "$INSTALL_DIR/cli.sh"
5356

5457
# Determine shell rc file
5558
detect_shell_rc() {
56-
local shell_name
57-
shell_name=$(basename "$SHELL")
59+
local shell_name
60+
shell_name=$(basename "$SHELL")
5861

59-
case "$shell_name" in
60-
zsh) echo "$HOME/.zshrc" ;;
61-
bash)
62-
# Prefer .bashrc, fall back to .bash_profile on macOS
63-
if [ -f "$HOME/.bashrc" ]; then
64-
echo "$HOME/.bashrc"
65-
else
66-
echo "$HOME/.bash_profile"
67-
fi
68-
;;
69-
*) echo "$HOME/.profile" ;;
70-
esac
62+
case "$shell_name" in
63+
zsh) echo "$HOME/.zshrc" ;;
64+
bash)
65+
# Prefer .bashrc, fall back to .bash_profile on macOS
66+
if [ -f "$HOME/.bashrc" ]; then
67+
echo "$HOME/.bashrc"
68+
else
69+
echo "$HOME/.bash_profile"
70+
fi
71+
;;
72+
*) echo "$HOME/.profile" ;;
73+
esac
7174
}
7275

7376
RC_FILE=$(detect_shell_rc)
7477
SOURCE_LINE="source \"\$HOME/.smplcli/cli.sh\""
7578

7679
# Add source line if not already present
7780
if ! grep -qF ".smplcli/cli.sh" "$RC_FILE" 2>/dev/null; then
78-
info "Adding source line to $RC_FILE..."
79-
echo "" >> "$RC_FILE"
80-
echo "# smplcli - unified task runner" >> "$RC_FILE"
81-
echo "$SOURCE_LINE" >> "$RC_FILE"
81+
info "Adding source line to $RC_FILE..."
82+
{
83+
echo ""
84+
echo "# smplcli - unified task runner"
85+
echo "$SOURCE_LINE"
86+
} >>"$RC_FILE"
8287
else
83-
info "Source line already exists in $RC_FILE"
88+
info "Source line already exists in $RC_FILE"
8489
fi
8590

8691
info "Installation complete!"

0 commit comments

Comments
 (0)