Skip to content

Copy directory(tree)#103

Merged
MusicalNinjaDad merged 11 commits into
mainfrom
copy
Nov 7, 2025
Merged

Copy directory(tree)#103
MusicalNinjaDad merged 11 commits into
mainfrom
copy

Conversation

@MusicalNinjaDad

@MusicalNinjaDad MusicalNinjaDad commented Nov 7, 2025

Copy link
Copy Markdown
Owner

Summary by Sourcery

Add a new Copy option and --copy flag to replicate entire directory trees to the destination, enforce mutual exclusion between copy and in-place modes, and update tests and documentation accordingly.

New Features:

  • Introduce a Copy option and --copy flag to copy complete directory contents to /DESTINATION/full/source/path
  • Support recursive directory copying when combined with --recursive

Enhancements:

  • Return a clear InvocationError when both --copy and --in-place are used together
  • Allow copying non-ELF files in copy mode without failing on format errors

Documentation:

  • Add description of the --copy flag in the CLI help and README

Tests:

  • Add unit and integration tests for copy behavior, including directory copy scenarios
  • Add TestCopyInplace in both CLI and internal tests to verify error handling for copy + in-place

@sourcery-ai

sourcery-ai Bot commented Nov 7, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR introduces a new “copy” mode to Snaggle by adding a Copy() option and corresponding CLI flag, wiring it through the core snaggle function to copy complete directories (with optional recursion) instead of creating links, enforcing constraints on invalid flag combinations, and providing full test coverage and documentation for the new behavior.

Sequence diagram for Snaggle execution with --copy flag

sequenceDiagram
    actor User
    participant CLI
    participant Snaggle
    participant FileSystem
    User->>CLI: Run 'snaggle --copy [options] SRC DEST'
    CLI->>Snaggle: Call Snaggle(path, root, opts...)
    Snaggle->>Snaggle: Validate options (copy, inplace, etc)
    Snaggle->>FileSystem: Copy directory contents to destination
    Snaggle->>CLI: Return result/output
Loading

ER diagram for expected files in copy mode test cases

erDiagram
    TESTCASE {
        string Src
        string Dest
        string[] ExpectedStdout
        string ExpectedFiles
        string Options
        string Flags
    }
    TESTDETAILS {
        string Path
        bool InSubdir
    }
    TESTCASE ||--o{ TESTDETAILS : contains
    TESTCASE ||--|{ ExpectedFiles : maps
    TESTCASE ||--|{ Options : uses
    TESTCASE ||--|{ Flags : uses
Loading

Class diagram for updated options and Option functions in Snaggle

classDiagram
    class options {
        +bool copy
        +bool inplace
        +bool recursive
        +bool verbose
    }
    class Option {
        <<function>>
    }
    Option <|.. Copy
    Option <|.. InPlace
    Option <|.. Recursive
    Option <|.. Verbose
    Copy : +func Copy() Option
    InPlace : +func InPlace() Option
    Recursive : +func Recursive() Option
    Verbose : +func Verbose() Option
Loading

Class diagram for new error handling in copy mode

classDiagram
    class InvocationError {
        +string Path
        +string Target
        +error err
        +func Error() string
    }
    class ErrCopyInplace {
        <<variable>>
    }
    InvocationError --|> error
    InvocationError : +Error() string
    ErrCopyInplace : errors.New("cannot copy in-place")
Loading

File-Level Changes

Change Details Files
Implement copy option in Snaggle core
  • add copy field to the options struct and implement the Copy() Option
  • define ErrCopyInplace and return it on conflicting copy+in-place invocations
  • modify ELF error handling to bypass format errors when copying
  • insert logic in snaggle() to copy files into the destination rather than linking
snaggle.go
Expose copy flag in CLI
  • introduce --copy boolean flag and bind it in the root command
  • append the Copy() option in RunE when the flag is set
  • update help templates and README to document the new flag
cmd/snaggle/main.go
README.md
Add unit and integration tests for copy functionality
  • extend TestCases in the test iterator to cover directory copy in various modes (recursive, relative, verbose)
  • add TestCopyInplace in cli_test.go to verify proper error and exit code on copy+in-place
  • add TestCopyInplace in snaggle_test.go to assert InvocationError details and empty output
internal/testing/testiterator.go
cmd/snaggle/cli_test.go
snaggle_test.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • The new directory‐copy tests in TestCases are deeply nested and verbose—consider extracting them into a separate, table-driven helper to reduce duplication and improve readability.
  • You’re shadowing the built-in copy identifier with a package-level copy flag—rename it (e.g. copyFlag) to avoid confusion.
  • Move the mutual-exclusion check for --copy and --in-place up into the CLI’s RunE so users get immediate feedback before any core logic runs.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new directory‐copy tests in TestCases are deeply nested and verbose—consider extracting them into a separate, table-driven helper to reduce duplication and improve readability.
- You’re shadowing the built-in `copy` identifier with a package-level `copy` flag—rename it (e.g. `copyFlag`) to avoid confusion.
- Move the mutual-exclusion check for `--copy` and `--in-place` up into the CLI’s RunE so users get immediate feedback before any core logic runs.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov

codecov Bot commented Nov 7, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.93939% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.17%. Comparing base (715ad37) to head (561c9f8).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/snaggle/main.go 33.33% 2 Missing ⚠️
internal/testing/testiterator.go 97.50% 1 Missing and 1 partial ⚠️
snaggle.go 87.50% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #103      +/-   ##
==========================================
+ Coverage   74.93%   77.17%   +2.24%     
==========================================
  Files          12       12              
  Lines         730      828      +98     
==========================================
+ Hits          547      639      +92     
- Misses        125      130       +5     
- Partials       58       59       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MusicalNinjaDad MusicalNinjaDad merged commit 4f2ce43 into main Nov 7, 2025
18 checks passed
@MusicalNinjaDad MusicalNinjaDad deleted the copy branch November 7, 2025 15:23
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.

1 participant