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

feat(flag): refactor separateArgs function #197

Merged
merged 2 commits into from
Jul 25, 2024
Merged

feat(flag): refactor separateArgs function #197

merged 2 commits into from
Jul 25, 2024

Conversation

Equationzhao
Copy link
Owner

@Equationzhao Equationzhao commented Jul 25, 2024

Refactor the separateArgs function to improve argument parsing and handling.

  • Implement new helper functions: buildFlagsWithArgsMap, handleLongFlag, and handleShortFlag
  • Enhance separateArgs to handle various flag scenarios, including long flags, short flags, flags with values, and double dash separator
  • Add unit tests for separateArgs, buildFlagsWithArgsMap, handleLongFlag, and handleShortFlag functions

Refactor separateArgs to reduce cognitive complexity and improve maintainability:
- Extract logic into separate functions: buildFlagsWithArgsMap, handleLongFlag, handleShortFlag
- Simplify main loop using switch statement
- Improve code readability

Add comprehensive unit tests:
- Test separateArgs function with various input scenarios
- Create separate tests for buildFlagsWithArgsMap, handleLongFlag, and handleShortFlag
- Ensure proper handling of different flag types and edge cases

This refactoring addresses the high cognitive complexity issue in the separateArgs function
while maintaining its functionality. The added tests improve code reliability and make
future modifications easier and safer.
Improve the separateArgs function to handle complex cases with double dashes and multiple flags. This change allows for more flexible and accurate parsing of command-line arguments.

- Refactor separateArgs function to handle edge cases and improve readability
- Add support for multiple occurrences of double dash ('--')
- Enhance handling of short flags with attached values
- Update tests to cover new complex cases with double dashes
- Add debug print statement to display final arguments
@Equationzhao Equationzhao changed the title feat(flag): refactor separateArgs function and add unit tests feat(flag): refactor separateArgs function Jul 25, 2024
@Equationzhao Equationzhao merged commit 0d5ae02 into master Jul 25, 2024
2 checks passed
@repo-ranger repo-ranger bot deleted the rearrange branch July 25, 2024 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant