fix: make -o flag robust against PowerShell argument splitting

PowerShell splits `-o=file.xlsx` into `-o=file` + `.xlsx` as separate
args. Fix: auto-append .xlsx if output has no extension, and filter
out .xlsx files from input args with a helpful warning.
This commit is contained in:
Oliver Jakoubek 2026-03-05 12:05:12 +01:00
commit 88aa81ff46

21
main.go
View file

@ -28,9 +28,15 @@ func main() {
os.Exit(0)
}
// PowerShell kann "-o=testdatei.xlsx" in "-o=testdatei" + ".xlsx" splitten
if filepath.Ext(*out) == "" {
*out += ".xlsx"
}
files := flag.Args()
if len(files) == 0 {
fmt.Fprintln(os.Stderr, "Verwendung: csv2xlsx [flags] datei1.csv datei2.csv ...")
fmt.Fprintln(os.Stderr, "Verwendung: csv2excel [flags] datei1.csv datei2.csv ...")
fmt.Fprintln(os.Stderr, "Tipp: In PowerShell Leerzeichen statt = verwenden: -o ausgabe.xlsx")
os.Exit(1)
}
@ -44,6 +50,19 @@ func run(files []string, out, sep, enc string) error {
xlsx := excelize.NewFile()
firstSheet := true
var csvFiles []string
for _, f := range files {
if strings.EqualFold(filepath.Ext(f), ".xlsx") {
fmt.Fprintf(os.Stderr, "Warnung: %s übersprungen Excel-Datei als Input? Meintest du: -o=%s\n", f, f)
continue
}
csvFiles = append(csvFiles, f)
}
files = csvFiles
if len(files) == 0 {
return fmt.Errorf("keine CSV-Dateien zum Verarbeiten")
}
for _, path := range files {
sheetName := strings.TrimSuffix(filepath.Base(path), filepath.Ext(path))