Initial commit

This commit is contained in:
kayomn 2022-12-02 01:24:13 +00:00
commit e44f196236
3 changed files with 164 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
modman

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module modman
go 1.19

160
main.go Normal file
View File

@ -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
}
}
}