Skip to content

Add --verbose and default to silent#98

Merged
MusicalNinjaDad merged 10 commits into
mainfrom
verbose
Nov 6, 2025
Merged

Add --verbose and default to silent#98
MusicalNinjaDad merged 10 commits into
mainfrom
verbose

Conversation

@MusicalNinjaDad

@MusicalNinjaDad MusicalNinjaDad commented Nov 6, 2025

Copy link
Copy Markdown
Owner

Summary by Sourcery

Introduce a new verbose mode for snaggle while defaulting to silent, parallel processing; add a version flag; update tests, benchmarks, and documentation to cover both modes

New Features:

  • Add -v/--verbose option for stdout output and sequential processing
  • Add --version flag to display the current snaggle version

Enhancements:

  • Silence logs by default and run snaggling in parallel when verbose is off
  • Set concurrency limits to 1 when verbose to enforce sequential file processing
  • Reorder and deduplicate internal defaultTests in alphabetical order

Documentation:

  • Update README and command help to document --verbose and --version flags and clarify behavior differences

Tests:

  • Expand benchmark suite to include verbose benchmarks and refresh results

@sourcery-ai

sourcery-ai Bot commented Nov 6, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR introduces a new --verbose mode and makes silent the default, wiring verbose into both the CLI and core library to control logging and concurrency, expands tests and benchmarks to cover verbose and silent runs, and refreshes documentation accordingly.

Sequence diagram for CLI option handling with --verbose

sequenceDiagram
    actor User
    participant CLI
    participant Library
    participant Logger
    User->>CLI: Run snaggle with/without --verbose
    CLI->>Library: Pass options (inplace, recursive, verbose)
    Library->>Logger: Set logging (stdout if verbose, discard if silent)
    Library->>Library: Set concurrency (sequential if verbose, parallel if silent)
    Library->>CLI: Return result
    CLI->>User: Show output (if verbose) or silent
Loading

Class diagram for updated options and Option functions

classDiagram
    class options {
        bool inplace
        bool recursive
        bool verbose
    }
    class Option {
        <<function>>
    }
    options <|-- Option
    Option : InPlace()
    Option : Recursive()
    Option : Verbose()
Loading

Class diagram for CLI flag additions

classDiagram
    class rootCmd {
        string Version
        string HelpTemplate
        Flags: inplace, recursive, verbose, version
        SetHelpTemplate()
        InitDefaultHelpFlag()
        InitDefaultVersionFlag()
    }
    rootCmd : BoolVar(&inplace, "in-place", ...)
    rootCmd : BoolVarP(&recursive, "recursive", ...)
    rootCmd : BoolVarP(&verbose, "verbose", ...)
    rootCmd : InitDefaultVersionFlag()
Loading

File-Level Changes

Change Details Files
CLI and documentation updated to expose verbose and version flags and describe new default behavior
  • Expose --verbose (-v) and --version flags in cmd/snaggle/main.go
  • Augment help templates and notes to explain verbose vs silent execution
  • Update README.md to document new flags and behavior
cmd/snaggle/main.go
README.md
Core Snaggle function wired to honor verbose option for logging and execution mode
  • Introduce verbose field in options struct and Verbose() option setter
  • Discard log output by default and restore output when verbose is enabled
  • Call errgroup.SetLimit(1) under verbose to force sequential processing
snaggle.go
Testing framework extended to run both verbose and silent permutations and enforce strict ordering
  • Insert verbose flag loops and suffixes in TestCases in internal/testing/testiterator.go
  • Append --verbose option and adjust ExpectedStdout setup for silent runs
  • Tighten assertions in internal/testing/assertions.go to use strict equality
internal/testing/testiterator.go
internal/testing/assertions.go
Benchmarks expanded to compare verbose vs silent performance and results updated
  • Loop over verbose=true/false in BenchmarkCommonBinaries in snaggle_test.go
  • Adjust benchmark temp directory setup and option injection
  • Refresh results in benchmarks.md to include verbose entries
snaggle_test.go
benchmarks.md

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

@codecov

codecov Bot commented Nov 6, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.15686% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.03%. Comparing base (3a99d54) to head (df36190).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/testing/testiterator.go 95.29% 2 Missing and 2 partials ⚠️
cmd/snaggle/main.go 50.00% 2 Missing ⚠️
internal/testing/assertions.go 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #98      +/-   ##
==========================================
+ Coverage   74.42%   75.03%   +0.60%     
==========================================
  Files          12       12              
  Lines         696      729      +33     
==========================================
+ Hits          518      547      +29     
- Misses        122      125       +3     
- Partials       56       57       +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

Copy link
Copy Markdown
Owner Author

@sourcery-ai review

@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 and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `internal/testing/testiterator.go:115` </location>
<code_context>
 	return func(testbody func(t *testing.T, tc TestCase) bool) {
 		for _, relative := range []bool{false, true} {
 			for _, inplace := range []bool{false, true} {
-				for _, bin := range tests {
</code_context>

<issue_to_address>
**issue (complexity):** Consider refactoring the nested test loops into a flat list of configuration structs and helper functions to simplify control flow and reduce duplication.

```markdown
You can collapse the four‐deep loops into a flat list of “configs” and then drive both your file-tests and dir-tests from that.  That eliminates most of the nesting and duplicates.  For example:

```go
type config struct {
  nameSuffix string
  opts       []snaggle.Option
  flags      []string
}

// build all combinations up front
func makeConfigs() []config {
  var out []config
  for _, relative := range []bool{false, true} {
    for _, inplace := range []bool{false, true} {
      for _, verbose := range []bool{false, true} {
        desc := ""
        flags := []string{}
        opts  := []snaggle.Option{}
        if relative   { desc += "_relative" }
        if inplace    { desc += "_inplace";  flags = append(flags, "--in-place"); opts = append(opts, snaggle.InPlace()) }
        if verbose    { desc += "_verbose";  flags = append(flags, "--verbose"); opts = append(opts, snaggle.Verbose()) }
        if !verbose    { desc += "_silent" }
        out = append(out, config{desc, opts, flags})
      }
    }
  }
  return out
}
```

Now replace your nested loops with:

```go
for _, cfg := range makeConfigs() {
  t.Run(cfg.nameSuffix, func(t *testing.T) {
    runFileTests(t, cfg, tests)
    if !specificTestsRequested {
      runDirTests (t, cfg, defaultTests)
    }
  })
}
```

And push the body of what was in each inner loop into two helpers:

```go
func runFileTests(t *testing.T, cfg config, tests []TestDetails) {
  for _, bin := range tests {
    tc := makeBaseTC(bin.Path, len(bin.Bin.Elf.Dependencies), cfg)
    generateOutput(bin, &tc, strings.Contains(cfg.nameSuffix, "_inplace"))
    maybeRelativize(&tc, strings.Contains(cfg.nameSuffix, "_relative"))
    if !strings.Contains(cfg.nameSuffix, "_verbose") {
      tc.ExpectedStdout = nil
    }
    testbody(t, tc)
  }
}

func runDirTests(t *testing.T, cfg config, defaults []TestDetails) {
  bins := pickBins(defaults, strings.Contains(cfg.nameSuffix, "_recursive"))
  tc := makeBaseTC(TestdataPath("."), 0, cfg)
  for _, bin := range bins {
    generateOutput(bin, &tc, strings.Contains(cfg.nameSuffix, "_inplace"))
  }
  maybeRelativize(&tc, strings.Contains(cfg.nameSuffix, "_relative"))
  if !strings.Contains(cfg.nameSuffix, "_verbose") {
    tc.ExpectedStdout = nil
  }
  testbody(t, tc)
}
```

You’d also factor out helpers like `makeBaseTC(...)`, `maybeRelativize(...)` and `pickBins(...)`.  This preserves exactly the same behavior but flattens the control flow and removes ~50 lines of duplicated plumbing.
</issue_to_address>

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.

@MusicalNinjaDad MusicalNinjaDad linked an issue Nov 6, 2025 that may be closed by this pull request
3 tasks

@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 deeply nested loops and repeated test setup in TestCases (internal/testing/testiterator.go) could be refactored into a more concise table-driven structure or helper functions to reduce duplication and improve readability.
  • Flag definitions and help text for --verbose/--version are duplicated between main.go, README.md, and benchmarks.md—consider centralizing them or extracting shared templates to ease future updates.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The deeply nested loops and repeated test setup in TestCases (internal/testing/testiterator.go) could be refactored into a more concise table-driven structure or helper functions to reduce duplication and improve readability.
- Flag definitions and help text for --verbose/--version are duplicated between main.go, README.md, and benchmarks.md—consider centralizing them or extracting shared templates to ease future updates.

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.

@MusicalNinjaDad MusicalNinjaDad merged commit e2c7cce into main Nov 6, 2025
18 checks passed
@MusicalNinjaDad MusicalNinjaDad deleted the verbose branch November 6, 2025 16: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.

add verbosity flag -v

1 participant