From 546825523512f20b0accbcd592dcb193917b6e22 Mon Sep 17 00:00:00 2001 From: Emma Alyx Wunder Date: Thu, 11 May 2023 21:45:56 +0200 Subject: [PATCH] Replaced opts.InputFiles array with opts.InputFile string option --- gbs/makegb.go | 4 +--- main.go | 33 ++++++++++++++------------------- opts.go | 6 +++--- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/gbs/makegb.go b/gbs/makegb.go index ed315aa..3f8f7a0 100644 --- a/gbs/makegb.go +++ b/gbs/makegb.go @@ -234,12 +234,10 @@ func MakeGB(gbsBytes []byte, outFile string) error { binary.BigEndian.PutUint16(gcs, globalChecksum(gbBytes)) copy(gbBytes[0x14E:0x150], gcs) - written, err := utils.WriteAllBytes(outFile, gbBytes) + _, err = utils.WriteAllBytes(outFile, gbBytes) if err != nil { return err } - log.Printf("gbBytes written to file: %d/%d", written, romSizeBytes) - return nil } diff --git a/main.go b/main.go index 02a9798..d15f381 100644 --- a/main.go +++ b/main.go @@ -35,28 +35,23 @@ func main() { log.Fatalf("Can't create output directory: %v", err) } - for i, inputFile := range opts.InputFiles { - if i > 0 { - log.Println("################") - } - - _, inputBase := path.Split(inputFile) - inputNoext := strings.TrimSuffix(inputBase, path.Ext(inputBase)) - outputFile := path.Join(opts.OutDir, fmt.Sprintf("%s.gb", inputNoext)) + _, inputBase := path.Split(opts.InputFile) + inputNoext := strings.TrimSuffix(inputBase, path.Ext(inputBase)) + outputFile := path.Join(opts.OutDir, fmt.Sprintf("%s.gb", inputNoext)) - log.Println(inputBase) + log.Printf("→ %s", inputBase) - gbsBytes, err := utils.ReadAllBytes(inputFile) - if err != nil { - log.Println(err) - continue - } + gbsBytes, err := utils.ReadAllBytes(opts.InputFile) + if err != nil { + log.Println(err) + return + } - err = gbs.MakeGB(gbsBytes, outputFile) - if err != nil { - log.Printf("Couldn't create GB file:") - log.Println(err) - } + err = gbs.MakeGB(gbsBytes, outputFile) + if err != nil { + log.Printf("Couldn't create GB file:") + log.Println(err) } + log.Printf("Successfully created %s", outputFile) } diff --git a/opts.go b/opts.go index 4c626c1..617da94 100644 --- a/opts.go +++ b/opts.go @@ -1,7 +1,7 @@ package main type CommandLineOpts struct { - InputFiles []string `short:"i" long:"input" description:"Input GBS files"` - OutDir string `short:"o" long:"outdir" description:"Output directory" default:"./"` - Version bool `short:"v" long:"version" description:"Show version and exit"` + InputFile string `short:"i" long:"input" description:"Input GBS file"` + OutDir string `short:"o" long:"outdir" description:"Output directory" default:"./"` + Version bool `short:"v" long:"version" description:"Show version and exit"` }