Skip to content

Conversation

@vwxyzh
Copy link
Contributor

@vwxyzh vwxyzh commented May 20, 2025

This pull request refactors and enhances argument parsing in the ChatSample.Cli application. The most significant changes include adding regular expressions for argument validation, introducing a reusable ParseArguments method, and updating existing methods to use this new approach. These changes improve code maintainability, readability, and robustness when handling user inputs.

Enhancements to Argument Parsing:

  • Expanded TypeInfo Record: Added a Regex property to the TypeInfo record to associate each type with a regular expression for validation. Updated the TypeMap dictionary to include these regular expressions for supported types (int, string, bool, double, and binary). [1] [2]

  • Added Regular Expressions: Introduced several GeneratedRegex methods for validating input types, including IntegerRegex, StringRegex, BooleanRegex, DoubleRegex, BytesRegex, and ParameterEndRegex. These regex patterns ensure inputs conform to expected formats.

Code Refactoring for Reusability:

  • New ParseArguments Method: Created a reusable ParseArguments method to handle argument parsing and validation using the associated regex patterns in TypeInfo. This method streamlines the validation process and centralizes error handling.

  • Refactored Existing Methods: Updated the Send, ClientSend, and ClientStream methods to use the new ParseArguments method, replacing inline argument parsing logic. This reduces code duplication and enhances readability. [1] [2] [3]

Bug Fix:

  • Fixed Escape Character Handling: Updated the Escape method to correctly handle escaped backslashes (\) in string inputs, ensuring proper parsing of escaped characters.

@vwxyzh vwxyzh enabled auto-merge (squash) May 20, 2025 03:24
Copy link
Member

@vicancy vicancy left a comment

Choose a reason for hiding this comment

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

add some test coverage?

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.

2 participants