Skip to content

Commit

Permalink
corrections for win
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Jan 13, 2024
1 parent e6fd858 commit 3b67968
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
11 changes: 10 additions & 1 deletion cmd/slackdump/internal/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
// collects the information and stores it in the struct. The struct is then
// serialized to JSON and printed to stdout.
//
// The collect() method can choose not to terminate on error, but, for string
// methods, populate it with the error message, there's a function called
// "looser(err)" that returns an error with prefix "ERROR", the string will
// look like "*ERROR: some error*".
//
// Procedure to add new collectors:
// 1. Create a new file in this package, named after the collector.
// 2. Define a struct with the name of the collector, alternatively, if
Expand Down Expand Up @@ -56,11 +61,11 @@ var CmdInfo = &base.Command{
}

type sysinfo struct {
OS osinfo `json:"os"`
Workspace workspace `json:"workspace"`
Playwright pwinfo `json:"playwright"`
Rod rodinfo `json:"rod"`
EzLogin ezlogin `json:"ez_login"`
OS osinfo `json:"os"`
}

type ezlogin struct {
Expand Down Expand Up @@ -113,3 +118,7 @@ func dirnames(des []fs.DirEntry) []string {
}
return res
}

func looser(err error) string {
return "*ERROR: " + err.Error() + "*"
}
9 changes: 6 additions & 3 deletions cmd/slackdump/internal/info/os.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package info

import (
"os"
"runtime"

"github.com/rusq/slackdump/v2/auth"
)

type osinfo struct {
OS string `json:"os"`
Arch string `json:"arch"`
IsDocker bool `json:"is_docker"`
OS string `json:"os"`
Arch string `json:"arch"`
IsDocker bool `json:"is_docker"`
IsXactive bool `json:"is_x_active"`
}

func (inf *osinfo) collect() {
inf.OS = runtime.GOOS
inf.Arch = runtime.GOARCH
inf.IsDocker = auth.IsDocker()
inf.IsXactive = os.Getenv("DISPLAY") != ""
}
8 changes: 7 additions & 1 deletion cmd/slackdump/internal/info/playwright.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (inf *pwinfo) collect() {
SkipInstallBrowsers: true},
)
if err != nil {
inf.Path = err.Error()
inf.Path = looser(err)
return
}
inf.Path = homerepl(pwdrv.DriverDirectory)
Expand All @@ -32,13 +32,19 @@ func (inf *pwinfo) collect() {
if stat, err := os.Stat(pwdrv.DriverBinaryLocation); err == nil {
inf.ScriptPerm = stat.Mode().String()
inf.ScriptExists = true
} else {
inf.ScriptPerm = looser(err)
}
}
if de, err := os.ReadDir(filepath.Join(pwdrv.DriverDirectory, "..")); err == nil {
inf.InstalledVersions = dirnames(de)
} else {
inf.InstalledVersions = []string{looser(err)}
}

if de, err := os.ReadDir(filepath.Join(pwdrv.DriverDirectory, "..", "..", "ms-playwright")); err == nil {
inf.InstalledBrowsers = dirnames(de)
} else {
inf.InstalledBrowsers = []string{looser(err)}
}
}
2 changes: 2 additions & 0 deletions cmd/slackdump/internal/info/rod.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ func (inf *rodinfo) collect() {
inf.Path = homerepl(launcher.DefaultBrowserDir)
if de, err := os.ReadDir(launcher.DefaultBrowserDir); err == nil {
inf.Browsers = dirnames(de)
} else {
inf.Browsers = []string{looser(err)}
}
}

0 comments on commit 3b67968

Please sign in to comment.