From 6f14cd7c0654efc524c6c850f676f99546619d66 Mon Sep 17 00:00:00 2001 From: Zorchenhimer Date: Thu, 18 Dec 2025 21:38:02 -0500 Subject: [PATCH] [fdsextract] Add --output option Currently only available when extracting single files. Will use the given filename as the output name instead of constructing one. TODO: Make this value a template that can be used with multiple files. --- cmd/fdsextract.go | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/cmd/fdsextract.go b/cmd/fdsextract.go index fdc32b8..b3b8af0 100644 --- a/cmd/fdsextract.go +++ b/cmd/fdsextract.go @@ -20,6 +20,8 @@ type Arguments struct { FileNum int `arg:"--file-num" default:"-1"` Range string `arg:"--range"` + + Output string `arg:"--output"` } func main() { @@ -39,10 +41,19 @@ func run(args *Arguments) error { return err } - outdir := strings.TrimSuffix(args.Input, filepath.Ext(args.Input)) - err = os.MkdirAll(outdir, 0775) - if err != nil { - return err + if args.Output != "" && args.FileNum == -1 { + return fmt.Errorf("--output can only be used when exporting a single file") + } + + outdir := "./" + if args.Output == "" { + outdir = strings.TrimSuffix(args.Input, filepath.Ext(args.Input)) + } + if args.Output != "" { + err = os.MkdirAll(outdir, 0775) + if err != nil { + return err + } } if args.Side >= 0 && args.FileNum == -1 { @@ -100,7 +111,11 @@ func run(args *Arguments) error { end = file.Size } - fileName := filepath.Join(outdir, fmt.Sprintf("%03d_%s_%02d_%02X", args.FileNum, sideName, file.Number, file.Id)) + fileName := args.Output + if fileName == "" { + fileName = filepath.Join(outdir, fmt.Sprintf("%03d_%s_%02d_%02X", args.FileNum, sideName, file.Number, file.Id)) + } + fmt.Println("fileName:", fileName) err := os.WriteFile(fileName, file.Data[start:end], 0664) if err != nil {