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

Add flag parsing and input validation methods #18

Merged
merged 1 commit into from
Mar 30, 2024

Conversation

catatsuy
Copy link
Owner

This pull request introduces significant refactoring to the CLI struct and its methods in the cli/cli.go file, aiming to improve the readability and maintainability of the code. The changes mainly involve moving flag parsing and input validation logic from the Run method into separate methods, and changing local variables in the Run method to struct fields. Additionally, the test TestRun_failToProvideStdin in cli/cli_test.go has been modified to accommodate these changes.

Here's a summary of the most important changes:

Refactoring in cli/cli.go:

  • CLI struct: Added new fields filePath, replaceExpr, isOverwrite, and filters to store the command-line flags' values.
  • Run method: Moved the flag parsing logic into a new method parseFlags and the input validation logic into a new method validateInput. Replaced the local variables filePath, replaceExpr, isOverwrite, and filters with the newly added struct fields. [1] [2] [3] [4] [5]
  • New parseFlags method: This method handles the parsing of command-line flags and assigns the values to the corresponding struct fields.
  • New validateInput method: This method validates the input based on the parsed flags and handles error messages.

Changes in cli/cli_test.go:

  • TestRun_failToProvideStdin test: Updated the test to handle the changes in the Run method, and added several new test cases to improve test coverage.

@catatsuy catatsuy merged commit 2e49c67 into main Mar 30, 2024
1 check passed
@catatsuy catatsuy deleted the feature_refactor_function_flags branch March 30, 2024 16:27
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