diff --git a/core/commands.go b/core/commands.go new file mode 100644 index 0000000..b00fb8b --- /dev/null +++ b/core/commands.go @@ -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 + diff --git a/core/flags.go b/core/flags.go new file mode 100644 index 0000000..2d00953 --- /dev/null +++ b/core/flags.go @@ -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", + }, +} + diff --git a/core/index.go b/core/index.go new file mode 100644 index 0000000..9a8bc95 --- /dev/null +++ b/core/index.go @@ -0,0 +1 @@ +package core diff --git a/core/mod.go b/core/mod.go new file mode 100644 index 0000000..90e9dd5 --- /dev/null +++ b/core/mod.go @@ -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() { + +} + diff --git a/core/resolve.go b/core/resolve.go new file mode 100644 index 0000000..745edf6 --- /dev/null +++ b/core/resolve.go @@ -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) +} + diff --git a/curseforge/curseforge.go b/curseforge/curseforge.go new file mode 100644 index 0000000..698adf5 --- /dev/null +++ b/curseforge/curseforge.go @@ -0,0 +1,19 @@ +package curseforge + +import ( + "fmt" + + "github.com/comp500/packwiz/core" + "github.com/urfave/cli" +) + +func init() { + core.Commands = append(core.Commands, cli.Command{ + Name: "curseforge", + Usage: "Manage curseforge-based mods", + Action: func(c *cli.Context) error { + fmt.Println("Not implemented yet!") + return nil + }, + }) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..841b11d --- /dev/null +++ b/go.mod @@ -0,0 +1,6 @@ +module github.com/comp500/packwiz + +require ( + github.com/BurntSushi/toml v0.3.1 + github.com/urfave/cli v1.20.0 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..ca07569 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw= +github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= diff --git a/main.go b/main.go new file mode 100644 index 0000000..d63be0f --- /dev/null +++ b/main.go @@ -0,0 +1,57 @@ +package main +import ( + "fmt" + "log" + "os" + + "github.com/comp500/packwiz/core" + "github.com/urfave/cli" + + // Modules of packwiz + _ "github.com/comp500/packwiz/curseforge" +) + +func init() { + core.Commands = append(core.Commands, cli.Command{ + Name: "delete", + Aliases: []string{"remove"}, + Usage: "Delete a mod from the modpack", + Action: func(c *cli.Context) error { + cmdDelete(core.FlagsFromContext(c)) + return nil + }, + }, cli.Command{ + Name: "delet", + Aliases: []string{"remov"}, + Usage: "Delete a mod from the modpack", + Action: func(c *cli.Context) error { + cmdDelete(core.FlagsFromContext(c)) + return nil + }, + }) +} + +func main() { + app := cli.NewApp() + app.Commands = core.Commands + app.Flags = core.CLIFlags[:] + app.HideVersion = true + app.Usage = "A command line tool for creating Minecraft modpacks." + + err := app.Run(os.Args) + if err != nil { + log.Fatal(err) + } +} + +func cmdDelete(flags core.Flags) { + mod := "demagnetize" + err := os.Remove(core.ResolveMod(mod, flags)) + if err != nil { + fmt.Printf("Error removing mod: %s", err) + } else { + fmt.Printf("Mod %s removed successfully!", mod) + } + // TODO: update index +} +