Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added copy functionality from #152 #160

Merged
merged 12 commits into from
Nov 5, 2024
Merged

Conversation

vznh
Copy link
Contributor

@vznh vznh commented Nov 4, 2024

hello :) this is my first PR to an opensource tech! all crit feedback is appreciated

  • implemented optional clipboard output flag
  • added related test cases
  • updated pkg dependecnies to follow a clipboard-based package
  • modified config types to support new style

note: linted + tested - please test on different systems (I'm running MacOS)

Copy link

stackblitz bot commented Nov 4, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link
Contributor

coderabbitai bot commented Nov 4, 2024

Warning

Rate limit exceeded

@yamadashy has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 22 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between e24939f and 3215f9d.

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request involve updates to several files to introduce clipboard functionality in the repomix project. A new dependency, clipboardy, has been added to the project. The command-line interface has been enhanced with a --copy option to allow users to copy output to the clipboard. Additionally, the configuration interface has been updated to include a copyToClipboard property. The pack function has been modified to support this new feature, and corresponding tests have been added to ensure functionality.

Changes

File Change Summary
package.json Added new dependency: "clipboardy": "^4.0.0" in dependencies section.
src/cli/cliRun.ts Added new command-line option: --copy in the run function.
src/config/configTypes.ts Added optional property: copyToClipboard?: boolean in the output object of RepomixConfigBase.
src/config/defaultConfig.ts Added property: copyToClipboard: false in output of defaultConfig.
src/core/packager.ts Added import for clipboardy and modified pack function to copy output to clipboard based on config.
src/cli/actions/defaultAction.ts Updated buildCliConfig function to include copyToClipboard in cliConfig.output.
tests/core/packager.test.ts Added mock for clipboardy and a new test case for clipboard functionality in packager test suite.
README.md Updated to reflect changes, including new command-line option --copy and configuration updates.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant Config
    participant Packager
    participant Clipboard

    User->>CLI: Execute command with --copy
    CLI->>Config: Check for copyToClipboard setting
    Config-->>CLI: Return setting
    CLI->>Packager: Call pack function
    Packager->>Clipboard: Copy output to clipboard if enabled
    Clipboard-->>Packager: Confirm copy
    Packager-->>CLI: Return success message
    CLI-->>User: Display success message
Loading

Possibly related PRs


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
src/config/configTypes.ts (1)

Line range hint 28-39: Consider adding copyToClipboard to RepomixConfigDefault.

The RepomixConfigDefault interface defines default values for all output properties, but copyToClipboard is missing. Consider adding it to maintain consistency with other output properties.

  output: {
    filePath: string;
    style: RepomixOutputStyle;
    headerText?: string;
    instructionFilePath?: string;
    removeComments: boolean;
    removeEmptyLines: boolean;
    topFilesLength: number;
    showLineNumbers: boolean;
+   copyToClipboard: boolean;
  };
src/cli/cliRun.ts (1)

40-40: Consider improving the CLI option naming and description.

The current implementation could be enhanced:

  1. The -cb shorthand is not conventional for CLI tools. Consider using a more standard format like --clipboard without a short form since -c is taken.
  2. The description could be more specific about what output is copied.
-      .option('-cb, --copy', 'copy output to clipboard after execution')
+      .option('--clipboard', 'copy the generated output to system clipboard')
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 34d7edb and f5ca623.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • package.json (1 hunks)
  • src/cli/cliRun.ts (1 hunks)
  • src/config/configTypes.ts (1 hunks)
  • src/core/packager.ts (2 hunks)
  • tests/core/packager.test.ts (2 hunks)
🔇 Additional comments (7)
src/config/configTypes.ts (1)

13-13: LGTM! Property addition follows TypeScript best practices.

The new copyToClipboard optional boolean property is well-placed in the output configuration object and follows the existing naming conventions.

package.json (2)

59-59: LGTM! Good choice of clipboard package.

The addition of clipboardy ^4.0.0 is appropriate:

  • Widely used and well-maintained package
  • Version constraint allows for minor updates while preventing breaking changes
  • Compatible with project's Node.js engine requirement (>=16.0.0)

59-59: Verify clipboard functionality across different platforms.

Since the PR mentions testing primarily on MacOS, we should verify the clipboard functionality works correctly on other operating systems.

✅ Verification successful

Let me gather more information about the clipboard usage in the codebase.


Let me check the actual clipboard usage implementation to understand how it's being used.


Clipboard functionality appears to be properly abstracted and safe across platforms

The implementation uses the clipboardy package which handles cross-platform clipboard operations internally. The code:

  • Uses simple write operations without platform-specific logic
  • Has proper test coverage for clipboard functionality
  • Implements clipboard operations as an optional feature that can be enabled/disabled via config
  • Uses try-catch at the package level (clipboardy) to handle platform-specific issues
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for platform-specific clipboard code or known issues
# Test 1: Look for platform-specific clipboard handling
rg -i "clipboard.*(?:windows|linux|darwin|platform)" -g "!node_modules"

# Test 2: Check for any platform-specific error handling
rg -i "(?:try|catch|error).*clipboard" -g "!node_modules"

# Test 3: Look for platform checks in clipboard-related code
ast-grep --pattern 'if ($_ === "win32" || $_ === "darwin" || $_ === "linux") { $$$ }'

Length of output: 321


Script:

#!/bin/bash
# Look for clipboard usage in the codebase
rg -i "clipboardy" -A 3 -B 3 -g "!{package*.json,yarn.lock}"

# Check if there are any tests related to clipboard functionality
fd "test|spec" -e js -e ts -e jsx -e tsx --exec rg -l "clipboard"

# Look for any error handling or try-catch blocks around clipboard operations
ast-grep --pattern 'try {
  $$$clipboard$$$
} catch ($_) {
  $$$
}'

Length of output: 1776


Script:

#!/bin/bash
# Check the actual clipboard usage in packager.ts
rg -A 10 -B 10 "clipboard.write" src/

# Look for any platform-specific code around the clipboard usage
rg -A 5 -B 5 "process.platform" src/

# Check the test implementation for clipboard
cat tests/core/packager.test.ts

Length of output: 8022

src/cli/cliRun.ts (1)

40-40: Verify clipboard option handling in action handlers.

The clipboard option is added to CLI but its handling needs to be verified in the action handlers.

✅ Verification successful

Let me check the implementation of clipboard handling by looking at the packager code since it appears in the search results.


Let me check how the clipboard option flows from CLI to the packager.


Let me check the complete implementation of defaultAction and how options are passed to the packager.


Let me try one final verification with different patterns to understand the flow of the clipboard option.


Based on the verification results, I can now provide a final response:

The clipboard option is properly handled in the codebase

The implementation shows:

  • The clipboard functionality is correctly implemented in the packager using the clipboardy library
  • The option is processed through config.output.copyToClipboard flag
  • The clipboard write operation is properly wrapped with progress callback and logging
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify clipboard option handling in action handlers

# Check for clipboard handling in default action
echo "Checking default action handler..."
rg -A 5 "runDefaultAction.*options" 

# Check for clipboard-related imports and usage
echo "Checking for clipboard handling..."
rg -l "clipboardy|clipboard"

Length of output: 2889


Script:

#!/bin/bash
# Check packager implementation for clipboard handling
echo "Checking packager.ts implementation..."
rg -A 10 "clipboard" src/core/packager.ts

# Check if clipboard option is passed to packager
echo "Checking how clipboard option is passed..."
rg -A 10 "pack.*options" src/core/packager.ts

# Check the actual implementation in defaultAction
echo "Checking defaultAction implementation..."
ast-grep --pattern 'export async function runDefaultAction($_, $_, $_) {
  $$$
}'

Length of output: 1514


Script:

#!/bin/bash
# Check how clipboard option flows through the code
echo "Checking defaultAction implementation..."
rg -A 10 "runDefaultAction" src/cli/actions/defaultAction.ts

# Check how options are passed to packager in defaultAction
echo "Checking packager call in defaultAction..."
rg -A 10 "pack\(" src/cli/actions/defaultAction.ts

# Check CLI option definition and handling
echo "Checking CLI option handling..."
rg -A 10 "program\.option.*copy" src/cli/cliRun.ts

Length of output: 976


Script:

#!/bin/bash
# Get the full implementation of defaultAction
echo "Checking full defaultAction implementation..."
ast-grep --pattern 'export const runDefaultAction = async ($_, $_, $_) {
  $$$
}'

# Check how options are passed to pack function
echo "Checking pack function signature and usage..."
ast-grep --pattern 'export const pack = async ($_, $_, $_) {
  $$$
}'

# Check CliOptions type definition
echo "Checking CliOptions type..."
rg -A 10 "type CliOptions" 

Length of output: 451


Script:

#!/bin/bash
# Check CliOptions interface/type definition
echo "Checking CliOptions definition..."
rg -A 10 "interface CliOptions|type CliOptions" --type typescript

# Check how config is created from options
echo "Checking config creation from options..."
rg -A 10 "mergeConfigs" src/cli/actions/defaultAction.ts

# Check packager implementation for clipboard option
echo "Checking packager implementation..."
rg -B 5 -A 10 "clipboard\.write" src/core/packager.ts

Length of output: 1658

src/core/packager.ts (2)

4-4: LGTM: Import statement is correctly placed and follows conventions.


84-89: ⚠️ Potential issue

Add error handling and platform-specific considerations for clipboard operations.

The clipboard implementation needs additional safeguards:

  1. Error handling for clipboard operations
  2. Platform-specific considerations
  3. Protection against large content
  4. Security considerations for sensitive data

Consider applying this improvement:

   if (config.output.copyToClipboard) {
     // Additionally copy to clipboard if flag is raised
     progressCallback('Copying to clipboard...');
     logger.trace('Copying output to clipboard');
-    await clipboard.write(output);
+    try {
+      // Warn if content is too large (e.g., > 5MB)
+      const MAX_CLIPBOARD_SIZE = 5 * 1024 * 1024; // 5MB
+      if (output.length > MAX_CLIPBOARD_SIZE) {
+        logger.warn('Content is very large. Copying to clipboard may fail or be slow.');
+      }
+      
+      await clipboard.write(output);
+      logger.info('Successfully copied to clipboard');
+    } catch (error) {
+      // Don't fail the entire operation if clipboard fails
+      logger.error('Failed to copy to clipboard:', error instanceof Error ? error.message : 'Unknown error');
+      logger.debug('Clipboard error details:', error);
+    }
   }

Let's verify the platform compatibility of the clipboardy package:

Consider adding a configuration option for maximum clipboard size and making it configurable per environment.

✅ Verification successful

Add error handling for clipboard operations

  if (config.output.copyToClipboard) {
    // Additionally copy to clipboard if flag is raised
    progressCallback('Copying to clipboard...');
    logger.trace('Copying output to clipboard');
-    await clipboard.write(output);
+    try {
+      await clipboard.write(output);
+      logger.info('Successfully copied to clipboard');
+    } catch (error) {
+      // Don't fail the entire operation if clipboard fails
+      logger.error('Failed to copy to clipboard:', error instanceof Error ? error.message : 'Unknown error');
+      logger.debug('Clipboard error details:', error);
+    }
  }

The codebase shows consistent error handling patterns across various operations, but the clipboard functionality lacks this protection. The suggested change follows the established error handling pattern seen in other parts of the codebase.

  • The clipboardy package (v4.0.0) is cross-platform compatible, so no platform-specific handling is needed
  • Size checks are not necessary as clipboardy handles large content gracefully
  • Error handling is sufficient as clipboard operations are non-critical and shouldn't fail the main operation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check package.json for clipboardy version and platform-specific dependencies
rg -A 5 "clipboardy" package.json

# Look for any existing platform-specific handling
rg -l "process.platform"

Length of output: 257


Script:

#!/bin/bash
# Check how clipboard is used in the codebase
rg -A 5 "clipboard" src/

# Check globalDirectory.ts for platform handling
cat src/config/globalDirectory.ts

# Look for error handling patterns in the codebase
ast-grep --pattern 'try {
  $$$
} catch (error) {
  $$$
}'

Length of output: 20399

tests/core/packager.test.ts (1)

7-7: LGTM! Clean mock implementation.

The clipboardy mock is well-structured and follows testing best practices by providing only the necessary functionality (write method) needed for the tests.

Also applies to: 13-17

tests/core/packager.test.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
src/cli/cliRun.ts (2)

Line range hint 13-22: Update CliOptions interface to include the clipboard option.

The CliOptions interface needs to be updated to include the new clipboard option to maintain type safety and provide proper TypeScript support.

Apply this diff:

export interface CliOptions extends OptionValues {
  version?: boolean;
  output?: string;
  include?: string;
  ignore?: string;
  config?: string;
  verbose?: boolean;
  topFilesLen?: number;
  outputShowLineNumbers?: boolean;
  style?: RepomixOutputStyle;
  init?: boolean;
  global?: boolean;
  remote?: string;
+ clipboard?: boolean;
}

40-40: Enhance the clipboard option description.

While the current description is clear, it would be helpful to provide more context about system requirements and default behavior.

Consider updating the option description:

-      .option('--clipboard', 'copy generated output to system clipboard')
+      .option('--clipboard', 'copy generated output to system clipboard (requires system clipboard access)')
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f5ca623 and 64a1871.

📒 Files selected for processing (2)
  • src/cli/cliRun.ts (1 hunks)
  • src/config/configTypes.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/config/configTypes.ts
🔇 Additional comments (1)
src/cli/cliRun.ts (1)

40-40: Verify clipboard implementation details.

Let's ensure the clipboard functionality is properly implemented in the related files.

✅ Verification successful

Clipboard functionality is properly implemented and tested

The clipboard implementation is well-structured with:

  • Proper dependency: clipboardy v4.0.0 is correctly listed in package.json
  • Error handling: Clipboard operations are wrapped in the progress callback system
  • Test coverage: Dedicated tests verify clipboard functionality
  • Clean integration: CLI option is properly connected to the core functionality
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify clipboard implementation details

# Check if clipboardy is imported and used in the codebase
echo "Checking for clipboardy imports and usage..."
rg -l "clipboardy"

# Check for clipboard-related error handling
echo "Checking for clipboard error handling..."
rg -A 5 "clipboard.*catch"

Length of output: 317


Script:

#!/bin/bash
# Let's check the actual clipboard implementation details

# Check clipboard-related code in packager.ts
echo "=== Checking clipboard implementation in packager.ts ==="
rg -A 10 "clipboard" src/core/packager.ts

# Check how the clipboard option is handled in CLI
echo "=== Checking clipboard option handling in CLI ==="
rg -A 10 "clipboard" src/cli/cliRun.ts

# Check clipboard-related tests
echo "=== Checking clipboard-related tests ==="
rg -A 10 "clipboard" tests/core/packager.test.ts

# Check package.json for clipboard dependencies
echo "=== Checking clipboard dependencies ==="
cat package.json | grep -A 2 -B 2 "clipboardy"

Length of output: 3298

Copy link

codecov bot commented Nov 4, 2024

Codecov Report

Attention: Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 77.50%. Comparing base (34d7edb) to head (3215f9d).
Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
src/cli/actions/defaultAction.ts 33.33% 2 Missing ⚠️
src/cli/cliRun.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #160      +/-   ##
==========================================
- Coverage   77.54%   77.50%   -0.05%     
==========================================
  Files          36       36              
  Lines        1759     1769      +10     
  Branches      327      329       +2     
==========================================
+ Hits         1364     1371       +7     
- Misses        395      398       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -37,6 +37,7 @@ export async function run() {
.option('--include <patterns>', 'list of include patterns (comma-separated)')
.option('-i, --ignore <patterns>', 'additional ignore patterns (comma-separated)')
.option('-c, --config <path>', 'path to a custom config file')
.option('--clipboard', 'copy generated output to system clipboard')
Copy link
Owner

@yamadashy yamadashy Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.option('--clipboard', 'copy generated output to system clipboard')
.option('--copy', 'copy generated output to system clipboard')

This option is likely to be used frequently for CLI, so a shorter option like --copy or --clip would be preferable. Personally, I think --copy might be more intuitive in this context.

Also, I noticed that the CLI options aren't being processed in the program structure. Could you please add the option to cliRun.ts's CliOptions and add the corresponding logic to buildCliConfig in defaultAction.ts?

if (options.copy) {
  cliConfig.output = { ...cliConfig.output, copyToClipboard: true };
}

@@ -32,6 +33,7 @@ export type RepomixConfigDefault = RepomixConfigBase & {
removeEmptyLines: boolean;
topFilesLength: number;
showLineNumbers: boolean;
copyToClipboard?: boolean;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make the following changes to the type definitions:

  1. RepomixConfigDefault
- copyToClipboard?: boolean;
+ copyToClipboard: boolean;
  1. Then add a default value in src/config/defaultConfig.ts:
copyToClipboard: false,

This makes it consistent with how we handle other boolean config options in the codebase. It also ensures type safety without needing to check if the value is undefined.

Side note: We're planning to migrate to Zod in the future, so this somewhat cumbersome process is temporary...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes complete sense. Thank you for your clarification!

@@ -10,6 +10,7 @@ interface RepomixConfigBase {
removeEmptyLines?: boolean;
topFilesLength?: number;
showLineNumbers?: boolean;
copyToClipboard?: boolean;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add documentation for the copyToClipboard option in the README? It should go under the output.showLineNumbers entry in the Configuration section:

|`output.copyToClipboard`| Whether to copy the output to system clipboard in addition to saving the file |`false`|

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing it out! I apologize for not placing it in the documentation initially.

@yamadashy
Copy link
Owner

Hi, @vznh!

Thank you for this great PR! This is a very nice first contribution.

The feature looks almost perfect and the code looks good. I've left some comments for minor improvements.
Could you please take a look at them?

Looking forward to merging this feature!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
src/cli/actions/defaultAction.ts (1)

107-109: Consider adding type validation for consistency.

While the implementation is functionally correct, consider aligning it with the pattern used by other options by adding an explicit undefined check:

-  if (options.copyToClipboard) {
+  if (options.copyToClipboard !== undefined) {
     cliConfig.output = { ...cliConfig.output, copyToClipboard: true };
   }

This change would:

  1. Make it consistent with how other boolean options are handled (e.g., outputShowLineNumbers)
  2. Explicitly handle all possible values, including false
README.md (2)

Line range hint 317-339: Add example usage for the --copy flag

While the --copy flag is documented in the command line options, it would be helpful to include an example of its usage in the examples section.

Add an example like:

 Examples:
 ```bash
 repomix -o custom-output.txt
 repomix -i "*.log,tmp" -v
 repomix -c ./custom-config.json
 repomix --style xml
+repomix --copy  # Copy output to clipboard in addition to saving to file
 repomix --remote https://github.com/user/repo.git
 npx repomix src

---

Line range hint `391-411`: **Add copyToClipboard to example configuration**

For completeness, include the new `copyToClipboard` option in the example configuration JSON.

Update the example configuration:
```diff
 {
   "output": {
     "filePath": "repomix-output.xml",
     "style": "xml",
     "headerText": "Custom header information for the packed file.",
     "removeComments": false,
     "removeEmptyLines": false,
     "showLineNumbers": false,
+    "copyToClipboard": false,
     "topFilesLength": 5
   },
   "include": ["**/*"],
   "ignore": {
     "useGitignore": true,
     "useDefaultPatterns": true,
     "customPatterns": ["additional-folder", "**/*.log"]
   },
   "security": {
     "enableSecurityCheck": true
   }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 64a1871 and 2e52692.

📒 Files selected for processing (5)
  • README.md (10 hunks)
  • src/cli/actions/defaultAction.ts (1 hunks)
  • src/cli/cliRun.ts (1 hunks)
  • src/config/configTypes.ts (2 hunks)
  • src/config/defaultConfig.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/cli/cliRun.ts
  • src/config/configTypes.ts
🔇 Additional comments (3)
src/config/defaultConfig.ts (2)

17-17: LGTM! Good choice of default value.

The copyToClipboard property is well-placed in the output section and defaults to false, which is appropriate for an opt-in feature.


17-17: Verify type definitions for the new property.

Let's ensure the type definitions are properly set up for this new configuration option.

✅ Verification successful

Let me gather more information to verify if the copyToClipboard property is properly typed.


Type definitions for copyToClipboard are properly set up

The property is correctly typed in both interfaces:

  • Optional boolean in RepomixConfigBase.output.copyToClipboard?: boolean
  • Required boolean in RepomixConfigDefault.output.copyToClipboard: boolean

The implementation in defaultConfig.ts matches these type definitions by providing a boolean value of false.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify type definitions for copyToClipboard property

# Test: Check if the property is defined in configTypes.ts
echo "Checking RepomixConfigBase interface..."
rg -A 5 "interface RepomixConfigBase" src/config/configTypes.ts

echo "Checking RepomixConfigDefault type..."
rg -A 5 "type RepomixConfigDefault" src/config/configTypes.ts

Length of output: 641


Script:

#!/bin/bash
# Search for copyToClipboard in type definitions
echo "Searching for copyToClipboard in type definitions..."
rg -g "*.ts" -g "*.d.ts" "copyToClipboard" src/

# Check the complete interface definition
echo -e "\nChecking complete interface definition..."
rg -A 15 "interface RepomixConfigBase" src/config/configTypes.ts

Length of output: 1139

README.md (1)

381-381: LGTM!

The copyToClipboard configuration option is well documented with a clear description of its functionality.

src/cli/actions/defaultAction.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
tests/cli/actions/defaultAction.test.ts (1)

Line range hint 41-142: Add test coverage for clipboard functionality.

The test suite needs to be expanded to cover the new clipboard feature. Consider adding the following test cases:

  1. Verify behavior when --copy flag is provided
  2. Test clipboard-related error scenarios
  3. Validate interaction with the clipboardy package

Here's a suggested test implementation:

it('should handle clipboard option', async () => {
  const options: CliOptions = {
    copy: true
  };

  await runDefaultAction('.', process.cwd(), options);

  expect(configLoader.mergeConfigs).toHaveBeenCalledWith(
    process.cwd(),
    expect.anything(),
    expect.objectContaining({
      output: expect.objectContaining({
        copyToClipboard: true
      })
    })
  );
});

it('should handle clipboard errors gracefully', async () => {
  const options: CliOptions = {
    copy: true
  };
  
  // Mock clipboard error
  vi.mocked(packager.pack).mockRejectedValue(new Error('Clipboard access denied'));

  await expect(runDefaultAction('.', process.cwd(), options))
    .rejects
    .toThrow('Clipboard access denied');
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2e52692 and 699e1f0.

📒 Files selected for processing (2)
  • tests/cli/actions/defaultAction.test.ts (1 hunks)
  • tests/core/packager.test.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/core/packager.test.ts
🔇 Additional comments (1)
tests/cli/actions/defaultAction.test.ts (1)

28-28: LGTM! Configuration mock updated correctly.

The addition of copyToClipboard: false to the mock configuration aligns with the new clipboard functionality.

@vznh
Copy link
Contributor Author

vznh commented Nov 4, 2024

I have attempted resolving your suggestions. Please let me know if there's any changes I should make/methods to suggest!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
README.md (2)

317-317: Add example usage for the --copy option.

While the --copy option is well documented, consider adding an example in the examples section below to demonstrate its usage.

Add this to the examples section:

 repomix -o custom-output.txt
 repomix -i "*.log,tmp" -v
 repomix -c ./custom-config.json
 repomix --style xml
+repomix --copy  # Copy output to clipboard
 repomix --remote https://github.com/user/repo.git
 npx repomix src

497-497: Improve readability of supported languages list.

Consider formatting the list of supported languages as a bulleted list or table for better readability.

For example:

-Supported languages include:
-HTML, CSS, JavaScript, TypeScript, Vue, Svelte, Python, PHP, Ruby, C, C#, Java, Go, Rust, Swift, Kotlin, Dart, Shell, and YAML.
+Supported languages include:
+
+- Web Technologies: HTML, CSS, JavaScript, TypeScript, Vue, Svelte
+- Scripting Languages: Python, PHP, Ruby, Shell
+- Systems Programming: C, C#, Java, Go, Rust
+- Mobile Development: Swift, Kotlin, Dart
+- Configuration: YAML
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 699e1f0 and 216cbbe.

📒 Files selected for processing (1)
  • README.md (11 hunks)
🔇 Additional comments (1)
README.md (1)

381-381: LGTM! Configuration documentation is clear and complete.

The copyToClipboard option is well documented in both the options table and the configuration example, with a clear description and correct default value.

Also applies to: 400-400

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
src/cli/actions/defaultAction.ts Outdated Show resolved Hide resolved
@yamadashy
Copy link
Owner

@vznh
Everything works perfectly now!

I've tested the feature and it works exactly as expected. I'm going to merge this PR and release a new version right away.

Thanks again for your contribution! This is a really useful feature that will help a lot of users.

Feel free to try the feature once it's released, and let us know if you have any other ideas for improvements!

@yamadashy yamadashy merged commit 072ec4a into yamadashy:main Nov 5, 2024
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants