Skip to content

Commit

Permalink
fields: Items must now match exactly, output useful errors when there…
Browse files Browse the repository at this point in the history
… are multiple results
  • Loading branch information
andsens committed Aug 5, 2024
1 parent 260d8ad commit ba6f29d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions bin/bitwarden-fields
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,19 @@ docopt_i=1;[[ $BASH_VERSION =~ ^4.3 ]] && docopt_i=2;for \
# shellcheck disable=2064
trap "exec 9>&-; BW_SESSION=\"$BW_SESSION\" bw lock >/dev/null" EXIT
fi
if ! data=$(bw --nointeraction --raw get item "$ITEMNAME"); then
exit_fatal 3 "Unable to retrieve '%s'" "$ITEMNAME"
local bw_result bw_result_num
bw_result=$(bw --nointeraction --raw list items --search "$ITEMNAME" | jq --arg name "$ITEMNAME" '[.[] | select(.name==$name)]')
if ! bw_result_num=$(jq -e 'length' <<<"$bw_result" 2>/dev/null); then
exit_fatal 1 "Unable to parse result from bw"
fi
if (( bw_result_num == 0)); then
exit_fatal 3 "'%s' was not found" "$ITEMNAME"
fi
if (( bw_result_num > 1)); then
exit_fatal 3 "Got multiple (%d) results when searching for '%s'" "$bw_result_num" "$ITEMNAME"
fi
if ! data=$(jq -e '.[0]' <<<"$bw_result" 2>/dev/null); then
exit_fatal 1 "Unable to parse result from bw" "$ITEMNAME"
fi
local item_id
item_id=$(jq -r '.id' <<<"$data")
Expand Down

0 comments on commit ba6f29d

Please sign in to comment.