Skip to content

Commit

Permalink
reportinfo.go: add wael's suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
lunarlattice0 committed Oct 17, 2023
1 parent 46ed852 commit c68eacd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
3 changes: 1 addition & 2 deletions cmd/vinegar/vinegar.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,10 @@ func main() {
log.Fatal(err)
}
case "reportinfo":
report, err := util.GenerateInfo(*configPath)
report, err := util.GenerateInfo(cfg)
if err != nil {
log.Fatal(err)
}
fmt.Println("Please share the information below.")
fmt.Printf("%+v\n", report)
case "winetricks":
if err := pfx.Winetricks(); err != nil {
Expand Down
24 changes: 8 additions & 16 deletions util/reportinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,27 @@ package util
import (
"errors"
"os"
"regexp"
"strings"
"github.com/vinegarhq/vinegar/internal/config"
)

type SysInfo struct {
AVXAvailable bool
Distro string //Done
Kernel string // Done
InFlatpak bool // Done
Config string // Done
Config config.Config // Done
}

func GenerateInfo(currentConfigurationPath string) (SysInfo, error) {
//TODO, returns struct Sysinfo.
currentSystem := &SysInfo{}
func GenerateInfo(currentConfiguration config.Config) (SysInfo, error) {

var currentSystem SysInfo

// Check for AVX
if cpufile, err := os.ReadFile("/proc/cpuinfo"); err != nil {
return SysInfo{}, err
} else {
exp := regexp.MustCompile(`avx`)
matches := exp.FindStringSubmatch(string(cpufile))
currentSystem.AVXAvailable = (len(matches) > 0)
currentSystem.AVXAvailable = strings.Contains(cpufile, "avx")) > 0
}

// Get Distro
Expand All @@ -53,18 +52,11 @@ func GenerateInfo(currentConfigurationPath string) (SysInfo, error) {
}

// Read the config and store
if config, err := os.ReadFile(currentConfigurationPath); err != nil {
return SysInfo{}, err
} else {
currentSystem.Config = string(config)
}
currentSystem.Config = currentConfiguration

// Check if in flatpak
if _, err := os.Stat("/.flatpak-info"); err == nil {
currentSystem.InFlatpak = true
} else if errors.Is(err, os.ErrNotExist) {
currentSystem.InFlatpak = false
}

return *currentSystem, nil
}

0 comments on commit c68eacd

Please sign in to comment.