Skip to content

Add new sub-command "run"#41

Merged
Jooho merged 2 commits intomainfrom
loopy_run_list
May 27, 2025
Merged

Add new sub-command "run"#41
Jooho merged 2 commits intomainfrom
loopy_run_list

Conversation

@Jooho
Copy link
Owner

@Jooho Jooho commented May 27, 2025

Summary by CodeRabbit

  • New Features

    • Added options to the CLI to list all available commands and display detailed information about specific commands, including descriptions and parameters.
    • Enhanced script headers with detailed descriptions and parameter listings for easier inspection.
  • Improvements

    • CLI error messages are now more informative when commands are not found.
    • Logging functions now support custom color output for improved readability.
    • Download scripts now skip installation steps for tools that are already present, preventing redundant downloads.
  • Bug Fixes

    • Adjusted cleanup and test scripts to improve error handling and output clarity.
  • Tests

    • Reduced test timeout duration for faster feedback.

Signed-off-by: Jooho Lee <jlee@redhat.com>
@coderabbitai
Copy link

coderabbitai bot commented May 27, 2025

Walkthrough

The changes introduce helper functions and conditional logic to avoid redundant CLI tool downloads in shell scripts, enhance the CLI run command with options to list and inspect available scripts, and improve logging with customizable colors. Script headers and error handling were refined, and test timeouts and command flags were updated.

Changes

File(s) Change Summary
hacks/download-cli-for-ci.sh, hacks/download-cli.sh Added check_binary_exists function; tool installations now skip if binary exists, ensuring idempotency.
src/cli/cli.py Changed import and registration from run_command to run for the CLI group.
src/cli/commands/run.py Added list_scripts, show_script_info, _print_script_info methods; refactored CLI to support --list and --info flags; improved error messaging.
src/commons/python/py_utils.py Added custom_log function; updated info to support optional color parameter for colored log output.
src/dev/scripts/debug-pod.sh Enhanced script header with description and parameters; changed pod deletion to redirect errors to /dev/null.
tests/conftest.py Reduced timeout from 120s to 60s.
tests/e2e/roles/cluster-tests/operator_install_delete/test_e2e_operator.py Removed --ignore-not-found from oc get pod command in operator deletion test.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant RunCommand

    User->>CLI: run --list
    CLI->>RunCommand: list_scripts()
    RunCommand-->>CLI: Print available scripts

    User->>CLI: run --info <command>
    CLI->>RunCommand: show_script_info(command)
    RunCommand-->>CLI: Print script info

    User->>CLI: run <command> [params]
    CLI->>RunCommand: run(command, params)
    RunCommand-->>CLI: Execute script or print error
Loading

Poem

In the warren of code, a rabbit hops,
Skipping downloads where the binary stops.
Scripts now list and show their lore,
With colored logs and info galore.
Tests run faster, errors less found,
A happier hop with each command sound!
🐇✨

✨ 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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: 2

🧹 Nitpick comments (2)
hacks/download-cli-for-ci.sh (1)

95-103: Consider improving the condition logic for OC & KUBECTL.

The current condition requires BOTH binaries to be missing before downloading. This could lead to unnecessary downloads if only one binary is missing.

Consider this improvement:

-if ! check_binary_exists "${root_directory}/bin/oc" || ! check_binary_exists "${root_directory}/bin/kubectl"; then
+oc_missing=false
+kubectl_missing=false
+if ! check_binary_exists "${root_directory}/bin/oc"; then
+    oc_missing=true
+fi
+if ! check_binary_exists "${root_directory}/bin/kubectl"; then
+    kubectl_missing=true
+fi
+if [[ "$oc_missing" == true ]] || [[ "$kubectl_missing" == true ]]; then

This would provide more granular control and only download when actually needed.

src/cli/commands/run.py (1)

7-7: Remove unused import identified by static analysis.

The info function is imported but never used in the code.

-from commons.python.py_utils import error, die, info, custom_log
+from commons.python.py_utils import error, die, custom_log
🧰 Tools
🪛 Ruff (0.11.9)

7-7: commons.python.py_utils.info imported but unused

Remove unused import: commons.python.py_utils.info

(F401)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc7d99c and 019d748.

📒 Files selected for processing (8)
  • hacks/download-cli-for-ci.sh (1 hunks)
  • hacks/download-cli.sh (1 hunks)
  • src/cli/cli.py (2 hunks)
  • src/cli/commands/run.py (4 hunks)
  • src/commons/python/py_utils.py (2 hunks)
  • src/dev/scripts/debug-pod.sh (2 hunks)
  • tests/conftest.py (1 hunks)
  • tests/e2e/roles/cluster-tests/operator_install_delete/test_e2e_operator.py (0 hunks)
💤 Files with no reviewable changes (1)
  • tests/e2e/roles/cluster-tests/operator_install_delete/test_e2e_operator.py
🧰 Additional context used
🧬 Code Graph Analysis (4)
src/cli/cli.py (1)
src/cli/commands/run.py (2)
  • run (119-148)
  • run (192-220)
hacks/download-cli.sh (1)
hacks/download-cli-for-ci.sh (3)
  • get_latest_release (36-39)
  • check_binary_exists (49-56)
  • delete_if_exists (41-47)
hacks/download-cli-for-ci.sh (1)
hacks/download-cli.sh (3)
  • get_latest_release (36-39)
  • check_binary_exists (49-56)
  • delete_if_exists (41-47)
src/cli/commands/run.py (1)
src/commons/python/py_utils.py (4)
  • error (76-77)
  • die (55-57)
  • info (65-69)
  • custom_log (48-52)
🪛 Ruff (0.11.9)
src/cli/commands/run.py

7-7: commons.python.py_utils.info imported but unused

Remove unused import: commons.python.py_utils.info

(F401)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: cluster-test (3.12)
  • GitHub Check: non-cluster-test (3.12)
🔇 Additional comments (13)
tests/conftest.py (1)

17-17: LGTM! Reasonable timeout reduction for improved test efficiency.

The timeout reduction from 120 to 60 seconds aligns with the PR's efficiency improvements and should help speed up test execution.

src/dev/scripts/debug-pod.sh (2)

3-10: Excellent documentation enhancement!

The detailed script header with description and parameter documentation significantly improves maintainability and usability. This makes it much easier for developers to understand the script's purpose and available options.


32-32: Good error handling refinement.

Replacing --ignore-not-found=true with 2>/dev/null is a good approach. This change ensures that actual errors aren't silently ignored while still suppressing expected "not found" error messages during cleanup.

src/commons/python/py_utils.py (2)

48-53: Well-implemented logging enhancement!

The new custom_log function provides flexible color customization while maintaining backward compatibility. The implementation correctly handles the optional color parameter and properly resets colors after printing.


65-69: Good backward-compatible enhancement to info function.

The updated info function maintains full backward compatibility while adding color customization support. The logic correctly prioritizes the custom color when provided and falls back to the default info color.

src/cli/cli.py (2)

6-6: Consistent import update for refactored run command.

The import change from run_command to run aligns with the enhanced CLI functionality that now supports --list and --info options for script management.


54-54: Proper CLI command registration update.

The command registration correctly uses the renamed run function, maintaining consistency with the refactored import and enhanced command functionality.

hacks/download-cli-for-ci.sh (2)

49-56: LGTM! Well-implemented binary existence check.

The function correctly checks for binary existence and provides clear feedback. The return values (0 for exists, 1 for not exists) follow shell convention.


62-69: Excellent idempotency improvement for YQ installation.

The conditional check prevents unnecessary downloads when the binary already exists, improving script efficiency and reliability.

hacks/download-cli.sh (1)

49-56: LGTM! Consistent binary existence check implementation.

The function is identical to the CI version, ensuring consistent behavior across scripts.

src/cli/commands/run.py (3)

18-41: Well-implemented script listing functionality.

The method correctly handles file discovery, deduplication, and error handling. Using a set to avoid duplicates when both .sh and .py versions exist is a good approach.


76-118: Robust script information extraction with good error handling.

The regex patterns for extracting description and parameters from script comments are well-designed. The formatting with colored output enhances user experience.


185-220: Well-structured CLI option handling with clear logic flow.

The branching logic correctly handles the different command modes (list, info, direct execution) and provides appropriate error messages when no command is specified.

@Jooho Jooho changed the title fix minor issues Add new sub-command "run" May 27, 2025
Signed-off-by: Jooho Lee <jlee@redhat.com>
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

♻️ Duplicate comments (1)
src/cli/commands/run.py (1)

66-69: ⚠️ Potential issue

Fix unreachable code after die() call.

This is identical to a previous review comment. The die() function calls sys.exit(1), making the subsequent code unreachable. The past review suggestion should be applied.

-                die(user_msg)
+                die(user_msg)

Note: The return statement and exception handling after die() are unreachable and should be removed.

🧹 Nitpick comments (2)
src/cli/commands/run.py (2)

7-7: Remove unused import.

The info function is imported but never used in this file.

-from commons.python.py_utils import error, die, info, custom_log
+from commons.python.py_utils import error, die, custom_log
🧰 Tools
🪛 Ruff (0.11.9)

7-7: commons.python.py_utils.info imported but unused

Remove unused import: commons.python.py_utils.info

(F401)


82-99: Consider improving regex patterns for better robustness.

The regex patterns for extracting description and parameters could be more robust. The current patterns may not handle edge cases well, such as descriptions spanning multiple comment blocks or nested parameter structures.

Consider these improvements:

            # Extract description
-            description_match = re.search(
-                r"#\s*Description:\s*(.*?)(?:\n#|\n\n|\n$)", content, re.DOTALL
-            )
+            description_match = re.search(
+                r"#\s*Description:\s*((?:#.*\n?)*)", content, re.MULTILINE
+            )
            
            # Extract parameters  
-            params_match = re.search(
-                r"#\s*Available Parameters:(.*?)(?:\n\n|\n$)", content, re.DOTALL
-            )
+            params_match = re.search(
+                r"#\s*Available Parameters:\s*((?:#.*\n?)*)", content, re.MULTILINE
+            )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 019d748 and 564bf43.

📒 Files selected for processing (2)
  • hacks/download-cli.sh (1 hunks)
  • src/cli/commands/run.py (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • hacks/download-cli.sh
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/cli/commands/run.py (1)
src/commons/python/py_utils.py (4)
  • error (76-77)
  • die (55-57)
  • info (65-69)
  • custom_log (48-52)
🪛 Ruff (0.11.9)
src/cli/commands/run.py

7-7: commons.python.py_utils.info imported but unused

Remove unused import: commons.python.py_utils.info

(F401)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: non-cluster-test (3.12)
  • GitHub Check: cluster-test (3.12)
🔇 Additional comments (4)
src/cli/commands/run.py (4)

18-41: Well-implemented script listing functionality.

The list_scripts method correctly handles script discovery and deduplication. The use of a set to avoid duplicate command names when both .sh and .py versions exist is a good approach.


105-113: Good parameter formatting logic.

The parameter formatting correctly handles the extraction and cleaning of comment-based documentation, providing user-friendly bullet-point output.


144-146: Excellent improvement to user feedback.

Adding the user-facing error message via error() provides better user experience by showing errors directly to the user in addition to logging.


184-219: Well-structured CLI option implementation.

The CLI function properly handles the new --list and --info options with appropriate validation and error messages. The logic flow is clear and the optional command_name argument works well with the new flags.

@Jooho
Copy link
Owner Author

Jooho commented May 27, 2025

/lgtm
/approve

@github-actions github-actions bot added the lgtm label May 27, 2025
@Jooho Jooho merged commit f2c37e6 into main May 27, 2025
6 checks passed
@Jooho Jooho deleted the loopy_run_list branch May 27, 2025 01:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant