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

💝 A general purpose WithCommand option. #2

Merged
merged 1 commit into from
Sep 20, 2024
Merged

Conversation

cardil
Copy link
Member

@cardil cardil commented Sep 20, 2024

Changes

  1. 💝 A general purpose WithCommand option.
  2. 🧹 Deprecating WithArgs, WithOutput, WithInput options

Summary by CodeRabbit

  • New Features

    • Introduced new functional options for configuring applications using the Cobra command-line library, allowing for enhanced modularity.
  • Bug Fixes

    • Updated command output handling to utilize the Cobra command framework for improved flexibility.
  • Chores

    • Updated Go version and dependencies for better performance and security.
    • Simplified configuration options by removing several outdated functions.
  • Tests

    • Adjusted test implementations to align with the new command output configuration approach.

@cardil cardil force-pushed the feature/command-option branch from 269059b to 05cbb72 Compare September 20, 2024 10:35
Copy link

coderabbitai bot commented Sep 20, 2024

Walkthrough

The pull request introduces several updates across multiple files, primarily focusing on the configuration of the App in the commandline package. It removes older functional options and replaces them with a new modular approach. The workflow file has been updated to use newer Go versions and actions, while the go.mod reflects changes in dependencies. Additionally, modifications in test files align with the updated command configuration methods.

Changes

Files Change Summary
.github/workflows/go.yml Updated Go version matrix to include '1.22' and '1.23', upgraded setup actions to v5 and v4, modified test command to [email protected], and moved FORCE_COLOR to a global env section.
.golangci.yaml Introduced configuration for GolangCI-Lint with a timeout, enabled specific linters, and excluded wrapcheck from test files.
app.go, options.go Removed Option type and associated configuration functions (WithArgs, WithInput, WithOutput, WithExit) from app.go, while introducing new functional options in options.go for configuring the App with WithCommand and WithExit.
go.mod Upgraded Go version to 1.22.0 and updated dependencies: cobra from v1.5.0 to v1.8.1, gotest.tools from v3.3.0 to v3.5.1, go-cmp from v0.5.5 to v0.6.0, and mousetrap from v1.0.0 to v1.1.0.
app_test.go, test/cmd/main_test.go Updated tests to reflect changes in command configuration, replacing direct output assignments with command-based configuration using WithCommand.
test/internal/cli/app.go Added a comment to ignore the Opts variable by the linter and simplified the Run function's signature by replacing the named args parameter with an underscore.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant CobraCommand

    User->>App: Initialize App
    App->>CobraCommand: Configure with Options
    CobraCommand->>App: Set Output Stream
    App->>User: Execute Command
Loading

🐇 "In the code, a dance we see,
Options gone, but new ones free!
With commands to guide the way,
A simpler path for us to play.
Let's hop along, with joy we cheer,
For changes bright, the future's near!" 🐇


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.

@cardil cardil force-pushed the feature/command-option branch from 05cbb72 to 4d08ab5 Compare September 20, 2024 10:44
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 05cbb72 and 4d08ab5.

Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
Files selected for processing (8)
  • .github/workflows/go.yml (2 hunks)
  • .golangci.yaml (1 hunks)
  • app.go (0 hunks)
  • app_test.go (3 hunks)
  • go.mod (1 hunks)
  • options.go (1 hunks)
  • test/cmd/main_test.go (2 hunks)
  • test/internal/cli/app.go (1 hunks)
Files not reviewed due to no reviewable changes (1)
  • app.go
Files skipped from review as they are similar to previous changes (4)
  • .github/workflows/go.yml
  • go.mod
  • options.go
  • test/cmd/main_test.go
Additional context used
golangci-lint
app_test.go

18-18: undefined: commandline

(typecheck)

test/internal/cli/app.go

9-9: undefined: commandline

(typecheck)

Additional comments not posted (3)
test/internal/cli/app.go (1)

16-16: LGTM!

Replacing the args parameter with an underscore (_) is a good practice to indicate that the argument is intentionally unused in the function. This change simplifies the function signature and enhances readability.

.golangci.yaml (1)

1-39: LGTM!

The golangci-lint configuration follows good practices:

  • It enables a set of presets for common linter categories to ensure code quality.
  • It specifically enables the gci linter for checking the order of imports.
  • It disables several opinionated or noisy linters to focus on the most important warnings.
  • It reasonably excludes wrapcheck linter warnings for test files.
  • It disallows replace directives in the go.mod file.

The configuration strikes a good balance between ensuring code quality and reducing noise.

app_test.go (1)

Line range hint 14-30: LGTM!

The changes in the TestExecuteOrDie function are good improvements:

  1. Replacing the deprecated ioutil package with io aligns with the updated Go standard library practices.
  2. Using a command configuration function to set the command's output, input, and arguments enhances the encapsulation of command setup and is a cleaner approach.

The test structure remains intact, ensuring the functionality is preserved while the command configuration method is modernized.

Tools
golangci-lint

17-17: undefined: commandline

(typecheck)


18-18: undefined: commandline

(typecheck)

test/internal/cli/app.go Show resolved Hide resolved
@cardil cardil merged commit 24d49d4 into main Sep 20, 2024
3 checks passed
@cardil cardil deleted the feature/command-option branch September 20, 2024 10:56
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