Skip to content
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

Print resource yaml #20

Merged
merged 8 commits into from
Nov 14, 2024
Merged

Print resource yaml #20

merged 8 commits into from
Nov 14, 2024

Conversation

jpeimer
Copy link
Collaborator

@jpeimer jpeimer commented Oct 6, 2024

  • Print resource yaml
  • If several resources are matching the get pattern, print yamls for all of them
  • Update readme
  • Continue user prompt loop if the prompt was empty

Summary by CodeRabbit

  • New Features
    • Enhanced documentation in the README.md for clearer usage instructions of the get command.
    • Added functionality to print resource YAML by introducing a new -oyaml flag in the command-line interface.
  • Bug Fixes
    • Corrected phrasing in example commands from "name starts form" to "name starts from."
  • Documentation
    • Introduced new examples in the README.md to illustrate printing resource YAML.

Copy link

coderabbitai bot commented Oct 6, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request includes updates to the README.md file to improve documentation for the must-gather-explorer tool, specifically enhancing usage instructions for the get command and adding new examples. Additionally, modifications to app/main.py introduce a new action for printing resource YAML, including a new function, print_resource_yaml, which processes user commands to output YAML content for specified resources.

Changes

File Change Summary
README.md Enhanced documentation for must-gather-explorer, clarified usage instructions, corrected phrasing, and added new examples for YAML output.
app/main.py Modified main function to recognize -oyaml flag, added print_resource_yaml function, and updated get_resources to accept a new parameter for YAML output. Method signatures for several functions were also updated.

Possibly related PRs

  • Print resource yaml #20: The changes in this PR directly relate to the main PR as both involve updates to the README.md file to clarify usage instructions for the get command and include examples for printing resource YAML. Additionally, both PRs modify the app/main.py file to enhance the functionality of the get_resources function and introduce the print_resource_yaml function.

Suggested reviewers

  • myakove

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

@redhat-qe-bot1
Copy link

Report bugs in Issues

The following are automatically added:

  • Add reviewers from OWNER file (in the root of the repository) under reviewers section.
  • Set PR size label.
  • New issue is created for the PR. (Closed when PR is merged/closed)
  • Run pre-commit if .pre-commit-config.yaml exists in the repo.

Available user actions:

  • To mark PR as WIP comment /wip to the PR, To remove it from the PR comment /wip cancel to the PR.
  • To block merging of PR comment /hold, To un-block merging of PR comment /hold cancel.
  • To mark PR as verified comment /verified to the PR, to un-verify comment /verified cancel to the PR.
    verified label removed on each new commit push.
  • To cherry pick a merged PR comment /cherry-pick <target branch to cherry-pick to> in the PR.
    • Multiple target branches can be cherry-picked, separated by spaces. (/cherry-pick branch1 branch2)
    • Cherry-pick will be started when PR is merged
  • To build and push container image command /build-and-push-container in the PR (tag will be the PR number).
    • You can add extra args to the Podman build command
      • Example: /build-and-push-container --build-arg OPENSHIFT_PYTHON_WRAPPER_COMMIT=<commit_hash>
  • To add a label by comment use /<label name>, to remove, use /<label name> cancel
  • To assign reviewers based on OWNERS file use /assign-reviewers
  • To check if PR can be merged use /check-can-merge
Supported /retest check runs
  • /retest tox: Retest tox
  • /retest python-module-install: Retest python-module-install
Supported labels
  • hold
  • verified
  • wip
  • lgtm

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

🧹 Outside diff range and nitpick comments (2)
README.md (2)

31-32: Excellent addition of YAML printing instructions!

The new section clearly explains how to use the YAML printing feature, which is a key objective of this PR. This addition significantly enhances the utility of the tool for users.

Consider adding a brief explanation of why a user might want to print the resource YAML. For example:

- To print the resource YAML (useful for viewing detailed configuration or troubleshooting), add `yaml` to the `get` command, for example:

This additional context could help users understand when and why they might use this feature.


33-34: Well-structured examples for YAML printing!

These examples effectively demonstrate how to use the new YAML printing feature, both with and without specifying a namespace. They are clear, concise, and consistent with the format of previous examples in the document.

For consistency with the previous examples, consider adding a comment after each command explaining what it does. For example:

get pvc hpp yaml # To print YAMLs of all PVCs when name starts from 'hpp'
get pvc -n openshift-storage hpp yaml # To print YAMLs of all PVCs in 'openshift-storage' namespace when name starts from 'hpp'

This would maintain the style established in the earlier examples and further clarify the purpose of each command.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f16502d and edd5a28.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • app/main.py (4 hunks)
🧰 Additional context used
🔇 Additional comments (3)
README.md (2)

28-29: Great improvements to the documentation!

The changes in these lines enhance the clarity and completeness of the usage instructions:

  1. The grammatical correction from "name starts form" to "name starts from" improves readability.
  2. The new example demonstrating the use of the 'get' command with a specified namespace is a valuable addition, providing users with a clear understanding of how to query resources in specific namespaces.

These updates contribute to a more user-friendly and comprehensive README.


28-34: Overall excellent improvements to the README!

The changes to this file successfully document the new YAML printing feature, aligning perfectly with the PR objectives. The updated examples and new instructions are clear, concise, and will greatly assist users in understanding and utilizing the new functionality.

The minor suggestions provided in the previous comments (adding context to the YAML printing explanation and maintaining consistency in example comments) would further enhance the already improved documentation. Great work on making the Must Gather Explorer tool more user-friendly and powerful!

app/main.py (1)

90-91: Good addition to handle empty user commands

The check for an empty user_command ensures the prompt continues if the user presses 'Enter' without typing a command, improving the user experience.

app/main.py Outdated Show resolved Hide resolved
app/main.py Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
app/main.py Outdated Show resolved Hide resolved
app/main.py Outdated Show resolved Hide resolved
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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between edd5a28 and 529e94c.

📒 Files selected for processing (1)
  • README.md (1 hunks)
🧰 Additional context used
🪛 Markdownlint
README.md

42-42: null
Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)


44-44: null
Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)


43-43: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)


43-43: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)

🔇 Additional comments (2)
README.md (2)

40-41: LGTM: Clear and helpful examples added

The new examples for using the get command with PersistentVolumeClaims are clear and provide good coverage of different use cases. They demonstrate filtering by name and namespace, which will be helpful for users.


42-42: No changes required

This line is part of the existing content and hasn't been modified. It fits well within the context of the examples provided.

🧰 Tools
🪛 Markdownlint

42-42: null
Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)

README.md Outdated Show resolved Hide resolved
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: 3

🧹 Outside diff range and nitpick comments (3)
README.md (1)

40-46: Summary: Documentation improvements with suggestions for further enhancements

The additions to the README.md file effectively document the new YAML printing feature of the Must-gather explorer tool. The examples provided are clear and helpful for users. To further improve the documentation:

  1. Consider adopting the Kubernetes-style -o yaml format for consistency with widely-used conventions.
  2. Improve markdown formatting by adding blank lines around list items and code blocks.
  3. Ensure consistency in the YAML output format across all examples.

These changes will enhance readability and align the tool's usage with familiar patterns, improving the overall user experience.

Would you like assistance in implementing these suggested changes throughout the README.md file?

🧰 Tools
🪛 Markdownlint

42-42: null
Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)


44-44: null
Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)


43-43: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)


43-43: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)

app/main.py (2)

135-142: Consider supporting the standard '-o yaml' option format

To align with common CLI conventions (e.g., kubectl), consider parsing the output format flag as -o yaml instead of -oyaml. This would improve user experience by matching expected command formats.

Apply this diff to adjust the parsing:

 print_yaml = False
-yaml_flag = "-oyaml"
+output_flag = "-o"
+output_format = ""
-if yaml_flag in commands_list:
+if output_flag in commands_list:
+    idx = commands_list.index(output_flag)
+    if idx + 1 < len(commands_list):
+        output_format = commands_list[idx + 1]
+        if output_format == 'yaml':
+            print_yaml = True
+            commands_list.pop(idx)  # Remove '-o'
+            commands_list.pop(idx)  # Remove 'yaml'
+        else:
+            CONSOLE.print(f"[red]Unsupported output format '{output_format}'[/red]")
+            continue
+    else:
+        CONSOLE.print("[red]Output format not specified after '-o' flag[/red]")
+        continue
+if print_yaml and action_name != GET_ACTION:
     if action_name != GET_ACTION:
-        CONSOLE.print(f"'{yaml_flag}' is only supported with '{GET_ACTION}' action")
+        CONSOLE.print(f"'--output yaml' is only supported with '{GET_ACTION}' action")
         continue
-    print_yaml = True
-    commands_list.remove(yaml_flag)

183-191: Note: Empty action functions

The get_logs, get_describe, and print_help functions are currently empty. If they are placeholders for future implementation, consider adding a TODO comment to indicate that they need to be completed.

Would you like assistance in implementing these functions or creating a GitHub issue to track their completion?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 529e94c and f5e4d24.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • app/main.py (3 hunks)
🧰 Additional context used
🪛 Markdownlint
README.md

42-42: null
Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)


44-44: null
Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)


43-43: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)


43-43: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)

🔇 Additional comments (5)
README.md (1)

40-41: LGTM: Clear and helpful examples added

The new examples for using the get command with PersistentVolumeClaims are clear and provide valuable information for users. They demonstrate how to filter resources by name prefix and how to specify a namespace, which enhances the usability of the tool.

app/main.py (4)

81-82: [Duplicate Comment] 'yaml' should not be in actions_dict

This issue was previously raised and is still applicable. Please refer to the prior feedback regarding not including 'yaml' as an action since it's an option for the 'get' action, not a separate action.


92-93: LGTM: Added check for empty user input

The addition of this check improves the user experience by preventing unexpected termination when the prompt is left empty.


157-167: LGTM: Updated 'get_resources' to handle YAML output

The modifications allow the get_resources function to print resource YAML when print_yaml is True, enhancing functionality.


170-180: LGTM: Added exception handling and dynamic separator

The function now handles exceptions when opening files and uses a dynamic separator based on terminal width, improving robustness and readability.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
app/main.py Show resolved Hide resolved
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

🧹 Outside diff range and nitpick comments (4)
app/main.py (4)

91-92: LGTM: Improved user experience for empty input

The addition of the condition to continue the loop on empty user input enhances the user experience by preventing unexpected termination. This aligns well with the PR objective.

Consider adding a user-friendly message when empty input is received:

 if not user_command:
+    CONSOLE.print("Empty input received. Please enter a command or type 'exit' to quit.")
     continue

132-143: LGTM: Added YAML output functionality

The implementation of the "-oyaml" flag successfully adds the ability to print YAML representations of resources, aligning with the PR objectives. The code correctly checks for the appropriate action and sets a boolean flag to control the output format.

For consistency with other constants in the file, consider defining the YAML flag as a constant:

+YAML_FLAG = "-oyaml"
 # ... (earlier in the file)
-yaml_flag = "-oyaml"
+if YAML_FLAG in commands_list:
     if action_name != GET_ACTION:
-        CONSOLE.print(f"'{yaml_flag}' is only supported with '{GET_ACTION}' action")
+        CONSOLE.print(f"'{YAML_FLAG}' is only supported with '{GET_ACTION}' action")
         continue
     print_yaml = True
-    commands_list.remove(yaml_flag)
+    commands_list.remove(YAML_FLAG)

162-173: LGTM: Updated get_resources function to handle YAML output

The get_resources function has been successfully updated to handle both YAML and table output formats based on the print_yaml flag. This change aligns with the PR objectives and maintains existing functionality.

Consider extracting the table printing logic into a separate function for better code organization:

 def get_resources(resources_raw_data: List[Dict[str, Any]], print_yaml: bool = False, **kwargs: Dict[Any, Any]) -> None:
     if print_yaml:
         print_resource_yaml(resources_raw_data=resources_raw_data)
     else:
-        # Print table of Namespace, Name
-        table = Table()
-        table.add_column("NAMESPACE")
-        table.add_column("NAME")
-        for raw_data in resources_raw_data:
-            table.add_row(raw_data["namespace"], raw_data["name"])
-        CONSOLE.print(table)
+        print_resource_table(resources_raw_data)
+
+def print_resource_table(resources_raw_data: List[Dict[str, Any]]) -> None:
+    table = Table()
+    table.add_column("NAMESPACE")
+    table.add_column("NAME")
+    for raw_data in resources_raw_data:
+        table.add_row(raw_data["namespace"], raw_data["name"])
+    CONSOLE.print(table)

175-185: LGTM: New print_resource_yaml function added

The print_resource_yaml function successfully implements the YAML output functionality, including proper error handling for file operations. The use of a terminal-width separator between resources improves readability.

Consider the following minor improvements:

  1. Use a context manager for file operations to ensure proper resource cleanup:
-        try:
-            with open(raw_data["yaml_file"]) as fd:
-                resource_yaml_content = fd.read()
-        except (FileNotFoundError, IOError) as e:
+        try:
+            with open(raw_data["yaml_file"], "r") as fd:
+                resource_yaml_content = fd.read()
+        except OSError as e:
  1. Consider using yaml.safe_dump() to ensure consistent YAML formatting:
 import yaml
 # ...
-        CONSOLE.print(resource_yaml_content)
+        yaml_dict = yaml.safe_load(resource_yaml_content)
+        CONSOLE.print(yaml.safe_dump(yaml_dict, default_flow_style=False))
  1. Extract the separator line to a constant for consistency:
+SEPARATOR = "-" * os.get_terminal_size().columns
 # ...
-        CONSOLE.print("-" * os.get_terminal_size().columns)
+        CONSOLE.print(SEPARATOR)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f5e4d24 and 2f9a3e2.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • app/main.py (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • README.md
🧰 Additional context used
🔇 Additional comments (4)
app/main.py (4)

78-81: LGTM: Improved code maintainability

The introduction of the GET_ACTION constant and its usage in actions_dict enhances code readability and maintainability. This change aligns with the DRY principle and reduces the risk of typos when referring to the "get" action.


106-108: LGTM: Improved error message formatting

The reformatted error message for unsupported actions enhances readability and follows Python best practices for string formatting. The use of f-strings and multi-line formatting improves code clarity.


Line range hint 1-265: Overall assessment: Approved with minor suggestions

The changes in this PR successfully implement the ability to print YAML representations of resources and improve the user experience of the Must Gather Explorer tool. The code is well-structured and aligns with the PR objectives.

Key improvements:

  1. Added YAML output functionality
  2. Enhanced error handling and user input processing
  3. Improved code readability and maintainability

Minor suggestions have been made throughout the review to further enhance code quality and consistency. These include:

  • Extracting constants for better maintainability
  • Improving error handling in file operations
  • Refactoring for better code organization

Overall, this PR represents a significant improvement to the tool's functionality and user experience.


159-159: ⚠️ Potential issue

Potential issue with function argument mismatch

The current implementation passes the print_yaml parameter to all action functions, which may cause errors for functions that don't expect this argument.

Consider modifying the code to handle different function signatures:

-actions_dict[action_name](resources_raw_data, print_yaml)
+if action_name == GET_ACTION:
+    actions_dict[action_name](resources_raw_data, print_yaml)
+else:
+    actions_dict[action_name](resources_raw_data)

Alternatively, you could update all action functions to accept **kwargs to handle additional parameters gracefully.

Likely invalid or redundant comment.

Copy link
Collaborator

@myakove myakove left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests

app/main.py Show resolved Hide resolved
@myakove
Copy link
Collaborator

myakove commented Nov 14, 2024

/lgtm

@jpeimer
Copy link
Collaborator Author

jpeimer commented Nov 14, 2024

/verified

@jpeimer jpeimer merged commit ec8715c into main Nov 14, 2024
5 of 6 checks passed
@jpeimer jpeimer deleted the print_yaml branch November 14, 2024 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants