commit 0ba68d2cd97ed5023b9d73dbcaadf1efa5f400fd
parent c42d39ee9f0af2dd211b2aa1c7174e278cadd2e4
Author: Sean Enck <sean@ttypty.com>
Date: Sun, 5 Feb 2023 09:41:20 -0500
pushing platform to a singular path
Diffstat:
4 files changed, 20 insertions(+), 17 deletions(-)
diff --git a/internal/inputs/env.go b/internal/inputs/env.go
@@ -280,6 +280,15 @@ func (o environmentOutput) formatEnvironmentVariable(required bool, name, val, d
return fmt.Sprintf("\n%s\n %s\n\n required: %t\n value: %s\n options: %s\n", name, desc, required, value, strings.Join(allowed, "|"))
}
+func PlatformSet() []string {
+ return []string{
+ MacOSPlatform,
+ LinuxWaylandPlatform,
+ LinuxXPlatform,
+ WindowsLinuxPlatform,
+ }
+}
+
// ListEnvironmentVariables will print information about env variables and potential/set values
func ListEnvironmentVariables(showValues bool) []string {
e := environmentOutput{showValues: showValues}
@@ -297,7 +306,7 @@ func ListEnvironmentVariables(showValues bool) []string {
results = append(results, e.formatEnvironmentVariable(false, ClipPasteEnv, detectedValue, "override the detected platform paste command", []string{commandArgsExample}))
results = append(results, e.formatEnvironmentVariable(false, ClipCopyEnv, detectedValue, "override the detected platform copy command", []string{commandArgsExample}))
results = append(results, e.formatEnvironmentVariable(false, clipMaxEnv, fmt.Sprintf("%d", defaultMaxClipboard), "override the amount of time before totp clears the clipboard (e.g. 10), must be an integer", []string{"integer"}))
- results = append(results, e.formatEnvironmentVariable(false, PlatformEnv, detectedValue, "override the detected platform", []string{MacOSPlatform, LinuxWaylandPlatform, LinuxXPlatform, WindowsLinuxPlatform}))
+ results = append(results, e.formatEnvironmentVariable(false, PlatformEnv, detectedValue, "override the detected platform", PlatformSet()))
results = append(results, e.formatEnvironmentVariable(false, noTOTPEnv, isNo, "disable TOTP integrations", isYesNoArgs))
results = append(results, e.formatEnvironmentVariable(false, HookDirEnv, "", "the path to hooks to execute on actions against the database", []string{"directory"}))
results = append(results, e.formatEnvironmentVariable(false, clipOSC52Env, isNo, "enable OSC52 clipboard mode", isYesNoArgs))
diff --git a/internal/platform/clipboard_test.go b/internal/platform/clipboard_test.go
@@ -55,8 +55,8 @@ func TestClipboardInstances(t *testing.T) {
os.Setenv("LOCKBOX_NOCLIP", "no")
os.Setenv("LOCKBOX_CLIP_MAX", "")
os.Setenv("LOCKBOX_CLIP_OSC52", "no")
- for _, item := range []inputs.SystemPlatform{inputs.MacOSPlatform, inputs.LinuxWaylandPlatform, inputs.LinuxXPlatform, inputs.WindowsLinuxPlatform} {
- os.Setenv("LOCKBOX_PLATFORM", string(item))
+ for _, item := range inputs.PlatformSet() {
+ os.Setenv("LOCKBOX_PLATFORM", item)
_, err := platform.NewClipboard()
if err != nil {
t.Errorf("invalid clipboard: %v", err)
diff --git a/internal/platform/core.go b/internal/platform/core.go
@@ -18,18 +18,12 @@ const (
func NewPlatform() (inputs.SystemPlatform, error) {
env := os.Getenv(inputs.PlatformEnv)
if env != "" {
- switch env {
- case inputs.MacOSPlatform:
- return inputs.MacOSPlatform, nil
- case inputs.LinuxWaylandPlatform:
- return inputs.LinuxWaylandPlatform, nil
- case inputs.WindowsLinuxPlatform:
- return inputs.WindowsLinuxPlatform, nil
- case inputs.LinuxXPlatform:
- return inputs.LinuxXPlatform, nil
- default:
- return unknownPlatform, errors.New("unknown platform mode")
+ for _, p := range inputs.PlatformSet() {
+ if p == env {
+ return inputs.SystemPlatform(p), nil
+ }
}
+ return unknownPlatform, errors.New("unknown platform mode")
}
b, err := exec.Command("uname", "-a").Output()
if err != nil {
diff --git a/internal/platform/core_test.go b/internal/platform/core_test.go
@@ -9,13 +9,13 @@ import (
)
func TestNewPlatform(t *testing.T) {
- for _, item := range []inputs.SystemPlatform{inputs.MacOSPlatform, inputs.LinuxWaylandPlatform, inputs.LinuxXPlatform, inputs.WindowsLinuxPlatform} {
- os.Setenv("LOCKBOX_PLATFORM", string(item))
+ for _, item := range inputs.PlatformSet() {
+ os.Setenv("LOCKBOX_PLATFORM", item)
s, err := platform.NewPlatform()
if err != nil {
t.Errorf("invalid clipboard: %v", err)
}
- if s != item {
+ if s != inputs.SystemPlatform(item) {
t.Error("mismatch on input and resulting detection")
}
}