Skip to content

Commit fd534c7

Browse files
committed
🧠 add --open option to playground topic consume to dump all topic into a file and open it #6441
1 parent 2301abf commit fd534c7

File tree

7 files changed

+94
-8
lines changed

7 files changed

+94
-8
lines changed

scripts/cli/completions.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ _playground_completions() {
11771177
;;
11781178

11791179
*'topic consume'*)
1180-
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_playground_completions_filter "--grep --help --key-subject --max-characters --max-messages --min-expected-messages --plot-latencies-timestamp-field --tail --timeout --topic --value-subject --verbose -h -t -v")" -- "$cur")
1180+
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_playground_completions_filter "--grep --help --key-subject --max-characters --max-messages --min-expected-messages --open --plot-latencies-timestamp-field --tail --timeout --topic --value-subject --verbose -h -o -t -v")" -- "$cur")
11811181
;;
11821182

11831183
*'topic produce'*)

scripts/cli/playground

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4784,7 +4784,7 @@ playground_topic_consume_usage() {
47844784
# :flag.usage
47854785
printf " %s\n" "$(magenta "--tail")"
47864786
printf " Tail on logs.\n"
4787-
printf " %s\n" "Conflicts: --min-expected-messages, --max-messages"
4787+
printf " %s\n" "Conflicts: --min-expected-messages, --max-messages, --open"
47884788
echo
47894789

47904790
# :flag.usage
@@ -4808,6 +4808,12 @@ playground_topic_consume_usage() {
48084808
printf " %s\n" "Default: 3000"
48094809
echo
48104810

4811+
# :flag.usage
4812+
printf " %s\n" "$(magenta "--open, -o")"
4813+
printf " 🔖 Save full dump of topic to a file and open with text editor set with\n playground config editor <editor> (default is code)\n"
4814+
printf " %s\n" "Conflicts: --max-characters, --tail, --min-expected-messages"
4815+
echo
4816+
48114817
# :command.usage_fixed_flags
48124818
printf " %s\n" "$(magenta "--help, -h")"
48134819
printf " Show this help\n"
@@ -20831,7 +20837,7 @@ playground_container_logs_command() {
2083120837

2083220838
if [[ -n "$open" ]]
2083320839
then
20834-
filename="/tmp/${container}-`date '+%Y-%m-%d-%H-%M-%S'`.log"
20840+
filename="/tmp/${container}-$(date '+%Y-%m-%d-%H-%M-%S').log"
2083520841
docker container logs "$container" > "$filename" 2>&1
2083620842
if [ $? -eq 0 ]
2083720843
then
@@ -21318,6 +21324,7 @@ playground_topic_consume_command() {
2131821324
key_subject="${args[--key-subject]}"
2131921325
value_subject="${args[--value-subject]}"
2132021326
max_characters="${args[--max-characters]}"
21327+
open="${args[--open]}"
2132121328

2132221329
if [[ -n "$key_subject" ]]
2132321330
then
@@ -21482,9 +21489,28 @@ playground_topic_consume_command() {
2148221489
fi
2148321490
fi
2148421491

21492+
if [[ -n "$open" ]]
21493+
then
21494+
filename="/tmp/dump-${topic}-$(date '+%Y-%m-%d-%H-%M-%S').log"
21495+
21496+
log "📄 Logging output to $filename"
21497+
playground topic consume --topic $topic --max-messages -1 > $filename
21498+
if [ $? -eq 0 ]
21499+
then
21500+
playground open --file "${filename}"
21501+
else
21502+
logerror "❌ failed to dump topic $topic"
21503+
fi
21504+
exit 0
21505+
fi
21506+
2148521507
if [ -n "$tail" ]
2148621508
then
2148721509
log "✨ Tailing content of topic $topic"
21510+
elif [[ -n "$max_messages" ]] && [ $max_messages -eq -1 ] && [[ ! -n "$timestamp_field" ]]
21511+
then
21512+
log "✨ --max-messages is set to -1, display content of topic $topic, it contains $nb_messages messages"
21513+
max_messages=$nb_messages
2148821514
elif [[ -n "$max_messages" ]] && [ $nb_messages -ge $max_messages ] && [[ ! -n "$timestamp_field" ]]
2148921515
then
2149021516
log "✨ Display content of topic $topic, it contains $nb_messages messages, but displaying only --max-messages=$max_messages"
@@ -21502,6 +21528,7 @@ playground_topic_consume_command() {
2150221528
then
2150321529
log "📈 plotting results.."
2150421530
fi
21531+
2150521532
key_type=""
2150621533
version=$(curl $sr_security -s "${sr_url}/subjects/${topic}-key/versions/latest" | jq -r .version)
2150721534
if [ "$version" != "null" ]
@@ -21695,6 +21722,7 @@ playground_topic_consume_command() {
2169521722
first_record=1
2169621723
is_base64=0
2169721724
export LC_ALL=C
21725+
2169821726
# Loop through each line in the named pipe
2169921727
while read -r line
2170021728
do
@@ -37519,7 +37547,7 @@ playground_topic_consume_parse_requirements() {
3751937547
# :flag.case
3752037548
--tail)
3752137549
# :flag.conflicts
37522-
for conflict in --min-expected-messages --max-messages; do
37550+
for conflict in --min-expected-messages --max-messages --open; do
3752337551
if [[ -n "${args[$conflict]:-}" ]]; then
3752437552
printf "conflicting options: %s cannot be used with %s\n" "$key" "$conflict" >&2
3752537553
exit 1
@@ -37587,6 +37615,21 @@ playground_topic_consume_parse_requirements() {
3758737615
fi
3758837616
;;
3758937617

37618+
# :flag.case
37619+
--open | -o)
37620+
# :flag.conflicts
37621+
for conflict in --max-characters --tail --min-expected-messages; do
37622+
if [[ -n "${args[$conflict]:-}" ]]; then
37623+
printf "conflicting options: %s cannot be used with %s\n" "$key" "$conflict" >&2
37624+
exit 1
37625+
fi
37626+
done
37627+
37628+
# :flag.case_no_arg
37629+
args['--open']=1
37630+
shift
37631+
;;
37632+
3759037633
-?*)
3759137634
printf "invalid option: %s\n" "$key" >&2
3759237635
exit 1

scripts/cli/playground.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1940,7 +1940,7 @@
19401940
"--tail"
19411941
],
19421942
"argument": "",
1943-
"description": "Tail on logs.\n\nConflicts with: --min-expected-messages, --max-messages\n"
1943+
"description": "Tail on logs.\n\nConflicts with: --min-expected-messages, --max-messages, --open\n"
19441944
},
19451945
{
19461946
"names": [
@@ -1969,6 +1969,14 @@
19691969
],
19701970
"argument": 3000,
19711971
"description": "Max characters per message to display (default is 3000)\n\nDefault value: 3000\n"
1972+
},
1973+
{
1974+
"names": [
1975+
"--open",
1976+
"-o"
1977+
],
1978+
"argument": "",
1979+
"description": "🔖 Save full dump of topic to a file and open with text editor set with playground config editor <editor> (default is code)\n\nConflicts with: --max-characters, --tail, --min-expected-messages\n"
19721980
}
19731981
]
19741982
},

scripts/cli/playground.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2091,7 +2091,7 @@ subcommands:
20912091
description: |
20922092
Tail on logs.
20932093
2094-
Conflicts with: --min-expected-messages, --max-messages
2094+
Conflicts with: --min-expected-messages, --max-messages, --open
20952095
20962096
- names:
20972097
- --plot-latencies-timestamp-field
@@ -2123,6 +2123,15 @@ subcommands:
21232123
21242124
Default value: 3000
21252125
2126+
- names:
2127+
- --open
2128+
- -o
2129+
argument: ""
2130+
description: |
2131+
🔖 Save full dump of topic to a file and open with text editor set with playground config editor <editor> (default is code)
2132+
2133+
Conflicts with: --max-characters, --tail, --min-expected-messages
2134+
21262135
- name: produce
21272136
description: |
21282137
📤 Produce to a topic

scripts/cli/src/bashly.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2341,7 +2341,7 @@ commands:
23412341
required: false
23422342
help: |-
23432343
Tail on logs.
2344-
conflicts: [--min-expected-messages, --max-messages]
2344+
conflicts: [--min-expected-messages, --max-messages, --open]
23452345

23462346
- long: --plot-latencies-timestamp-field
23472347
required: false
@@ -2377,6 +2377,12 @@ commands:
23772377
help: |-
23782378
Max characters per message to display (default is 3000)
23792379
2380+
- long: --open
2381+
short: -o
2382+
help: |-
2383+
🔖 Save full dump of topic to a file and open with text editor set with playground config editor <editor> (default is code)
2384+
conflicts: [--max-characters, --tail, --min-expected-messages]
2385+
23802386
- name: produce
23812387
filters:
23822388
- schema_registry_running

scripts/cli/src/commands/container/logs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ max_wait="${args[--max-wait]}"
55

66
if [[ -n "$open" ]]
77
then
8-
filename="/tmp/${container}-`date '+%Y-%m-%d-%H-%M-%S'`.log"
8+
filename="/tmp/${container}-$(date '+%Y-%m-%d-%H-%M-%S').log"
99
docker container logs "$container" > "$filename" 2>&1
1010
if [ $? -eq 0 ]
1111
then

scripts/cli/src/commands/topic/consume.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ timestamp_field="${args[--plot-latencies-timestamp-field]}"
99
key_subject="${args[--key-subject]}"
1010
value_subject="${args[--value-subject]}"
1111
max_characters="${args[--max-characters]}"
12+
open="${args[--open]}"
1213

1314
if [[ -n "$key_subject" ]]
1415
then
@@ -171,9 +172,28 @@ do
171172
fi
172173
fi
173174

175+
if [[ -n "$open" ]]
176+
then
177+
filename="/tmp/dump-${topic}-$(date '+%Y-%m-%d-%H-%M-%S').log"
178+
179+
log "📄 dumping topic content to $filename"
180+
playground topic consume --topic $topic --max-messages -1 > $filename
181+
if [ $? -eq 0 ]
182+
then
183+
playground open --file "${filename}"
184+
else
185+
logerror "❌ failed to dump topic $topic"
186+
fi
187+
exit 0
188+
fi
189+
174190
if [ -n "$tail" ]
175191
then
176192
log "✨ Tailing content of topic $topic"
193+
elif [[ -n "$max_messages" ]] && [ $max_messages -eq -1 ] && [[ ! -n "$timestamp_field" ]]
194+
then
195+
log "✨ --max-messages is set to -1, display full content of topic $topic, it contains $nb_messages messages"
196+
max_messages=$nb_messages
177197
elif [[ -n "$max_messages" ]] && [ $nb_messages -ge $max_messages ] && [[ ! -n "$timestamp_field" ]]
178198
then
179199
log "✨ Display content of topic $topic, it contains $nb_messages messages, but displaying only --max-messages=$max_messages"

0 commit comments

Comments
 (0)