mirror of
https://github.com/dwinkler1/np.git
synced 2026-02-19 22:40:57 -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
|
||||
if [[ -f "devenv.nix" ]]; then
|
||||
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
|
||||
else
|
||||
echo "❌ No devenv.nix file found in the current directory."
|
||||
|
|
|
|||
|
|
@ -43,25 +43,32 @@ fi
|
|||
|
||||
# Initialize git
|
||||
if [[ ! -d ".git" ]]; then
|
||||
git init
|
||||
echo "✓ Initialized Git repository"
|
||||
if ! command -v git &> /dev/null; then
|
||||
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
|
||||
|
||||
# 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" &&
|
||||
! git ls-files --error-unmatch flake.nix >/dev/null 2>&1; then
|
||||
echo "✓ Adding flake.nix to Git repository"
|
||||
git add flake.nix
|
||||
elif [[ -f "flake.nix" ]]; then
|
||||
echo "✓ flake.nix already tracked/staged in Git"
|
||||
fi
|
||||
if command -v git &> /dev/null && [[ -d ".git" ]]; then
|
||||
if [[ -f "flake.nix" ]] && ! git diff --cached --name-only 2>/dev/null | grep -q "flake.nix" &&
|
||||
! git ls-files --error-unmatch flake.nix >/dev/null 2>&1; then
|
||||
echo "✓ Adding flake.nix to Git repository"
|
||||
git add flake.nix
|
||||
elif [[ -f "flake.nix" ]]; then
|
||||
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" &&
|
||||
! git ls-files --error-unmatch flake.lock >/dev/null 2>&1; then
|
||||
echo "✓ Adding flake.lock to Git repository"
|
||||
git add flake.lock
|
||||
elif [[ -f "flake.lock" ]]; then
|
||||
echo "✓ flake.lock already tracked/staged in Git"
|
||||
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
|
||||
echo "✓ Adding flake.lock to Git repository"
|
||||
git add flake.lock
|
||||
elif [[ -f "flake.lock" ]]; then
|
||||
echo "✓ flake.lock already tracked/staged in Git"
|
||||
fi
|
||||
fi
|
||||
# Create .gitignore
|
||||
if [[ ! -f ".gitignore" ]]; then
|
||||
|
|
|
|||
|
|
@ -1,5 +1,14 @@
|
|||
#!/usr/bin/env bash
|
||||
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
|
||||
echo "🐍 Initializing UV project..."
|
||||
uv init
|
||||
|
|
|
|||
|
|
@ -3,10 +3,29 @@ set -euo pipefail
|
|||
|
||||
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
|
||||
if [[ ! -f "flake.nix" ]]; then
|
||||
# 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)"
|
||||
if [[ ! -f "flake.nix" ]]; then
|
||||
echo "❌ Error: flake.nix not found in repository root"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue