fix: parse -o flag correctly to resolve output filename
Fix bug where -o flag value was read as pointer instead of string value, causing memory addresses to be printed and output path to resolve to ".xlsx".
This commit is contained in:
parent
f1b44efca9
commit
37ad950241
3 changed files with 191 additions and 10 deletions
22
main.go
22
main.go
|
|
@ -26,10 +26,13 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Println(sep)
|
||||
fmt.Println(enc)
|
||||
fmt.Println(out)
|
||||
if err := run(files, *out, *sep, *enc); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run(files []string, out, sep, enc string) error {
|
||||
xlsx := excelize.NewFile()
|
||||
firstSheet := true
|
||||
|
||||
|
|
@ -49,11 +52,11 @@ func main() {
|
|||
defer f.Close()
|
||||
|
||||
var reader io.Reader = f
|
||||
if *enc == "windows1252" {
|
||||
if enc == "windows1252" {
|
||||
reader = transform.NewReader(f, charmap.Windows1252.NewDecoder())
|
||||
}
|
||||
|
||||
delimiter := detectDelimiter(path, *sep)
|
||||
delimiter := detectDelimiter(path, sep)
|
||||
|
||||
csvReader := csv.NewReader(reader)
|
||||
csvReader.Comma = delimiter
|
||||
|
|
@ -85,12 +88,11 @@ func main() {
|
|||
fmt.Printf("✓ %s → Reiter \"%s\" (%d Zeilen)\n", path, sheetName, row-1)
|
||||
}
|
||||
|
||||
if err := xlsx.SaveAs(*out); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Fehler beim Speichern: %v\n", err)
|
||||
os.Exit(1)
|
||||
if err := xlsx.SaveAs(out); err != nil {
|
||||
return fmt.Errorf("Fehler beim Speichern: %w", err)
|
||||
}
|
||||
fmt.Printf("✅ Gespeichert: %s\n", *out)
|
||||
|
||||
fmt.Printf("✅ Gespeichert: %s\n", out)
|
||||
return nil
|
||||
}
|
||||
|
||||
func detectDelimiter(path, hint string) rune {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue