Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance ContentReader with New Formatting Options and Code Refactoring (
#38) * refact(options): improve var names and cli args The variable names are now more intuitive, and the use of versionStr in GetVersion makes the logic easier to follow. * feat(options): add new flags and configuration options - Added flags for HTML, Markdown, MimeType, and LineNumbers formatting - Introduced ShouldFormat flag to determine if any formatting options are enabled - Updated ParseFlags to parse new command-line flags and set default values * feat(reader): enhance content reading and formatting capabilities - Added ContentReader struct holding a reference to Config for configuration-based content reading and formatting - Implemented ReadAll to read content from files or stdin and aggregate results - Introduced ReadFilesAsync for concurrent file reading using goroutines - Added JoinAll to aggregate content from multiple sources into a single string - Implemented ReadFile for reading and formatting content from a single file - Added Readable to check file readability and accessibility - Implemented IOReader for reading content from an io.Reader - Added CreateContent to apply formatting based on configuration - Implemented Format for HTML, Markdown, MIME type inclusion, and line numbering * refactor(clipper): update Run function to use new ContentReader - Updated Run to utilize the new ContentReader for reading and processing content - Improved error handling and aggregation of content from multiple sources * feat(cli): update main to use ContentReader and improve readability - Replaced direct instantiation of ContentReader with configuration-driven instantiation - Enhanced readability by defining reader and passing it to clipper.Run * test(reader): add comprehensive tests for ContentReader functionalities - Added tests for ReadAll with multiple files - Added tests for ReadFile to ensure proper file reading - Added tests for Readable to verify file accessibility checks - Added tests for IOReader to handle reading from io.Reader - Added tests for CreateContent with and without formatting options (HTML, Markdown) - Added tests for JoinAll to aggregate multiple content strings * chore(deps): update dependencies in go.mod - Added github.com/gabriel-vasile/mimetype v1.4.4 for MIME type detection. - Added github.com/stretchr/testify v1.9.0 for testing assertions. Also updated indirect dependencies: - github.com/davecgh/go-spew v1.1.1 - github.com/pmezard/go-difflib v1.0.0 - golang.org/x/net v0.26.0 - gopkg.in/yaml.v3 v3.0.1 * docs: Update README.md with new features and installation options - Updated README.md file to include new features such as Mimetype & Codeblock. - Revised installation instructions to provide clearer guidance on using the install script and manual installation methods. * refactor(reader): improve code documentation and optimize error handling - Enhanced comments across ContentReader functions for better clarity and understanding. - Moved error check inside the goroutine before the mu.Lock() call in ReadFilesAsync to reduce mutex hold time and improve efficiency. * refactor(reader): improve comments and add tests for JoinAll with empty contents - Enhanced comments for better documentation in reader.go and tests. - Added tests to cover scenarios where JoinAll receives empty contents, ensuring no extra new line is added for empty contents.
- Loading branch information