Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: updates Package Structure, Add Interfaces, and Enhance Test…
…ing (#29) * refactor: remove main_test.go Removed main_test.go as its functionality is now integrated into more specific test files. * refactor: remove main.go Removed main.go file to migrate functionality to the more appropriately named cli/main.go. * feat: define options configuration struct Define a configuration struct for command line options to manage and parse command line arguments effectively. * feat: introduce content and clipboard interfaces Introduce interfaces for content reading and clipboard writing to enhance flexibility and testability. * refactor: restructure command line argument handling Refactor command line argument handling into a dedicated CLI package for improved organization and clarity. * feat: add ClipboardWriter as a parameter to Run - Modify the Run function to accept a ClipboardWriter as a parameter instead of creating a DefaultClipboardWriter directly. This would enable easier mocking of the clipboard for testing. * feat: update clipper.Run() with the default clipboard writer * test: add comprehensive unit tests for clipper package This commit introduces a new `tests/clipper_test.go` file, which includes comprehensive unit tests for the clipper package. The tests cover various components including: - FileContentReader: Reads content from a file. - StdinContentReader: Reads content from standard input. - DefaultClipboardWriter: Writes content to the clipboard. - ParseContent: Parses content from multiple sources, including direct text, files, and invalid inputs. Additionally, the tests use helper functions for creating temporary files and replacing stdin, improving readability and maintainability. * chore: bump release to 1.5.0 * build: update build target to the cli folder * tests: skips DefaultClipboardWriter test on CI Skipping clipboard test in short mode. Helps avoid errors when on CI environments. * refactor: modify Run() to return (string, error) instead of printing and exiting - Refactored the `Run` function to return a `string` (representing the success message or version information) and an `error`. - This change allows the caller of `Run` to handle the output and errors gracefully, rather than relying on `Run` to print messages and exit directly. - Updated the error handling to use `fmt.Errorf` with error wrapping (%w) for better context. - This improvement enhances the flexibility and testability of the `clipper` tool. * refactor: update main function to handle Run's (string, error) return values - Modified the `main` function to call `clipper.Run` and handle both the returned message and error. - Prints the success message if no error occurred, or an error message if an error was encountered. - Exits with a status code of 0 for success or 1 for errors. - This change ensures that the `main` function gracefully handles the output and errors generated by the `Run` function. * refactor: extract GetReaders function to improve code organization - Introduced a new function `GetReaders` in `clipper.go` to handle the logic of creating `ContentReader` instances based on command-line arguments. - This refactoring improves the readability and maintainability of the `Run` function by separating out a specific task. - The `Run` function now calls `GetReaders` to obtain the necessary readers, making its logic more focused and concise.
- Loading branch information