mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-19 13:06:30 +02:00
Initial command system
This commit is contained in:
parent
63df728f42
commit
a531e36713
6
core/commands.go
Normal file
6
core/commands.go
Normal 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
33
core/flags.go
Normal 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
1
core/index.go
Normal file
@ -0,0 +1 @@
|
||||
package core
|
29
core/mod.go
Normal file
29
core/mod.go
Normal 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
15
core/resolve.go
Normal 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)
|
||||
}
|
||||
|
19
curseforge/curseforge.go
Normal file
19
curseforge/curseforge.go
Normal file
@ -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
|
||||
},
|
||||
})
|
||||
}
|
6
go.mod
Normal file
6
go.mod
Normal file
@ -0,0 +1,6 @@
|
||||
module github.com/comp500/packwiz
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v0.3.1
|
||||
github.com/urfave/cli v1.20.0
|
||||
)
|
4
go.sum
Normal file
4
go.sum
Normal file
@ -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=
|
57
main.go
Normal file
57
main.go
Normal file
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user