Permalink
Browse files

client: copy: when multiple items match, allow interactive choosing

  • Loading branch information...
jcs committed Sep 6, 2017
1 parent 869e47d commit d1eb84c108fd20d39676f0576b36dfb294311ffc
Showing with 28 additions and 3 deletions.
  1. +28 −3 client.go
View
@@ -846,10 +846,35 @@ func lookupSingleItem(vault *onepass.Vault, pattern string) (onepass.Item, error
if len(items) > 1 {
fmt.Fprintf(os.Stderr, "Multiple matching items:\n")
for _, item := range items {
fmt.Fprintf(os.Stderr, " %s (%s)\n", item.Title, item.Uuid)
for x, item := range items {
fmt.Fprintf(os.Stderr, "%d) %s (%s)\n", x, item.Title, item.Uuid)
}
return onepass.Item{}, fmt.Errorf("Multiple matching items")
if !terminal.IsTerminal(int(os.Stdout.Fd())) {
return onepass.Item{}, fmt.Errorf("Multiple matching items")
}
opt := -1
for {
i := readLinePrompt("Item to copy")
if i == "" {
return onepass.Item{}, fmt.Errorf("Multiple matching items")
}
opt, err = strconv.Atoi(i)
if err != nil {
fmt.Fprintf(os.Stderr, "Invalid option: %v\n", err)
continue
}
if opt >= 0 && opt < len(items) {
break
}
fmt.Fprintf(os.Stderr, "Invalid option: %d\n", opt)
}
return items[opt], nil
}
return items[0], nil

0 comments on commit d1eb84c

Please sign in to comment.