Treat empty environ values as absent in HasEnvSource

Amolith created

Change summary

cmd/root.go                      | 2 --
internal/config/config.go        | 4 ++--
internal/config/resolved_test.go | 4 ++--
internal/restic/exec.go          | 2 --
internal/ui/screens/snapshot.go  | 1 -
5 files changed, 4 insertions(+), 9 deletions(-)

Detailed changes

cmd/root.go 🔗

@@ -469,8 +469,6 @@ func promptForCommand(command string, cfg *config.ResolvedConfig) (map[string][]
 	}
 }
 
-
-
 // includeFlags lists the restic flags that provide explicit file
 // selection for restore. When any of these are already present in the
 // resolved config, the interactive file picker is skipped — the user

internal/config/config.go 🔗

@@ -84,10 +84,10 @@ const CommandSuffix = "_COMMAND"
 // check for it themselves.
 func (rc *ResolvedConfig) HasEnvSource(key string) bool {
 	if rc.Environ != nil {
-		if _, ok := rc.Environ[key]; ok {
+		if v, ok := rc.Environ[key]; ok && v != "" {
 			return true
 		}
-		if _, ok := rc.Environ[key+CommandSuffix]; ok {
+		if v, ok := rc.Environ[key+CommandSuffix]; ok && v != "" {
 			return true
 		}
 	}

internal/config/resolved_test.go 🔗

@@ -37,10 +37,10 @@ func TestHasEnvSource(t *testing.T) {
 			want:    false,
 		},
 		{
-			name:    "empty string value still counts as present",
+			name:    "empty string value counts as absent",
 			environ: map[string]string{"RESTIC_REPOSITORY": ""},
 			envKey:  "RESTIC_REPOSITORY",
-			want:    true,
+			want:    false,
 		},
 		{
 			name:    "command variant for non-restic key",

internal/restic/exec.go 🔗

@@ -12,8 +12,6 @@ import (
 	"git.secluded.site/keld/internal/config"
 )
 
-
-
 // resticNativeCommands lists .environ keys that restic handles natively.
 // Keld passes these through as-is rather than executing them.
 var resticNativeCommands = map[string]bool{

internal/ui/screens/snapshot.go 🔗

@@ -274,7 +274,6 @@ func (s *Snapshot) rebuildSelectForm() {
 // theme changes preserve the user's input. Callers that start a fresh
 // entry (Init, switchToManual) reset s.entered explicitly.
 func (s *Snapshot) buildManualForm() {
-
 	input := huh.NewInput().
 		Title("Snapshot ID").
 		Description("Supports snapshotID:subfolder syntax, or \"latest\".").