-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexec-enrich-ordered.sh
executable file
·24 lines (19 loc) · 1.09 KB
/
exec-enrich-ordered.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env bash
# I want to use enrich_pipeline to enrich an object like so:
#
# Stage 1: { "stage_one": 1 }
# Stage 2: { "stage_one": 1, "stage_two": 2 }
# Stage 3: { "stage_one": 1, "stage_two": 2, "stage_three": 3 }
#
# But it does not work. The actual final result is:
# Stage 3: { "stage_one": 1, "stage_two": 2, "stage_three": 1 }
#
# The "stage_three" value should be 3 but it is 1.
echo '{ "stage_one": 1 }' | jq 'include "mylib"; . as $sub | exec_fns_foreach_obj([stage_two, stage_three]; $sub)'
# UPDATE: it works with the exec_fns_foreach_obj function! See belows
# This kind of does something
# echo '{ "stage_one": 1 }' | jq 'include "mylib"; . | exec_fns_foreach([stage_two, stage_three]; { "stage_one": 1 })'
# This kind of does something even better and is more DRY
#echo '{ "stage_one": 100 }' | jq 'include "mylib"; . as $sub | exec_fns_foreach([stage_two, stage_three]; $sub)'
# SUCCESS. UPDATE: not quite actually, need a conditional check so as to only emit the last item
#echo '{ "stage_one": 1 }' | jq 'include "mylib"; . as $sub | exec_fns_foreach_obj([stage_two, stage_three]; $sub)'