supitsdu / clipper

Seamlessly copy file contents to clipboard from command line. Lightweight, cross-platform tool for instant text transfers.
MIT License
3 stars 3 forks source link

Refactor `options.Config` to Remove Pointer for `DirectText` (Improving Usability and Testing) #30

Closed supitsdu closed 4 months ago

supitsdu commented 4 months ago

The options.Config struct currently uses a pointer to a string (*string) for the DirectText field. This design choice was initially made to accommodate the return type of flag.String in the ParseFlags() function. However, it has led to increased complexity and challenges in testing and usage due to the need for pointer dereferencing.

Reasoning:

As noted in the PR review, using a pointer for DirectText provided minimal memory optimization benefits and introduced unnecessary complications. Removing the pointer simplifies the code and avoids potential nil pointer errors during testing and subsequent usage.

Proposed Changes:

  1. Remove Pointer: Change the type of the DirectText field in options.Config from *string to string.
  2. Update ParseFlags(): Modify the ParseFlags() function to assign the value returned by flag.String directly to the DirectText field (which is now a string).
  3. Update clipper Package: Ensure that any references to config.DirectText in the clipper package are updated to reflect the change in type.
  4. Update Tests: Adjust unit tests in the clipper_test package to account for the new type of the DirectText field.

Expected Benefits:

_Originally posted by @ccoVeille in https://github.com/supitsdu/clipper/pull/29#discussion_r1657817850_