Skip to content

Commit 955d05f

Browse files
committed
Print hero name in addition to deck name
Add capability to print duplicates for cards.
1 parent f3f8d81 commit 955d05f

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ By default mcdbcli prints the deck in release order grouped by aspect.
4242
Print in wave order.
4343
Can be combined with -a option.
4444

45+
* -u
46+
Print duplicates alongside originals.
47+
4548
Without -d or -l options `mcdbcli` will read deck as JSON from stdin.
4649

4750
```sh

mcdbcli

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ declare PACK_ORDER=false
99
declare RELEASE_ORDER=false
1010
declare SUPER_ALPHABETICAL_ORDER=false
1111
declare WAVE_ORDER=false
12+
declare PRINT_DUPLICATES=false
1213
declare DECK_JSON
1314

1415
init_packs() {
@@ -95,12 +96,30 @@ print_card() {
9596
local card_name="$(jq -r '.real_name' <<<$card_json)"
9697
local pack_name="$(jq -r '.pack_name' <<<$card_json)"
9798
local position="$(jq -r '.position' <<<$card_json)"
99+
local -a duplicate_files
100+
101+
if $PRINT_DUPLICATES; then
102+
for duplicate_id in $(jq -r 'if (.duplicated_by | length) > 0 then .duplicated_by[] else empty end' <<<$card_json); do
103+
duplicate_files+=($(get_card_file $duplicate_id))
104+
done
105+
fi
98106

99107
printf ' %d \u00D7 ' "$amount"
100108

101109
print_faction_color "$faction_code"
102110

103-
printf '%s\e[0m (\e[90mWave #%s\e[0m %s #%d)\n' "$card_name" "$wave_number" "$pack_name" "$position"
111+
printf '%s\e[0m (\e[90mWave #%d\e[0m %s #%d' "$card_name" "$wave_number" "$pack_name" "$position"
112+
113+
if $PRINT_DUPLICATES; then
114+
for duplicate_file in "${duplicate_files[@]}"; do
115+
local duplicate_pack_code=$(jq -r '.pack_code' $duplicate_file)
116+
local duplicate_wave_number=$(get_wave_number "$duplicate_pack_code")
117+
local duplicate_pack_name=$(jq -r '.pack_name' $duplicate_file)
118+
local duplicate_position=$(jq -r '.position' $duplicate_file)
119+
printf '\e[90m, Wave #%d\e[0m %s #%d' "$duplicate_wave_number" "$duplicate_pack_name" "$duplicate_position"
120+
done
121+
fi
122+
printf ')\n'
104123
}
105124

106125
get_card_file() {
@@ -228,12 +247,13 @@ print_cards() {
228247

229248
print_deck() {
230249
local deck_name=$(jq -r '.name' <<<"$DECK_JSON")
250+
local hero_name=$(jq -r '.hero_name' <<<"$DECK_JSON")
231251

232-
printf '%s\n' "$deck_name"
252+
printf '%s (%s)\n' "$deck_name" "$hero_name"
233253

234254
local -a card_files
235-
for card_id_json in $(jq -r '.slots | keys | .[]' <<<"$DECK_JSON"); do
236-
card_files+=($(get_card_file $card_id_json))
255+
for card_id in $(jq -r '.slots | keys | .[]' <<<"$DECK_JSON"); do
256+
card_files+=($(get_card_file $card_id))
237257
done
238258

239259
if $SUPER_ALPHABETICAL_ORDER; then
@@ -271,7 +291,7 @@ print_deck() {
271291

272292
init_packs
273293

274-
while getopts 'd:l:aprw' opt; do
294+
while getopts 'd:l:aprwu' opt; do
275295
case $opt in
276296
d)
277297
DECK_JSON="$(curl -s "${MCDB_API_URL}/deck/${OPTARG}")"
@@ -294,6 +314,9 @@ while getopts 'd:l:aprw' opt; do
294314
w)
295315
WAVE_ORDER=true
296316
;;
317+
u)
318+
PRINT_DUPLICATES=true
319+
;;
297320
esac
298321
done
299322

0 commit comments

Comments
 (0)