mirror of
https://github.com/dwinkler1/np.git
synced 2026-02-19 14:30:59 -05:00
Add robust command availability checks to all shell scripts
- Add check for @defaultPackageName@-devenv in activateDevenv.sh - Add check for uv command in initPython.sh - Add check for git command in initProject.sh (with graceful degradation) - Add checks for wget, sed, nix in updateDeps.sh - Provide clear error messages when commands are not available - Prevent scripts from failing with cryptic errors when tools are missing Co-authored-by: dwinkler1 <22460147+dwinkler1@users.noreply.github.com>
This commit is contained in:
parent
8fc712be60
commit
0273515951
4 changed files with 56 additions and 16 deletions
|
|
@ -2,6 +2,11 @@
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
if [[ -f "devenv.nix" ]]; then
|
if [[ -f "devenv.nix" ]]; then
|
||||||
echo "🚀 Activating devenv environment..."
|
echo "🚀 Activating devenv environment..."
|
||||||
|
if ! command -v @defaultPackageName@-devenv &> /dev/null; then
|
||||||
|
echo "❌ Command '@defaultPackageName@-devenv' not found."
|
||||||
|
echo "Ensure devenv is properly configured in your environment."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
exec @defaultPackageName@-devenv shell
|
exec @defaultPackageName@-devenv shell
|
||||||
else
|
else
|
||||||
echo "❌ No devenv.nix file found in the current directory."
|
echo "❌ No devenv.nix file found in the current directory."
|
||||||
|
|
|
||||||
|
|
@ -43,25 +43,32 @@ fi
|
||||||
|
|
||||||
# Initialize git
|
# Initialize git
|
||||||
if [[ ! -d ".git" ]]; then
|
if [[ ! -d ".git" ]]; then
|
||||||
git init
|
if ! command -v git &> /dev/null; then
|
||||||
echo "✓ Initialized Git repository"
|
echo "⚠️ Warning: 'git' command not found. Skipping git initialization."
|
||||||
|
echo "Install git to enable version control."
|
||||||
|
else
|
||||||
|
git init
|
||||||
|
echo "✓ Initialized Git repository"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if files exist and are not already staged/tracked before adding
|
# Check if files exist and are not already staged/tracked before adding
|
||||||
if [[ -f "flake.nix" ]] && ! git diff --cached --name-only 2>/dev/null | grep -q "flake.nix" &&
|
if command -v git &> /dev/null && [[ -d ".git" ]]; then
|
||||||
! git ls-files --error-unmatch flake.nix >/dev/null 2>&1; then
|
if [[ -f "flake.nix" ]] && ! git diff --cached --name-only 2>/dev/null | grep -q "flake.nix" &&
|
||||||
echo "✓ Adding flake.nix to Git repository"
|
! git ls-files --error-unmatch flake.nix >/dev/null 2>&1; then
|
||||||
git add flake.nix
|
echo "✓ Adding flake.nix to Git repository"
|
||||||
elif [[ -f "flake.nix" ]]; then
|
git add flake.nix
|
||||||
echo "✓ flake.nix already tracked/staged in Git"
|
elif [[ -f "flake.nix" ]]; then
|
||||||
fi
|
echo "✓ flake.nix already tracked/staged in Git"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -f "flake.lock" ]] && ! git diff --cached --name-only 2>/dev/null | grep -q "flake.lock" &&
|
if [[ -f "flake.lock" ]] && ! git diff --cached --name-only 2>/dev/null | grep -q "flake.lock" &&
|
||||||
! git ls-files --error-unmatch flake.lock >/dev/null 2>&1; then
|
! git ls-files --error-unmatch flake.lock >/dev/null 2>&1; then
|
||||||
echo "✓ Adding flake.lock to Git repository"
|
echo "✓ Adding flake.lock to Git repository"
|
||||||
git add flake.lock
|
git add flake.lock
|
||||||
elif [[ -f "flake.lock" ]]; then
|
elif [[ -f "flake.lock" ]]; then
|
||||||
echo "✓ flake.lock already tracked/staged in Git"
|
echo "✓ flake.lock already tracked/staged in Git"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
# Create .gitignore
|
# Create .gitignore
|
||||||
if [[ ! -f ".gitignore" ]]; then
|
if [[ ! -f ".gitignore" ]]; then
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,14 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Check if uv command is available
|
||||||
|
if ! command -v uv &> /dev/null; then
|
||||||
|
echo "❌ Command 'uv' not found."
|
||||||
|
echo "UV is required for Python project management."
|
||||||
|
echo "Ensure UV is properly installed in your environment."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ ! -f "pyproject.toml" ]]; then
|
if [[ ! -f "pyproject.toml" ]]; then
|
||||||
echo "🐍 Initializing UV project..."
|
echo "🐍 Initializing UV project..."
|
||||||
uv init
|
uv init
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,29 @@ set -euo pipefail
|
||||||
|
|
||||||
echo "🔄 Updating project dependencies..."
|
echo "🔄 Updating project dependencies..."
|
||||||
|
|
||||||
|
# Check for required commands
|
||||||
|
if ! command -v wget &> /dev/null; then
|
||||||
|
echo "❌ Error: 'wget' command not found."
|
||||||
|
echo "Please install wget to fetch R version information."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v sed &> /dev/null; then
|
||||||
|
echo "❌ Error: 'sed' command not found."
|
||||||
|
echo "Please install sed to update flake.nix."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v nix &> /dev/null; then
|
||||||
|
echo "❌ Error: 'nix' command not found."
|
||||||
|
echo "Please install Nix to update flake inputs."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Ensure we're in the repository root
|
# Ensure we're in the repository root
|
||||||
if [[ ! -f "flake.nix" ]]; then
|
if [[ ! -f "flake.nix" ]]; then
|
||||||
# Try to find git root
|
# Try to find git root
|
||||||
if git rev-parse --show-toplevel >/dev/null 2>&1; then
|
if command -v git &> /dev/null && git rev-parse --show-toplevel >/dev/null 2>&1; then
|
||||||
cd "$(git rev-parse --show-toplevel)"
|
cd "$(git rev-parse --show-toplevel)"
|
||||||
if [[ ! -f "flake.nix" ]]; then
|
if [[ ! -f "flake.nix" ]]; then
|
||||||
echo "❌ Error: flake.nix not found in repository root"
|
echo "❌ Error: flake.nix not found in repository root"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue