48 lines
1018 B
Go
48 lines
1018 B
Go
package plugin
|
|
|
|
import (
|
|
tomlpkg "github.com/BurntSushi/toml"
|
|
)
|
|
|
|
type ModFile struct {
|
|
Plugin ModPlugin `toml:"plugin"`
|
|
Compatibility *ModCompat `toml:"compatibility"`
|
|
Requires []ModRequirement `toml:"requires"`
|
|
}
|
|
|
|
type ModPlugin struct {
|
|
Name string `toml:"name"`
|
|
Scope string `toml:"scope"`
|
|
Version string `toml:"version"`
|
|
Kind string `toml:"kind,omitempty"`
|
|
Categories []string `toml:"categories,omitempty"`
|
|
}
|
|
|
|
type ModCompat struct {
|
|
BlockCore string `toml:"block_core"`
|
|
}
|
|
|
|
type ModRequirement struct {
|
|
Name string `toml:"name"`
|
|
Version string `toml:"version"`
|
|
}
|
|
|
|
func ParseModFull(b []byte) (*ModFile, error) {
|
|
var m ModFile
|
|
if err := tomlpkg.Unmarshal(b, &m); err != nil {
|
|
return nil, err
|
|
}
|
|
return &m, nil
|
|
}
|
|
|
|
func (m *ModFile) Coords() string {
|
|
if m == nil {
|
|
return ""
|
|
}
|
|
scope := m.Plugin.Scope
|
|
if scope == "" {
|
|
return m.Plugin.Name + "@" + m.Plugin.Version
|
|
}
|
|
return "@" + scope + "/" + m.Plugin.Name + "@" + m.Plugin.Version
|
|
}
|