Skip to content

Commit

Permalink
Update ficsit-cli to 0.3.0, replace zerolog with slog
Browse files Browse the repository at this point in the history
  • Loading branch information
mircearoata committed Dec 17, 2023
1 parent 9237ae8 commit 2a4af5d
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 134 deletions.
6 changes: 3 additions & 3 deletions backend/args.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package backend

import (
"log/slog"
"net/url"
"strings"

"github.com/pkg/errors"
"github.com/rs/zerolog/log"

"github.com/satisfactorymodding/SatisfactoryModManager/backend/bindings"
)
Expand All @@ -18,12 +18,12 @@ func ProcessArguments(args []string) {
uri := args[0]
err := handleURI(uri)
if err != nil {
log.Error().Err(err).Str("uri", uri).Msg("Failed to handle smmanager:// URI")
slog.Error("failed to handle smmanager:// URI", slog.Any("error", err), slog.String("uri", uri))
}
} else {
err := handleFile(args[0])
if err != nil {
log.Error().Err(err).Str("path", args[1]).Msg("Failed to handle file")
slog.Error("failed to handle file", slog.Any("error", err), slog.String("path", args[0]))
}
}
bindings.BindingsInstance.App.Show()
Expand Down
6 changes: 3 additions & 3 deletions backend/autoupdate/autoupdate.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package autoupdate

import (
"log/slog"
"time"

"github.com/rs/zerolog/log"
"github.com/spf13/viper"

"github.com/satisfactorymodding/SatisfactoryModManager/backend/autoupdate/updater"
Expand Down Expand Up @@ -40,12 +40,12 @@ func CheckInterval(interval time.Duration) {
go func() {
err := Updater.CheckForUpdate()
if err != nil {
log.Error().Err(err).Msg("Failed to check for update")
slog.Error("failed to check for update", slog.Any("error", err))
}
for range updateCheckTicker.C {
err := Updater.CheckForUpdate()
if err != nil {
log.Error().Err(err).Msg("Failed to check for update")
slog.Error("failed to check for update", slog.Any("error", err))
}
}
}()
Expand Down
4 changes: 2 additions & 2 deletions backend/bindings/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package bindings

import (
"context"
"log/slog"
"strings"
"time"

"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"

Expand Down Expand Up @@ -76,7 +76,7 @@ func (a *App) startup(ctx context.Context) {
if changed {
err := settings.SaveSettings()
if err != nil {
log.Error().Err(err).Msg("Failed to save settings")
slog.Error("failed to save settings", slog.Any("error", err))
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions backend/bindings/debug_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"context"
"encoding/json"
"fmt"
"log/slog"
"os"
"path"
"runtime"
"time"

"github.com/pkg/errors"
"github.com/rs/zerolog/log"
ficsitCli "github.com/satisfactorymodding/ficsit-cli/cli"
"github.com/spf13/viper"
wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"
Expand Down Expand Up @@ -175,7 +175,7 @@ func (d *DebugInfo) GenerateDebugInfo() bool {
},
})
if err != nil {
log.Error().Err(err).Msg("Failed to open save dialog")
slog.Error("failed to open save dialog", slog.Any("error", err))
return false
}
if filename == "" {
Expand All @@ -184,7 +184,7 @@ func (d *DebugInfo) GenerateDebugInfo() bool {

err = d.generateAndSaveDebugInfo(filename)
if err != nil {
log.Error().Err(err).Msg("Failed to generate debuginfo")
slog.Error("failed to generate debug info", slog.Any("error", err))
return false
}

Expand Down
27 changes: 14 additions & 13 deletions backend/bindings/ficsitcli/installs.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package ficsitcli

import (
"log/slog"
"os"
"os/exec"
"sort"

"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/satisfactorymodding/ficsit-cli/cli"
resolver "github.com/satisfactorymodding/ficsit-resolver"

"github.com/satisfactorymodding/SatisfactoryModManager/backend/installfinders"
)
Expand Down Expand Up @@ -133,13 +134,13 @@ func (f *FicsitCLI) GetInstallation(path string) *InstallationInfo {
}

func (f *FicsitCLI) SelectInstall(path string) error {
l := log.With().Str("task", "selectInstall").Str("path", path).Logger()
l := slog.With(slog.String("task", "selectInstall"), slog.String("path", path))
if f.selectedInstallation != nil && f.selectedInstallation.Info.Path == path {
return nil
}
installation := f.GetInstallation(path)
if installation == nil {
l.Error().Str("path", path).Msg("Failed to find installation")
l.Error("Failed to find installation")
return errors.New("Installation \"" + path + "\" not found")
}
f.selectedInstallation = installation
Expand All @@ -162,7 +163,7 @@ func (f *FicsitCLI) SelectInstall(path string) error {
installErr := f.validateInstall(f.selectedInstallation, "__select_install__")

if installErr != nil {
l.Error().Err(installErr).Str("install", installation.Info.Path).Msg("Failed to validate install")
l.Error("Failed to validate install", slog.Any("error", installErr), slog.String("install", installation.Info.Path))
return errors.Wrap(installErr, "Failed to validate install")
}
return nil
Expand All @@ -177,10 +178,10 @@ func (f *FicsitCLI) GetSelectedInstall() *installfinders.Installation {

func (f *FicsitCLI) SetModsEnabled(enabled bool) error {
if f.selectedInstallation == nil {
log.Error().Msg("No installation selected")
slog.Error("no installation selected")
return errors.New("No installation selected")
}
l := log.With().Str("task", "setModsEnabled").Bool("enabled", enabled).Logger()
l := slog.With(slog.String("task", "setModsEnabled"), slog.Bool("enabled", enabled), slog.String("install", f.selectedInstallation.Info.Path))

var message string
if enabled {
Expand All @@ -207,7 +208,7 @@ func (f *FicsitCLI) SetModsEnabled(enabled bool) error {
installErr := f.validateInstall(f.selectedInstallation, "__toggle_mods__")

if installErr != nil {
l.Error().Err(installErr).Str("install", f.selectedInstallation.Info.Path).Msg("Failed to validate install")
l.Error("failed to validate install", slog.Any("error", installErr))
return errors.Wrap(installErr, "Failed to validate install")
}

Expand All @@ -226,21 +227,21 @@ func (f *FicsitCLI) GetSelectedInstallProfileMods() map[string]cli.ProfileMod {
return profile.Mods
}

func (f *FicsitCLI) GetSelectedInstallLockfileMods() (map[string]cli.LockedMod, error) {
func (f *FicsitCLI) GetSelectedInstallLockfileMods() (map[string]resolver.LockedMod, error) {
if f.selectedInstallation == nil {
return make(map[string]cli.LockedMod), nil
return make(map[string]resolver.LockedMod), nil
}
lockfile, err := f.selectedInstallation.Installation.LockFile(f.ficsitCli)
if err != nil {
return nil, errors.Wrap(err, "failed to get lockfile")
}
if lockfile == nil {
return make(map[string]cli.LockedMod), nil
return make(map[string]resolver.LockedMod), nil
}
return lockfile.Mods, nil
}

func (f *FicsitCLI) GetSelectedInstallLockfile() (*cli.LockFile, error) {
func (f *FicsitCLI) GetSelectedInstallLockfile() (*resolver.LockFile, error) {
if f.selectedInstallation == nil {
return nil, nil
}
Expand All @@ -253,13 +254,13 @@ func (f *FicsitCLI) GetSelectedInstallLockfile() (*cli.LockFile, error) {

func (f *FicsitCLI) LaunchGame() {
if f.selectedInstallation == nil {
log.Error().Msg("No installation selected")
slog.Error("no installation selected")
return
}
cmd := exec.Command(f.selectedInstallation.Info.LaunchPath[0], f.selectedInstallation.Info.LaunchPath[1:]...)
out, err := cmd.CombinedOutput()
if err != nil {
log.Error().Err(err).Str("cmd", cmd.String()).Str("output", string(out)).Msg("Failed to launch game")
slog.Error("failed to launch game", slog.Any("error", err), slog.String("cmd", cmd.String()), slog.String("output", string(out)))
return
}
}
4 changes: 2 additions & 2 deletions backend/bindings/ficsitcli/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package ficsitcli

import (
"fmt"
"log/slog"
"sync"
"time"

"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/satisfactorymodding/ficsit-cli/cli"
"github.com/satisfactorymodding/ficsit-cli/utils"
wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"
Expand Down Expand Up @@ -124,7 +124,7 @@ func (f *FicsitCLI) validateInstall(installation *InstallationInfo, progressItem
func (f *FicsitCLI) EmitModsChange() {
lockfileMods, err := f.GetSelectedInstallLockfileMods()
if err != nil {
log.Error().Err(err).Msg("Failed to load lockfile")
slog.Error("failed to load lockfile", slog.Any("error", err))
return
}
wailsRuntime.EventsEmit(f.ctx, "lockfileMods", lockfileMods)
Expand Down
Loading

0 comments on commit 2a4af5d

Please sign in to comment.