Skip to content

Conversation

@almas-x
Copy link
Contributor

@almas-x almas-x commented Feb 12, 2025

📑 Description

Ensures that built-in CLI flags are separated from user-defined flags, grouping them distinctly for better organization and clarity in the output.

Before:

go run . new -h
Description:
   Create a new Goravel application

Usage:
   goravel [global options] new [options] [--] <name>

Options:
       --database The database driver your application will use
       --dev      Installs the latest "development" release
   -f, --force    Forces install even if the directory already exists
   -h, --help     Show help
       --http     The HTTP driver your application will use
       --storage  The filesystem module your application will use

After:

go run . new -h
Description:
   Create a new Goravel application

Usage:
   goravel [global options] new [options] [--] <name>

Options:
       --database The database driver your application will use
       --dev      Installs the latest "development" release
   -f, --force    Forces install even if the directory already exists
       --http     The HTTP driver your application will use
       --storage  The filesystem module your application will use
   -h, --help     Show help

Closes https://github.com/goravel/goravel/issues/?

Summary by CodeRabbit

  • New Features
    • Improved ordering of command-line options. Built-in flags are now consistently shown at the end, enhancing clarity and ease-of-use when reviewing available commands.
    • Added global flags for help and version information, providing users with more options directly through the command-line interface.

✅ Checks

  • Added test cases for my code

@almas-x almas-x requested a review from a team as a code owner February 12, 2025 09:03
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 12, 2025

Warning

Rate limit exceeded

@almas1992 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 3 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between f5035ce and 9a8cd52.

📒 Files selected for processing (2)
  • console/application.go (1 hunks)
  • console/cli_helper.go (8 hunks)

Walkthrough

The changes introduce modifications to the handling and display of command-line flags in the console package. A new global variable globalFlags has been added, which centralizes the definition of global flags. The sortFlags and sortCommands functions have been updated to improve the sorting logic, ensuring that global flags are consistently displayed at the end of the list. Additionally, the getFlagName function's signature has been altered for better compatibility with the new flag handling.

Changes

File Change Summary
console/cli_helper.go Updated getFlagName function signature and logic; modified sortFlags to prioritize global flags at the end; updated sortCommands for command sorting.
console/application.go Added global variable globalFlags to define and manage global flags; modified NewApplication to utilize globalFlags.

Suggested reviewers

  • hwbrzzl

Possibly related PRs

  • chore: [#880] Make --no-ansi a global option #881: The changes in the main PR and the retrieved PR are related as both modify the console/application.go file to enhance the handling of global flags, specifically with the introduction and management of globalFlags.
  • feat: improve artisan command output readability #766: The changes in the main PR are related to the modifications in the console/application.go file, specifically regarding the handling of global flags, which is also a focus in the retrieved PR. Both PRs involve updates to the NewApplication function and the management of flags within the application.

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: 9a8cd52 Previous: 5779d21 Ratio
Benchmark_EncryptString 6225 ns/op 2160 B/op 15 allocs/op 2188 ns/op 2160 B/op 15 allocs/op 2.85
Benchmark_EncryptString - ns/op 6225 ns/op 2188 ns/op 2.85
Benchmark_DecryptString 6125 ns/op 2040 B/op 17 allocs/op 2083 ns/op 2040 B/op 17 allocs/op 2.94
Benchmark_DecryptString - ns/op 6125 ns/op 2083 ns/op 2.94

This comment was automatically generated by workflow using github-action-benchmark.

@hwbrzzl
Copy link
Contributor

hwbrzzl commented Feb 12, 2025

There seems to be no obvious difference, can Global Options be added?

image

@codecov
Copy link

codecov bot commented Feb 12, 2025

Codecov Report

Attention: Patch coverage is 57.14286% with 6 lines in your changes missing coverage. Please review.

Project coverage is 66.42%. Comparing base (5779d21) to head (9a8cd52).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
console/cli_helper.go 57.14% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #884      +/-   ##
==========================================
- Coverage   66.47%   66.42%   -0.06%     
==========================================
  Files         151      151              
  Lines       10387    10376      -11     
==========================================
- Hits         6905     6892      -13     
- Misses       3124     3126       +2     
  Partials      358      358              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@almas-x
Copy link
Contributor Author

almas-x commented Feb 12, 2025

There seems to be no obvious difference, can Global Options be added?

image

Great idea, I’ll give it a shot. Just a heads-up, the main change is putting -h and --help at the end.🤣

Copy link
Contributor

@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
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f80e784 and c4fcd33.

📒 Files selected for processing (1)
  • console/cli_helper.go (1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
console/cli_helper.go

[warning] 324-325: console/cli_helper.go#L324-L325
Added lines #L324 - L325 were not covered by tests

🔇 Additional comments (1)
console/cli_helper.go (1)

306-316: LGTM! Clear and well-structured initialization of built-in flags.

The map of built-in flags and the helper function provide a clean way to identify built-in flags.

@almas-x
Copy link
Contributor Author

almas-x commented Feb 12, 2025

Unfortunately, in V2 we can’t access global options. But in V3(unreleased), they introduced the parent property, allowing subcommands to access flags from the top-level command.🙁

@almas-x
Copy link
Contributor Author

almas-x commented Feb 12, 2025

Unfortunately, in V2 we can’t access global options. But in V3(unreleased), they introduced the parent property, allowing subcommands to access flags from the top-level command.🙁

We could also hardcode it, although it’s not the best approach.

hwbrzzl
hwbrzzl previously approved these changes Feb 12, 2025
Copy link
Contributor

@hwbrzzl hwbrzzl left a comment

Choose a reason for hiding this comment

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

LGTM

@hwbrzzl
Copy link
Contributor

hwbrzzl commented Feb 12, 2025

Unfortunately, in V2 we can’t access global options. But in V3(unreleased), they introduced the parent property, allowing subcommands to access flags from the top-level command.🙁

Good catch, it's not a big deal. We can implement it in the future.

@almas-x
Copy link
Contributor Author

almas-x commented Feb 13, 2025

image

Copy link
Contributor

@hwbrzzl hwbrzzl left a comment

Choose a reason for hiding this comment

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

Great 👍

@almas-x almas-x merged commit 460946e into master Feb 13, 2025
11 of 14 checks passed
@almas-x almas-x deleted the almas/chore branch February 13, 2025 09:34
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.

3 participants