From 89404187ae79450eed02a06a59ba210a2096c54e Mon Sep 17 00:00:00 2001 From: rsteube Date: Tue, 22 Jul 2025 23:18:33 +0200 Subject: [PATCH] value: support duplicates e.g. `adb pull DEVICE_FILE {DEVICE_FILE | LOCAL_FILE}...` --- internal/common/value.go | 25 ++++++++++++++++++++----- internal/shell/shell.go | 1 + 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/internal/common/value.go b/internal/common/value.go index 501f048a5..3c4e90a2a 100644 --- a/internal/common/value.go +++ b/internal/common/value.go @@ -47,9 +47,13 @@ func RawValuesFrom(values ...string) RawValues { } func (r RawValues) Unique() RawValues { - uniqueRawValues := make(map[string]RawValue) + type key struct { + Value string + Uid string + } + uniqueRawValues := make(map[key]RawValue) for _, value := range r { - uniqueRawValues[value.Value] = value + uniqueRawValues[key{value.Value, value.Uid}] = value } rawValues := make([]RawValue, 0, len(uniqueRawValues)) @@ -150,6 +154,17 @@ func (a ByValue) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // ByDisplay alias to filter by display. type ByDisplay []RawValue -func (a ByDisplay) Len() int { return len(a) } -func (a ByDisplay) Less(i, j int) bool { return a[i].Display < a[j].Display } -func (a ByDisplay) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a ByDisplay) Len() int { return len(a) } +func (a ByDisplay) Less(i, j int) bool { + if a[i].Display == a[j].Display { + return ByUid(a).Less(i, j) // ensure consistency in export + } + return a[i].Display < a[j].Display +} +func (a ByDisplay) Swap(i, j int) { a[i], a[j] = a[j], a[i] } + +type ByUid []RawValue + +func (a ByUid) Len() int { return len(a) } +func (a ByUid) Less(i, j int) bool { return a[i].Uid < a[j].Uid } +func (a ByUid) Swap(i, j int) { a[i], a[j] = a[j], a[i] } diff --git a/internal/shell/shell.go b/internal/shell/shell.go index 43e340096..d3858728b 100644 --- a/internal/shell/shell.go +++ b/internal/shell/shell.go @@ -117,6 +117,7 @@ func Value(shell string, value string, meta common.Meta, values common.RawValues for index := range values { values[index].Uid = "" } + values = values.Unique() // re-filter after clearance return f(value, meta, values) } return ""