From b64650e11499b5899e13a5c870e48dc11df5c0bf Mon Sep 17 00:00:00 2001 From: ofluffydev Date: Mon, 28 Oct 2024 09:14:05 -0500 Subject: [PATCH] added -o flag to specify output for package --- cmd/main.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/cmd/main.go b/cmd/main.go index a092fcb..a1cd6db 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "regexp" + "strings" "git.oreonproject.org/oreonproject/eternity/common" "git.oreonproject.org/oreonproject/eternity/lib" @@ -40,6 +41,31 @@ func main() { } } + // Allow the user to choose an output dir + var outputDir = "./" // Default output directory + + // Loop through arguments to find "-o" or "--output" + for i := 2; i < len(os.Args); i++ { + if os.Args[i] == "-o" || os.Args[i] == "--output" { + // Check if next argument exists and is not another flag + if i+1 < len(os.Args) && !strings.HasPrefix(os.Args[i+1], "-") { + outputDir = os.Args[i+1] + if !filepath.IsAbs(outputDir) { + outputDir, _ = filepath.Abs(outputDir) // Convert to absolute path if relative + } + break + } else { + fmt.Println("FATAL: Output directory not specified or invalid after", os.Args[i]) + os.Exit(1) + } + } + } + + logger.LogFunc(lib.Log{ + Level: "INFO", + Content: "Build directory set to: " + outputDir, + }) + privateKey, err, vagueError := common.LoadPrivateKey(logger) if err != nil || vagueError != nil { common.LoadPrivateKeyHandleError(err, vagueError, logger) @@ -66,7 +92,7 @@ func main() { if err != nil || vagueError != nil { common.BuildEPKHandleError(tempDir, err, vagueError, logger) } else { - filePath := filepath.Join("./", config.Metadata.Name+"-"+config.Metadata.Version.String()) + filePath := filepath.Join(outputDir, config.Metadata.Name+"-"+config.Metadata.Version.String()) config.Metadata.DecompressedSize = size err, vagueError := lib.PackageEPK(config.Metadata, config.Build, tempDir, filePath+".epk", privateKey, logger) if err != nil || vagueError != nil {