Initial command system

This commit is contained in:
comp500
2019-03-17 15:04:00 +00:00
parent 63df728f42
commit a531e36713
9 changed files with 170 additions and 0 deletions

6
core/commands.go Normal file
View File

@@ -0,0 +1,6 @@
package core
import "github.com/urfave/cli"
// Commands stores all the commands that packwiz can run. Append to this slice to add your own commands.
var Commands []cli.Command

33
core/flags.go Normal file
View File

@@ -0,0 +1,33 @@
package core
import (
"github.com/urfave/cli"
)
// Flags stores common information passed as flags to the program.
type Flags struct {
PackFile string
ModsFolder string
}
// FlagsFromContext converts a CLI context (from commands) into a Flags struct, for use in helper functions.
func FlagsFromContext(c *cli.Context) Flags {
return Flags{
c.GlobalString("pack-file"),
c.GlobalString("mods-folder"),
}
}
// CLIFlags is used internally to initialise the internal flags (easier to keep in one place)
var CLIFlags = [...]cli.Flag{
cli.StringFlag{
Name: "pack-file",
Value: "pack.toml",
Usage: "The modpack metadata file to use",
},
cli.StringFlag{
Name: "mods-folder",
Value: "mods",
Usage: "The mods folder to use",
},
}

1
core/index.go Normal file
View File

@@ -0,0 +1 @@
package core

29
core/mod.go Normal file
View File

@@ -0,0 +1,29 @@
package core
import "github.com/BurntSushi/toml"
// Mod stores metadata about a mod. This is written to a TOML file for each mod.
type Mod struct {
metaFilename string
Name string `toml:"name"`
FileName string `toml:"filename"`
Side string `toml:"side"`
Optional bool `toml:"optional"`
Download struct {
URL string `toml:"url"`
HashFormat string `toml:"hash-format"`
Hash string `toml:"hash"`
} `toml:"download"`
Update map[string]toml.Primitive
}
// The three possible values of Side (the side that the mod is on) are "server", "client", and "both".
const (
ServerSide = "server"
ClientSide = "client"
UniversalSide = "both"
)
func (m Mod) Write() {
}

15
core/resolve.go Normal file
View File

@@ -0,0 +1,15 @@
package core
import (
"path/filepath"
"strings"
)
// ModExtension is the file extension of the mod metadata files
const ModExtension = ".toml"
// ResolveMod returns the path to a mod file from it's name
func ResolveMod(modName string, flags Flags) string {
fileName := strings.ToLower(strings.TrimSuffix(modName, ModExtension)) + ModExtension
return filepath.Join(flags.ModsFolder, fileName)
}