Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

NirZabari
Copy link

@NirZabari NirZabari commented Jun 1, 2025

Great project!

I've added a small script which will setup all katas.

Summary by CodeRabbit

  • New Features
    • Introduced an automated setup and cleaning script with support for both Bash and PowerShell environments.
    • Added command-line options for silent mode and cleaning operations.
    • Provides color-coded output for better readability of messages and errors.

Copy link

coderabbitai bot commented Jun 1, 2025

Walkthrough

A new Bash script, dojo_setup.sh, has been added to automate setup and cleaning tasks for multiple project directories. It supports "setup" and "clean" modes, selectable via command-line arguments, and includes a --silent flag to suppress output. The script executes setup scripts or removes exercise directories as appropriate.

Changes

File(s) Change Summary
dojo_setup.sh Added a Bash script for automated setup and cleaning of project directories with CLI options.

Poem

A script now hops from dir to dir,
Setting up with bashy whir,
Or cleaning up the exercise mess,
With silent paws (or noisy, yes!).
Green and red, its colors show—
The dojo’s ready, off we go!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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 portability

To catch errors and undefined variables early and increase portability, consider replacing the shebang with /usr/bin/env bash and enabling set -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 option

Currently unknown options print an error and exit, and there's no support for --help or explicit setup 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 restricting find 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 policy

Directly 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 status

In --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 explicitly exit 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7d2c18f and 443486f.

📒 Files selected for processing (1)
  • dojo_setup.sh (1 hunks)
🔇 Additional comments (1)
dojo_setup.sh (1)

57-71: Clean mode logic is sound

The branch correctly identifies and removes exercise directories at both depth levels, with informative output when not silenced. The implementation matches the intended behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant