fix: resolve 3 critical review findings
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 <virgil@lethean.io>
This commit is contained in:
parent
3b3b042509
commit
bcaf1554f8
3 changed files with 8 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ func New(opts ...Option) (*Core, error) {
|
|||
io: defaultIO,
|
||||
etc: NewEtc(),
|
||||
crash: NewCrashHandler(),
|
||||
cli: NewCliApp("", "", ""),
|
||||
svc: newServiceManager(),
|
||||
}
|
||||
c.bus = newMessageBus(c)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue