package main import ( "eternity/common" "eternity/lib" "fmt" "os" "os/signal" "path/filepath" ) func main() { if len(os.Args) < 2 { fmt.Println("Usage: eternity ") os.Exit(1) } logger := &common.DefaultLogger for i, arg := range os.Args { if arg == "--help" || arg == "-h" || (i != 1 && arg == "help") { logger.LogFunc(lib.Log{ Level: "FATAL", Content: "To ask for help, use 'eternity help , not --help, -h, or eternity help.", }) } } switch os.Args[1] { case "build": inMemory := true if len(os.Args) > 2 { if os.Args[2] == "-d" || os.Args[2] == "--disk" { inMemory = false } } privateKey, err, vagueError := common.LoadPrivateKey(logger) if err != nil || vagueError != nil { common.LoadPrivateKeyHandleError(err, vagueError, logger) } config, err, vagueError := lib.ParseConfig("eternity.json", logger) if err != nil || vagueError != nil { common.EternityJsonHandleError(err, vagueError, logger) } else { var tempDir string c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt) go func() { for sig := range c { fmt.Println("\nCaught", sig, "signal, exiting...") if tempDir != "" { common.BuildEPKRemoveTemporaryDirectory(tempDir, logger) } os.Exit(1) } }() tempDir, err, vagueError = lib.BuildEPK("./", inMemory, config.Build, logger) if err != nil || vagueError != nil { common.BuildEPKHandleError(tempDir, err, vagueError, logger) } else { filePath := filepath.Join("./", config.Metadata.Name+"-"+config.Metadata.Version.String()) err, vagueError := lib.PackageEPK(config.Metadata, config.Build, tempDir, filePath+".epk", privateKey, logger) if err != nil || vagueError != nil { common.PackageEPKHandleError(err, vagueError, logger) } else { common.BuildEPKRemoveTemporaryDirectory(tempDir, logger) logger.LogFunc(lib.Log{ Level: "INFO", Content: "Successfully built and packaged EPK at " + filePath + ".epk", }) } } } case "help": if len(os.Args) > 2 { switch os.Args[2] { case "build": fmt.Println("Usage: eternity build [-d/--disk]") fmt.Println(" -d, --disk Build EPK on disk instead of in memory. This is useful for large EPKs.") case "convert": fmt.Println("Usage: eternity convert []") case "repo": fmt.Println("Usage: eternity repo ") fmt.Println(" build Build a repository from a directory containing EPK project directories.") fmt.Println(" generate Generate a repository from a directory containing EPKs.") case "package": fmt.Println("Usage: eternity package ") default: fmt.Println("Usage: eternity help ") } } else { fmt.Println("Usage: eternity help ") } } }