TReq icon indicating copy to clipboard operation
TReq copied to clipboard

Add a validation and suggestions for incorrect subcommands

Open talis-fb opened this issue 1 year ago • 0 comments

The current behavior of the treq command allows the execution of a request when a subcommand is omitted, potentially leading to confusion. For example, both treq GET url.com and treq url.com execute the same command. However, if the user mistypes a subcommand (e.g., treq GE url.com), it interprets the mistyped text as the URL and additional parameters, submitting a GET request for http://GE and attempting to validate url.com as a Request item.

The proposal is to implement a command validator specifically for default command requests (no subcommand provided). This validator will check for potential mistyped subcommands. If the entered command closely resembles a valid subcommand, provide a helpful suggestion to the user before executing the command.

Expected Behavior:

  • Implement a command validator to identify potential mistyped subcommands for default command requests.
  • Provide suggestions for valid subcommands using string distance calculation (Levenshtein distance).
  • Optionally, continue execution only if the user confirms the suggested correction. (Consider implementing a flag like --no-confirm to skip the confirmation prompt and only display a warning.)

Additional Considerations:

  • Ensure that the string distance calculation is case-insensitive. For example, when a user types treq get or treq GEt, the recommendation to type GET should appear, regardless of the casing.
  • Provide a nice and clear output warning for this help.
  • Conduct thorough testing to verify the accurate of String distance algorithm

talis-fb avatar Jan 27 '24 13:01 talis-fb