5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 22:13:36 +08:00
wails/cmd/linuxdb.go
Byron 08fe7b64d6 Yaml bug (#207)
* test: azure pipeline

* fix: azure pipeline yaml

* feat: elementary support

* feat: opensuse support

* fix: 0_setup.go line 27

* fix: 0_setup.go line 27

* fix: opensuse yaml

* fix: opensuse yaml

* fix: opensuse yaml

* fix: opensuse yaml

* fix: opensuse yaml

* fix: opensuse yaml

* fix: yaml

* fix: yaml

* fix: yaml

* fix: opensuse yaml

* fix: opensuse

* fix: opensuse

* fix: opensuse

* fix: opensuse

* fix: string trim os osRelease field NAME

* fix: 0_setup.go if err typo

* test

* test

* fix: typo in linux.go

* test: remove quotes from opensuse case

* test: revert

* test: ""

* test: ""

* test: ""

* test: ""

* fix: replace trim with replace

* fix: drop 0_setup.go and run checks by system.go

* fix: elementary os yaml name

* fix: open suse yaml entry

* fix: commented out result.Release = version

* fix: commented out result.Release = version

* fix: revert Replace to Trim

* fix: Linux Mint yaml entry

* fix: capitalize distros entries

* fix: capitalize distros entries

* fix: capitalize distros entries

* test

* test

* fix: open suse yaml entry

* fix: yaml entris

* test

* test

* test

* test

* test

* test

* branch changing

* fix: bug in setup process

* debugging

* debugging

* debugging

* debugging

* fix: yaml entries & err == nil bug

* Update prerequisites.go

* fix: bug

* fix: 0_setup.go

* fix: yaml bug

* fix: yaml bug
2019-08-26 05:02:49 +10:00

92 lines
2.5 KiB
Go

package cmd
import (
"log"
"github.com/leaanthony/mewn"
"gopkg.in/yaml.v3"
)
// LinuxDB is the database for linux distribution data.
type LinuxDB struct {
Distributions map[string]*Distribution `yaml:"distributions"`
}
// Distribution holds the os-release ID and a map of releases.
type Distribution struct {
ID string `yaml:"id"`
Releases map[string]*Release `yaml:"releases"`
}
// GetRelease attempts to return the specific Release information
// for the given release name. If there is no specific match, the
// default release data is returned.
func (d *Distribution) GetRelease(version string) *Release {
result := d.Releases[version]
if result == nil {
result = d.Releases["default"]
}
return result
}
// Release holds the name and version of the release as given by
// os-release. Programs is a slice of dependant programs required
// to be present on the local installation for Wails to function.
// Libraries is a slice of libraries that must be present for Wails
// applications to compile.
type Release struct {
Name string `yaml:"name"`
Version string `yaml:"version"`
GccVersionCommand string `yaml:"gccversioncommand"`
Programs []*Prerequisite `yaml:"programs"`
Libraries []*Prerequisite `yaml:"libraries"`
}
// Prerequisite is a simple struct containing a program/library name
// plus the distribution specific help text indicating how to install
// it.
type Prerequisite struct {
Name string `yaml:"name"`
Help string `yaml:"help,omitempty"`
}
// Load will load the given filename from disk and attempt to
// import the data into the LinuxDB.
func (l *LinuxDB) Load(filename string) error {
if fs.FileExists(filename) {
data, err := fs.LoadAsBytes(filename)
if err != nil {
return err
}
return l.ImportData(data)
}
return nil
}
// ImportData will unmarshal the given YAML formatted data
// into the LinuxDB
func (l *LinuxDB) ImportData(data []byte) error {
return yaml.Unmarshal(data, l)
}
// GetDistro returns the Distribution information for the
// given distribution name. If the distribution is not supported,
// nil is returned.
func (l *LinuxDB) GetDistro(distro string) *Distribution {
return l.Distributions[distro]
}
// NewLinuxDB creates a new LinuxDB instance from the bundled
// linuxdb.yaml file.
func NewLinuxDB() *LinuxDB {
data := mewn.Bytes("./linuxdb.yaml")
result := LinuxDB{
Distributions: make(map[string]*Distribution),
}
err := result.ImportData(data)
if err != nil {
log.Fatal(err)
}
return &result
}