From e44f196236302ebd257b6812f4463450871b11f6 Mon Sep 17 00:00:00 2001 From: kayomn Date: Fri, 2 Dec 2022 01:24:13 +0000 Subject: [PATCH] Initial commit --- .gitignore | 1 + go.mod | 3 + main.go | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 .gitignore create mode 100644 go.mod create mode 100644 main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..edc2462 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +modman diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..d3470a9 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module modman + +go 1.19 diff --git a/main.go b/main.go new file mode 100644 index 0000000..1f3b133 --- /dev/null +++ b/main.go @@ -0,0 +1,160 @@ +package main + +import ( + "archive/zip" + "fmt" + "os" + "strings" +) + +type Command struct { + Name string + Description string + Action func([]string) Result + Arguments []string + IsVarargs bool +} + +func Failed(message string) Result { + return Result{ + HasFailed: true, + Message: message, + } +} + +func Ok(message string) Result { + return Result{ + HasFailed: false, + Message: message, + } +} + +type Result struct { + Message string + HasFailed bool +} + +var commands = []Command{ + { + Name: "install", + Description: "Install one or more mod archives into modman", + Arguments: []string{"archive path"}, + IsVarargs: true, + + Action: func(arguments []string) Result { + var processed = 0 + + for i := range arguments { + var archivePath = arguments[i] + + if strings.HasSuffix(archivePath, ".zip") { + var reader, err = zip.OpenReader(archivePath) + + if err == nil { + defer reader.Close() + + processed += 1 + } + + continue + } + } + + return Ok(fmt.Sprint(processed, "of", len(arguments), "installed")) + }, + }, + + { + Name: "remove", + Description: "Remove one or more mods from modman", + Arguments: []string{"mod name"}, + IsVarargs: true, + + Action: func(arguments []string) Result { + // TODO: Implement. + return Failed("Not implemented") + }, + }, + + { + Name: "rename", + Description: "Rename a mod within modman", + Arguments: []string{"mod name", "new name"}, + IsVarargs: false, + + Action: func(arguments []string) Result { + // TODO: Implement. + return Failed("Not implemented") + }, + }, + + { + Name: "list", + Description: "List all installed mods", + Arguments: []string{}, + IsVarargs: false, + + Action: func(arguments []string) Result { + // TODO: Implement. + return Failed("Not implemented") + }, + }, + + { + Name: "deploy", + Description: "Deploy all installed and enabled mods", + Arguments: []string{}, + IsVarargs: false, + + Action: func(arguments []string) Result { + // TODO: Implement. + return Failed("Not implemented") + }, + }, +} + +func main() { + var argCount = len(os.Args) + + if argCount == 1 { + fmt.Println("Modman v0.1") + fmt.Println("Enter one of the following commands following modman:") + + for i := range commands { + var command = commands[i] + + fmt.Print("\t", command.Name) + + for j := range command.Arguments { + fmt.Print(" [", command.Arguments[j], "]") + } + + if command.IsVarargs { + fmt.Println("...") + } else { + fmt.Println() + } + } + + return + } + + var commandName = os.Args[1] + + for i := range commands { + var command = commands[i] + + if command.Name == commandName { + var result = command.Action(os.Args[2:]) + + if result.HasFailed { + fmt.Fprint(os.Stderr, result.Message) + os.Exit(1) + } + + fmt.Print(result.Message) + + return + } + } +}