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:
parent
ad8f7937b1
commit
88aa81ff46
1 changed files with 20 additions and 1 deletions
21
main.go
21
main.go
|
|
@ -28,9 +28,15 @@ func main() {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PowerShell kann "-o=testdatei.xlsx" in "-o=testdatei" + ".xlsx" splitten
|
||||||
|
if filepath.Ext(*out) == "" {
|
||||||
|
*out += ".xlsx"
|
||||||
|
}
|
||||||
|
|
||||||
files := flag.Args()
|
files := flag.Args()
|
||||||
if len(files) == 0 {
|
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)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,6 +50,19 @@ func run(files []string, out, sep, enc string) error {
|
||||||
xlsx := excelize.NewFile()
|
xlsx := excelize.NewFile()
|
||||||
firstSheet := true
|
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 {
|
for _, path := range files {
|
||||||
|
|
||||||
sheetName := strings.TrimSuffix(filepath.Base(path), filepath.Ext(path))
|
sheetName := strings.TrimSuffix(filepath.Base(path), filepath.Ext(path))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue