Skip to content

Commit f12c93f

Browse files
author
Alade Yessoufou
committed
Add config UX improvements with --config, --profile, and --print flags (Task #4)
1 parent 7ca1464 commit f12c93f

5 files changed

Lines changed: 1101 additions & 192 deletions

File tree

lib/commands/config.sh

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,48 @@
1+
# Default config file path
2+
SHIPNODE_CONFIG_FILE="${SHIPNODE_CONFIG_FILE:-shipnode.conf}"
3+
4+
# Set config file based on --config or --profile flags
5+
# Usage: set_config_file "$@"
6+
# Returns: remaining arguments (with flags removed)
7+
set_config_file() {
8+
local args=()
9+
local i=1
10+
local total=$#
11+
12+
while [ $i -le $total ]; do
13+
local arg="${!i}"
14+
case "$arg" in
15+
--config)
16+
i=$((i + 1))
17+
if [ $i -le $total ]; then
18+
SHIPNODE_CONFIG_FILE="${!i}"
19+
else
20+
error "--config requires a path argument"
21+
fi
22+
;;
23+
--profile)
24+
i=$((i + 1))
25+
if [ $i -le $total ]; then
26+
SHIPNODE_CONFIG_FILE="shipnode.${!i}.conf"
27+
else
28+
error "--profile requires an environment name (e.g., staging, prod)"
29+
fi
30+
;;
31+
*)
32+
args+=("$arg")
33+
;;
34+
esac
35+
i=$((i + 1))
36+
done
37+
38+
# Return remaining args as a string
39+
printf '%s\n' "${args[*]}"
40+
}
41+
142
# Load configuration
243
load_config() {
3-
if [ ! -f "shipnode.conf" ]; then
4-
error "shipnode.conf not found. Run 'shipnode init' first."
44+
if [ ! -f "$SHIPNODE_CONFIG_FILE" ]; then
45+
error "$SHIPNODE_CONFIG_FILE not found. Run 'shipnode init' first."
546
fi
647

748
info "Loading configuration..."
@@ -16,23 +57,23 @@ load_config() {
1657

1758
# Source the config file with error handling
1859
set -a
19-
if ! source shipnode.conf 2>&1; then
20-
error "Failed to parse shipnode.conf"
60+
if ! source "$SHIPNODE_CONFIG_FILE" 2>&1; then
61+
error "Failed to parse $SHIPNODE_CONFIG_FILE"
2162
fi
2263
set +a
2364

2465
# Validate required variables
2566
if [ -z "$APP_TYPE" ]; then
26-
error "APP_TYPE not set in shipnode.conf"
67+
error "APP_TYPE not set in $SHIPNODE_CONFIG_FILE"
2768
fi
2869
if [ -z "$SSH_USER" ]; then
29-
error "SSH_USER not set in shipnode.conf"
70+
error "SSH_USER not set in $SHIPNODE_CONFIG_FILE"
3071
fi
3172
if [ -z "$SSH_HOST" ]; then
32-
error "SSH_HOST not set in shipnode.conf"
73+
error "SSH_HOST not set in $SHIPNODE_CONFIG_FILE"
3374
fi
3475
if [ -z "$REMOTE_PATH" ]; then
35-
error "REMOTE_PATH not set in shipnode.conf"
76+
error "REMOTE_PATH not set in $SHIPNODE_CONFIG_FILE"
3677
fi
3778

3879
# Set defaults

lib/commands/doctor.sh

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ cmd_doctor() {
2929
echo ""
3030

3131
# Config validation (if config exists)
32-
if [ -f "shipnode.conf" ]; then
32+
if [ -f "$SHIPNODE_CONFIG_FILE" ]; then
3333
info "Configuration validation:"
3434
check_health_check_path || has_warnings=true
3535
echo ""
@@ -106,21 +106,21 @@ cmd_doctor_security() {
106106
fi
107107
}
108108

109-
# Check if shipnode.conf exists and required vars are set
109+
# Check if config file exists and required vars are set
110110
check_local_config() {
111-
if [ ! -f "shipnode.conf" ]; then
112-
echo "shipnode.conf not found"
111+
if [ ! -f "$SHIPNODE_CONFIG_FILE" ]; then
112+
echo "$SHIPNODE_CONFIG_FILE not found"
113113
return 1
114114
fi
115115

116116
# Try to load config
117117
set +e
118-
source shipnode.conf 2>/dev/null
118+
source "$SHIPNODE_CONFIG_FILE" 2>/dev/null
119119
local source_result=$?
120120
set -e
121121

122122
if [ $source_result -ne 0 ]; then
123-
echo "shipnode.conf has syntax errors"
123+
echo "$SHIPNODE_CONFIG_FILE has syntax errors"
124124
return 1
125125
fi
126126

@@ -132,11 +132,11 @@ check_local_config() {
132132
[ -z "$REMOTE_PATH" ] && missing_vars+=("REMOTE_PATH")
133133

134134
if [ ${#missing_vars[@]} -gt 0 ]; then
135-
echo "shipnode.conf missing required variables: ${missing_vars[*]}"
135+
echo "$SHIPNODE_CONFIG_FILE missing required variables: ${missing_vars[*]}"
136136
return 1
137137
fi
138138

139-
echo "shipnode.conf exists and is valid"
139+
echo "$SHIPNODE_CONFIG_FILE exists and is valid"
140140
return 0
141141
}
142142

@@ -176,12 +176,12 @@ check_local_package_json() {
176176

177177
# Check if HEALTH_CHECK_PATH starts with / (if set)
178178
check_health_check_path() {
179-
if [ ! -f "shipnode.conf" ]; then
179+
if [ ! -f "$SHIPNODE_CONFIG_FILE" ]; then
180180
return 0
181181
fi
182182

183183
set +e
184-
source shipnode.conf 2>/dev/null
184+
source "$SHIPNODE_CONFIG_FILE" 2>/dev/null
185185
set -e
186186

187187
if [ -n "$HEALTH_CHECK_PATH" ] && [[ ! "$HEALTH_CHECK_PATH" =~ ^/ ]]; then
@@ -195,13 +195,13 @@ check_health_check_path() {
195195

196196
# Test SSH connection
197197
check_ssh_connection() {
198-
if [ ! -f "shipnode.conf" ]; then
199-
echo " ✗ Cannot test SSH - shipnode.conf not found"
198+
if [ ! -f "$SHIPNODE_CONFIG_FILE" ]; then
199+
echo " ✗ Cannot test SSH - $SHIPNODE_CONFIG_FILE not found"
200200
return 1
201201
fi
202202

203203
set +e
204-
source shipnode.conf 2>/dev/null
204+
source "$SHIPNODE_CONFIG_FILE" 2>/dev/null
205205
set -e
206206

207207
if [ -z "$SSH_USER" ] || [ -z "$SSH_HOST" ]; then
@@ -223,12 +223,12 @@ check_ssh_connection() {
223223

224224
# Check remote environment (batched checks)
225225
check_remote_environment() {
226-
if [ ! -f "shipnode.conf" ]; then
226+
if [ ! -f "$SHIPNODE_CONFIG_FILE" ]; then
227227
return 1
228228
fi
229229

230230
set +e
231-
source shipnode.conf 2>/dev/null
231+
source "$SHIPNODE_CONFIG_FILE" 2>/dev/null
232232
set -e
233233

234234
local ssh_port="${SSH_PORT:-22}"
@@ -352,12 +352,12 @@ REMOTE_CHECKS
352352

353353
# Quiet SSH connection check (no output)
354354
check_ssh_connection_quiet() {
355-
if [ ! -f "shipnode.conf" ]; then
355+
if [ ! -f "$SHIPNODE_CONFIG_FILE" ]; then
356356
return 1
357357
fi
358358

359359
set +e
360-
source shipnode.conf 2>/dev/null
360+
source "$SHIPNODE_CONFIG_FILE" 2>/dev/null
361361
set -e
362362

363363
if [ -z "$SSH_USER" ] || [ -z "$SSH_HOST" ]; then
@@ -371,21 +371,21 @@ check_ssh_connection_quiet() {
371371
check_local_file_permissions() {
372372
local has_issues=false
373373

374-
# Check shipnode.conf permissions
375-
if [ -f "shipnode.conf" ]; then
374+
# Check config file permissions
375+
if [ -f "$SHIPNODE_CONFIG_FILE" ]; then
376376
local conf_perms
377-
conf_perms=$(stat -c "%a" shipnode.conf 2>/dev/null || stat -f "%Lp" shipnode.conf 2>/dev/null)
377+
conf_perms=$(stat -c "%a" "$SHIPNODE_CONFIG_FILE" 2>/dev/null || stat -f "%Lp" "$SHIPNODE_CONFIG_FILE" 2>/dev/null)
378378
if [ -n "$conf_perms" ]; then
379379
# Check if permissions are too permissive (readable by group/others)
380380
local other_read=$((conf_perms % 10 / 1))
381381
local group_read=$(((conf_perms / 10) % 10 / 1))
382382

383383
if [ "$other_read" -ge 4 ] || [ "$group_read" -ge 4 ]; then
384-
echo "shipnode.conf has overly permissive permissions ($conf_perms)"
385-
echo " Recommendation: Run 'chmod 600 shipnode.conf'"
384+
echo "$SHIPNODE_CONFIG_FILE has overly permissive permissions ($conf_perms)"
385+
echo " Recommendation: Run 'chmod 600 $SHIPNODE_CONFIG_FILE'"
386386
has_issues=true
387387
else
388-
echo "shipnode.conf permissions are secure ($conf_perms)"
388+
echo "$SHIPNODE_CONFIG_FILE permissions are secure ($conf_perms)"
389389
fi
390390
fi
391391
fi

lib/commands/help.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ Commands:
99
init --template <name> Create config from framework template
1010
init --list-templates List available framework templates
1111
init --non-interactive Create basic shipnode.conf without prompts
12+
init --print Print config to stdout (no file created)
1213
setup First-time server setup (Node, PM2, Caddy, jq)
1314
deploy Deploy the application
1415
deploy --skip-build Deploy without running build step
16+
17+
Global Options:
18+
--config <path> Use custom config file (default: shipnode.conf)
19+
--profile <env> Use profile config: shipnode.<env>.conf
1520
doctor Run pre-flight diagnostic checks
1621
doctor --security Run non-destructive security audit
1722
harden Interactive server security hardening wizard
@@ -65,11 +70,16 @@ Examples:
6570
shipnode init --template nextjs # Use Next.js template
6671
shipnode init --template react # Use React template
6772
shipnode init --list-templates # List all available templates
73+
shipnode init --print # Print config to stdout
74+
shipnode init --print --template express # Print Express template config
6875
shipnode setup # Setup server (first time)
6976
shipnode doctor # Run diagnostics
7077
shipnode doctor --security # Run security audit
7178
shipnode harden # Interactive security hardening
7279
shipnode deploy # Deploy your app
80+
shipnode deploy --profile staging # Deploy using shipnode.staging.conf
81+
shipnode deploy --config custom.conf # Deploy using custom config file
82+
shipnode --profile prod deploy # Alternative flag position
7383
shipnode env # Upload .env file to server
7484
shipnode unlock # Clear stuck deployment lock
7585
shipnode rollback # Rollback to previous release

0 commit comments

Comments
 (0)