remix-flat-routes icon indicating copy to clipboard operation
remix-flat-routes copied to clipboard

Refactor cli script for better readability and separation of concerns

Open oats7777 opened this issue 1 year ago • 0 comments

  1. Error message handling: Previously, error messages were handled inline within the main function, making the code harder to read and maintain. This PR introduces a separate function, printErrorAndExit, which takes care of printing the error message and exiting the process. This helps keep the code clean and makes it easier to handle errors.

  2. Option building: The process of building the options object was mixed with validating command line arguments. This PR introduces a separate function, buildOptions, which is responsible solely for creating the options object based on the provided arguments. This separation of concerns makes the code easier to understand and maintain.

  3. Usage message: The usage function has been renamed to printUsageAndExit to better convey its purpose. Additionally, the usage message has been updated to use a template string, improving readability.

These changes not only make the code more readable but also follow best practices for separation of concerns, ensuring that each function has a single, clear responsibility. This will make the script easier to maintain and extend in the future.

oats7777 avatar Apr 25 '23 07:04 oats7777