From bcaf1554f8df4008793046da312c8bb03dc7d15b Mon Sep 17 00:00:00 2001 From: Snider Date: Wed, 18 Mar 2026 02:40:00 +0000 Subject: [PATCH] fix: resolve 3 critical review findings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit C1: mnt_extract.go rename bug — source path was mutated before reading from fs.FS. Now uses separate sourcePath/targetPath. C2: cli_command.go os.Stderr = nil — replaced with flags.SetOutput(io.Discard). No more global nil stderr. C3: Cli() returned nil — now initialised in New() with NewCliApp("", "", ""). Found by opus code-reviewer agent (final review pass). Co-Authored-By: Virgil --- pkg/core/cli_command.go | 9 ++++----- pkg/core/core.go | 1 + pkg/core/mnt_extract.go | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/core/cli_command.go b/pkg/core/cli_command.go index b50b0e0..eeee533 100644 --- a/pkg/core/cli_command.go +++ b/pkg/core/cli_command.go @@ -3,6 +3,7 @@ package core import ( "errors" "flag" + "io" "fmt" "os" "reflect" @@ -75,11 +76,9 @@ func (c *Command) setApp(app *CliApp) { // parseFlags parses the given flags func (c *Command) parseFlags(args []string) error { // Parse flags - tmp := os.Stderr - os.Stderr = nil - defer func() { - os.Stderr = tmp - }() + // Suppress flag parse errors to stderr + + c.flags.SetOutput(io.Discard) // Credit: https://stackoverflow.com/a/74146375 var positionalArgs []string diff --git a/pkg/core/core.go b/pkg/core/core.go index 3c5c181..ae2abca 100644 --- a/pkg/core/core.go +++ b/pkg/core/core.go @@ -33,6 +33,7 @@ func New(opts ...Option) (*Core, error) { io: defaultIO, etc: NewEtc(), crash: NewCrashHandler(), + cli: NewCliApp("", "", ""), svc: newServiceManager(), } c.bus = newMessageBus(c) diff --git a/pkg/core/mnt_extract.go b/pkg/core/mnt_extract.go index 21188e3..e882bb4 100644 --- a/pkg/core/mnt_extract.go +++ b/pkg/core/mnt_extract.go @@ -135,11 +135,12 @@ func Extract(fsys fs.FS, targetDir string, data any, opts ...ExtractOptions) err // Copy standard files for _, path := range standardFiles { + targetPath := path name := filepath.Base(path) if renamed := opt.RenameFiles[name]; renamed != "" { - path = filepath.Join(filepath.Dir(path), renamed) + targetPath = filepath.Join(filepath.Dir(path), renamed) } - target := renderPath(filepath.Join(targetDir, path), data) + target := renderPath(filepath.Join(targetDir, targetPath), data) if err := copyFile(fsys, path, target); err != nil { return err }