Add --verbose and default to silent#98
Conversation
Reviewer's GuideThis 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 --verbosesequenceDiagram
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
Class diagram for updated options and Option functionsclassDiagram
class options {
bool inplace
bool recursive
bool verbose
}
class Option {
<<function>>
}
options <|-- Option
Option : InPlace()
Option : Recursive()
Option : Verbose()
Class diagram for CLI flag additionsclassDiagram
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()
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
|
@sourcery-ai review |
There was a problem hiding this comment.
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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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:
Enhancements:
Documentation:
Tests: