Add flag parsing and input validation methods #18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces significant refactoring to the
CLI
struct and its methods in thecli/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 theRun
method into separate methods, and changing local variables in theRun
method to struct fields. Additionally, the testTestRun_failToProvideStdin
incli/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 fieldsfilePath
,replaceExpr
,isOverwrite
, andfilters
to store the command-line flags' values.Run
method: Moved the flag parsing logic into a new methodparseFlags
and the input validation logic into a new methodvalidateInput
. Replaced the local variablesfilePath
,replaceExpr
,isOverwrite
, andfilters
with the newly added struct fields. [1] [2] [3] [4] [5]parseFlags
method: This method handles the parsing of command-line flags and assigns the values to the corresponding struct fields.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 theRun
method, and added several new test cases to improve test coverage.