mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-19 13:06:30 +02:00
Fix struct tagging by just using string keys
This commit is contained in:
parent
ef98591d02
commit
f23f99b5be
@ -5,7 +5,7 @@ var UpdateParsers = make(map[string]UpdateParser)
|
|||||||
// UpdateParser takes an unparsed interface{} (as a map[string]interface{}), and returns an Updater for a mod file.
|
// UpdateParser takes an unparsed interface{} (as a map[string]interface{}), and returns an Updater for a mod file.
|
||||||
// This can be done using the mapstructure library or your own parsing methods.
|
// This can be done using the mapstructure library or your own parsing methods.
|
||||||
type UpdateParser interface {
|
type UpdateParser interface {
|
||||||
ParseUpdate(interface{}) (Updater, error)
|
ParseUpdate(map[string]interface{}) (Updater, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updater checks for and does updates on a mod
|
// Updater checks for and does updates on a mod
|
||||||
|
19
core/mod.go
19
core/mod.go
@ -8,13 +8,15 @@ import (
|
|||||||
|
|
||||||
// Mod stores metadata about a mod. This is written to a TOML file for each mod.
|
// Mod stores metadata about a mod. This is written to a TOML file for each mod.
|
||||||
type Mod struct {
|
type Mod struct {
|
||||||
metaFile string // The file for the metadata file, used as an ID
|
metaFile string // The file for the metadata file, used as an ID
|
||||||
Name string `toml:"name"`
|
Name string `toml:"name"`
|
||||||
FileName string `toml:"filename"`
|
FileName string `toml:"filename"`
|
||||||
Side string `toml:"side,omitempty"`
|
Side string `toml:"side,omitempty"`
|
||||||
Optional bool `toml:"optional,omitempty"`
|
Optional bool `toml:"optional,omitempty"`
|
||||||
Download ModDownload `toml:"download"`
|
Download ModDownload `toml:"download"`
|
||||||
Update map[string]interface{} `toml:"update"`
|
// Update is a map of map of stuff, so you can store arbitrary values on string keys to define updating
|
||||||
|
Update map[string]map[string]interface{} `toml:"update"`
|
||||||
|
updaters map[string]Updater
|
||||||
}
|
}
|
||||||
|
|
||||||
// ModDownload specifies how to download the mod file
|
// ModDownload specifies how to download the mod file
|
||||||
@ -37,6 +39,7 @@ func LoadMod(modFile string) (Mod, error) {
|
|||||||
if _, err := toml.DecodeFile(modFile, &mod); err != nil {
|
if _, err := toml.DecodeFile(modFile, &mod); err != nil {
|
||||||
return Mod{}, err
|
return Mod{}, err
|
||||||
}
|
}
|
||||||
|
mod.updaters = make(map[string]Updater)
|
||||||
// Horrible reflection library to convert to Updaters
|
// Horrible reflection library to convert to Updaters
|
||||||
for k, v := range mod.Update {
|
for k, v := range mod.Update {
|
||||||
updateParser, ok := UpdateParsers[k]
|
updateParser, ok := UpdateParsers[k]
|
||||||
@ -45,7 +48,7 @@ func LoadMod(modFile string) (Mod, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return mod, err
|
return mod, err
|
||||||
}
|
}
|
||||||
mod.Update[k] = updater
|
mod.updaters[k] = updater
|
||||||
} else {
|
} else {
|
||||||
return mod, errors.New("Update plugin " + k + " not found!")
|
return mod, errors.New("Update plugin " + k + " not found!")
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
package curseforge
|
package curseforge
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -147,13 +148,16 @@ func cmdInstall(flags core.Flags, mod string, modArgsTail []string) error {
|
|||||||
|
|
||||||
fileInfo, err := getFileInfo(modID, fileID)
|
fileInfo, err := getFileInfo(modID, fileID)
|
||||||
|
|
||||||
updateMap := make(map[string]interface{})
|
updateMap := make(map[string]map[string]interface{})
|
||||||
|
|
||||||
updateMap["curseforge"] = cfUpdater{
|
updateMap["curseforge"], err = cfUpdater{
|
||||||
ProjectID: modID,
|
ProjectID: modID,
|
||||||
FileID: fileID,
|
FileID: fileID,
|
||||||
// TODO: determine update channel
|
// TODO: determine update channel
|
||||||
ReleaseChannel: "release",
|
ReleaseChannel: "release",
|
||||||
|
}.ToMap()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
modMeta := core.Mod{
|
modMeta := core.Mod{
|
||||||
@ -176,19 +180,25 @@ func cmdInstall(flags core.Flags, mod string, modArgsTail []string) error {
|
|||||||
|
|
||||||
type cfUpdateParser struct{}
|
type cfUpdateParser struct{}
|
||||||
|
|
||||||
func (u cfUpdateParser) ParseUpdate(updateUnparsed interface{}) (core.Updater, error) {
|
func (u cfUpdateParser) ParseUpdate(updateUnparsed map[string]interface{}) (core.Updater, error) {
|
||||||
var updater cfUpdater
|
var updater cfUpdater
|
||||||
err := mapstructure.Decode(updateUnparsed, &updater)
|
err := mapstructure.Decode(updateUnparsed, &updater)
|
||||||
return updater, err
|
return updater, err
|
||||||
}
|
}
|
||||||
|
|
||||||
type cfUpdater struct {
|
type cfUpdater struct {
|
||||||
ProjectID int `mapstructure:"project-id" toml:"project-id"`
|
ProjectID int `mapstructure:"project-id"`
|
||||||
FileID int `mapstructure:"file-id" toml:"file-id"`
|
FileID int `mapstructure:"file-id"`
|
||||||
ReleaseChannel string `mapstructure:"release-channel" toml:"release-channel"`
|
ReleaseChannel string `mapstructure:"release-channel"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u cfUpdater) DoUpdate(mod core.Mod) (bool, error) {
|
func (u cfUpdater) DoUpdate(mod core.Mod) (bool, error) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u cfUpdater) ToMap() (map[string]interface{}, error) {
|
||||||
|
newMap := make(map[string]interface{})
|
||||||
|
err := mapstructure.Decode(u, &newMap)
|
||||||
|
return newMap, err
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user