diff --git a/flatpak/capabilities_linux.go b/flatpak/capabilities_linux.go new file mode 100644 index 0000000..14ef8b0 --- /dev/null +++ b/flatpak/capabilities_linux.go @@ -0,0 +1,56 @@ +//go:build linux + +package flatpak + +import ( + "context" + "fmt" + "strings" + + "github.com/gogrlx/snack" +) + +func latestVersion(ctx context.Context, pkg string) (string, error) { + out, err := run(ctx, []string{"remote-info", "flathub", pkg}) + if err != nil { + if strings.Contains(err.Error(), "exit status 1") { + return "", fmt.Errorf("flatpak latestVersion %s: %w", pkg, snack.ErrNotFound) + } + return "", fmt.Errorf("flatpak latestVersion: %w", err) + } + // remote-info output is key:value like `flatpak info` + p := parseInfo(out) + if p == nil || p.Version == "" { + return "", fmt.Errorf("flatpak latestVersion %s: %w", pkg, snack.ErrNotFound) + } + return p.Version, nil +} + +func listUpgrades(ctx context.Context) ([]snack.Package, error) { + out, err := run(ctx, []string{"remote-ls", "--updates", "--columns=name,application,version,origin"}) + if err != nil { + // No updates available may produce an error on some versions + if strings.Contains(err.Error(), "No updates") { + return nil, nil + } + return nil, fmt.Errorf("flatpak listUpgrades: %w", err) + } + return parseList(out), nil +} + +func upgradeAvailable(ctx context.Context, pkg string) (bool, error) { + upgrades, err := listUpgrades(ctx) + if err != nil { + return false, err + } + for _, u := range upgrades { + if u.Name == pkg || u.Description == pkg { + return true, nil + } + } + return false, nil +} + +func versionCmp(_ context.Context, ver1, ver2 string) (int, error) { + return semverCmp(ver1, ver2), nil +} diff --git a/flatpak/capabilities_other.go b/flatpak/capabilities_other.go new file mode 100644 index 0000000..9dadcec --- /dev/null +++ b/flatpak/capabilities_other.go @@ -0,0 +1,25 @@ +//go:build !linux + +package flatpak + +import ( + "context" + + "github.com/gogrlx/snack" +) + +func latestVersion(_ context.Context, _ string) (string, error) { + return "", snack.ErrUnsupportedPlatform +} + +func listUpgrades(_ context.Context) ([]snack.Package, error) { + return nil, snack.ErrUnsupportedPlatform +} + +func upgradeAvailable(_ context.Context, _ string) (bool, error) { + return false, snack.ErrUnsupportedPlatform +} + +func versionCmp(_ context.Context, _, _ string) (int, error) { + return 0, snack.ErrUnsupportedPlatform +} diff --git a/ports/capabilities_other.go b/ports/capabilities_other.go new file mode 100644 index 0000000..5441940 --- /dev/null +++ b/ports/capabilities_other.go @@ -0,0 +1,45 @@ +//go:build !openbsd + +package ports + +import ( + "context" + + "github.com/gogrlx/snack" +) + +func latestVersion(_ context.Context, _ string) (string, error) { + return "", snack.ErrUnsupportedPlatform +} + +func listUpgrades(_ context.Context) ([]snack.Package, error) { + return nil, snack.ErrUnsupportedPlatform +} + +func upgradeAvailable(_ context.Context, _ string) (bool, error) { + return false, snack.ErrUnsupportedPlatform +} + +func versionCmp(_ context.Context, _, _ string) (int, error) { + return 0, snack.ErrUnsupportedPlatform +} + +func autoremove(_ context.Context, _ ...snack.Option) error { + return snack.ErrUnsupportedPlatform +} + +func clean(_ context.Context) error { + return snack.ErrUnsupportedPlatform +} + +func fileList(_ context.Context, _ string) ([]string, error) { + return nil, snack.ErrUnsupportedPlatform +} + +func owner(_ context.Context, _ string) (string, error) { + return "", snack.ErrUnsupportedPlatform +} + +func upgradePackages(_ context.Context, _ []snack.Target, _ ...snack.Option) (snack.InstallResult, error) { + return snack.InstallResult{}, snack.ErrUnsupportedPlatform +}