-
Notifications
You must be signed in to change notification settings - Fork 950
Utility: Add script to setup all katas #378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
WalkthroughA new Bash script, Changes
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (5)
dojo_setup.sh (5)
1-4
: Add strict mode and improve shebang portabilityTo catch errors and undefined variables early and increase portability, consider replacing the shebang with
/usr/bin/env bash
and enablingset -euo pipefail
at the top of the script.Diff:
-#!/bin/bash +#!/usr/bin/env bash +# Exit on error, undefined variable, and fail on pipe errors +set -euo pipefail SILENT=false MODE="setup" # Default mode
11-27
: Enhance argument parsing with help and explicit setup optionCurrently unknown options print an error and exit, and there's no support for
--help
or explicitsetup
subcommand. Adding a usage function improves UX:Example diff:
+usage() { + cat <<EOF +Usage: $0 [options] [clean] + +Options: + -s, --silent suppress output + -h, --help show this help message + +Commands: + clean remove exercise directories (default is setup) + setup explicitly run setup scripts (default) +EOF + exit 1 +} while [[ "$#" -gt 0 ]]; do case "$1" in + setup) + MODE="setup" + shift + ;; -s|--silent) SILENT=true shift # past argument ;; + -h|--help) + usage + ;; clean) MODE="clean" shift # past argument ;;
29-33
: Simplify directory traversal by using-mindepth
You manually skip
.
in the loop. You can eliminate that by restrictingfind
to start at depth 1:Suggested change:
-find . -maxdepth 2 -type d \( -name ".git" -o -name ".github" \) -prune -o -print0 | while ... +find . -mindepth 1 -maxdepth 2 -type d \( -name ".git" -o -name ".github" \) -prune -o -print0 | while ...Then you can remove the manual:
if [ "$dir_path" == "." ]; then continue fi
45-56
: Invoke PowerShell scripts with-File
and relaxed policyDirectly calling
pwsh "./setup.ps1"
may not respect execution policies. It’s more reliable to pass-File
and bypass policy:Example diff:
- if command -v pwsh &> /dev/null; then - (cd "$dir_path" && pwsh "./setup.ps1" >/dev/null 2>&1 || true) - elif command -v powershell &> /dev/null; then - (cd "$dir_path" && powershell "./setup.ps1" >/dev/null 2>&1 || true) + if command -v pwsh &> /dev/null; then + (cd "$dir_path" && pwsh -NoLogo -NonInteractive -ExecutionPolicy Bypass -File "setup.ps1" >/dev/null 2>&1 || true) + elif command -v powershell &> /dev/null; then + (cd "$dir_path" && powershell -NoLogo -NonInteractive -ExecutionPolicy Bypass -File "setup.ps1" >/dev/null 2>&1 || true) elif [ "$SILENT" == "false" ]; then echo -e "${RED}Skipping setup.ps1 for $project_dir: Neither pwsh nor powershell command found.${RC}" fi
74-80
: Ensure consistent exit statusIn
--silent
mode or if the loop executes without printing, the last command could be from the loop, affecting the script’s exit code. It’s safer to explicitlyexit 0
after printing the final message:Example:
if [ "$SILENT" == "false" ]; then if [ "$MODE" == "setup" ]; then echo -e "${GREEN}Finished setup${RC}" elif [ "$MODE" == "clean" ]; then echo -e "${GREEN}Finished clean${RC}" fi fi +exit 0
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
dojo_setup.sh
(1 hunks)
🔇 Additional comments (1)
dojo_setup.sh (1)
57-71
: Clean mode logic is soundThe branch correctly identifies and removes
exercise
directories at both depth levels, with informative output when not silenced. The implementation matches the intended behavior.
Great project!
I've added a small script which will setup all katas.
Summary by CodeRabbit