Skip to content

Commit bd9f534

Browse files
committed
fix: Do not automatically append --pass-by-ref when using bobject
1 parent a64c835 commit bd9f534

File tree

4 files changed

+18
-34
lines changed

4 files changed

+18
-34
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ declare -A yankee_object=([xray]=)
2727
declare -A xray_object=([whiskey]=victor [foxtrot]=)
2828
declare -a foxtrot_array=(omicron pi rho sigma)
2929

30-
bobject set-object root_object '.zulu' zulu_object
31-
bobject set-object root_object '.zulu.yankee' yankee_object
32-
bobject set-object root_object '.zulu.yankee.xray' xray_object
30+
bobject set-object --pass-by-ref root_object '.zulu' zulu_object
31+
bobject set-object --pass-by-ref root_object '.zulu.yankee' yankee_object
32+
bobject set-object --pass-by-ref root_object '.zulu.yankee.xray' xray_object
3333
bobject set-array root_object '.zulu.yankee.xray.foxtrot' foxtrot_array
3434

3535
bobject get-object root_object '.zulu.yankee.xray'

docs/errors.md

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
11
# Errors
22

3-
Depending on your operation, your object transaction may fail. This details the reasons
4-
5-
In this context, value means either "member of object" or "index of array"
6-
7-
## Get
8-
9-
- `ERROR_NOT_FOUND`
10-
- Attempted to access a value that does not exist
11-
- `ERROR_VALUE_INCORRECT_TYPE`
12-
- Attempted to access a value that has the wrong type. This can happen if the query uses `.[30]` to get an array index, but an object exists instead. It can also happen if the user writes `get-string`, and it found a non-string value after evaluating the query. It can also happen if the user writes `set-string`, and the place to write the new value already has a value of a different type
13-
- `ERROR_VOBJ_INVALID_TYPE`
14-
- The virtual object (a string that contains a reference to the real global object) had keys with unexpected values. You shouldn't get this error unless something has seriously gone wrong
15-
16-
# Handling
17-
18-
Because Bash often does the wrong thing silently, it's important to fail early when any inputs are unexpected. `bash-object` does this at every level
19-
20-
Below, if any of the assurances do not pass, `bash-object` will fail with a non-zero exit code. For some of these, `VERIFY_BASH_OBJECT` must be a variable
3+
Because Bash often does the wrong thing silently, it's important to fail early when any inputs are unexpected. Extra checks that require spawning subshells require setting the `VERIFY_BASH_OBJECT` variable. We recommend exporting it so any child Bash processes keep the verification behavior
214

5+
The following checks are performed
226

237
1. Argument parsing
248

pkg/lib/cmd/bobject.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ bobject() {
1919
bash_object.traverse-get object "$@"
2020
;;
2121
set-string)
22-
bash_object.traverse-set --pass-by-ref string "$@"
22+
bash_object.traverse-set string "$@"
2323
;;
2424
set-array)
25-
bash_object.traverse-set --pass-by-ref array "$@"
25+
bash_object.traverse-set array "$@"
2626
;;
2727
set-object)
28-
bash_object.traverse-set --pass-by-ref object "$@"
28+
bash_object.traverse-set object "$@"
2929
;;
3030
*)
3131
bash_object.util.die 'ERROR_ARGUMENTS_INVALID' "Subcommand '$subcmd' not recognized"

tests/e2e.bats

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ load './util/init.sh'
3535
for subcmd in "${subcmds[@]}"; do
3636
declare -A OBJECT=()
3737

38-
run bobject "$subcmd" 'OBJECT' '.zulu.yankee' 'xray' 'invalid'
38+
run bobject "$subcmd" --pass-by-ref 'OBJECT' '.zulu.yankee' 'xray' 'invalid'
3939

4040
assert_failure
4141
assert_line -p "Expected '4' arguments, but received '5'"
@@ -48,7 +48,7 @@ load './util/init.sh'
4848
for subcmd in "${subcmds[@]}"; do
4949
declare -A OBJECT=()
5050

51-
run bobject "$subcmd" 'OBJECT' '.zulu'
51+
run bobject "$subcmd" --pass-by-ref 'OBJECT' '.zulu'
5252

5353
assert_failure
5454
assert_line -p "Expected '4' arguments, but received '3'"
@@ -60,8 +60,8 @@ load './util/init.sh'
6060
declare -A subobj=()
6161
str='MEOW'
6262

63-
bobject set-object 'OBJECT' '.zulu' subobj
64-
bobject set-string 'OBJECT' '.zulu.yankee' str
63+
bobject set-object --pass-by-ref 'OBJECT' '.zulu' subobj
64+
bobject set-string --pass-by-ref 'OBJECT' '.zulu.yankee' str
6565
bobject get-string 'OBJECT' '.zulu.yankee'
6666

6767
assert [ "$REPLY" = 'MEOW' ]
@@ -72,8 +72,8 @@ load './util/init.sh'
7272
declare -A subobj=()
7373
str='MEOW'
7474

75-
bobject set-object 'OBJECT' '.zulu' subobj
76-
bobject set-string 'OBJECT' '.["zulu"].["yankee"]' str
75+
bobject set-object --pass-by-ref 'OBJECT' '.zulu' subobj
76+
bobject set-string --pass-by-ref 'OBJECT' '.["zulu"].["yankee"]' str
7777
bobject get-string 'OBJECT' '.["zulu"].["yankee"]'
7878

7979
assert [ "$REPLY" = 'MEOW' ]
@@ -86,10 +86,10 @@ load './util/init.sh'
8686
declare -A xray_object=([whiskey]=victor [foxtrot]=)
8787
declare -a foxtrot_array=(omicron pi rho sigma)
8888

89-
bobject set-object root_object '.zulu' zulu_object
90-
bobject set-object root_object '.zulu.yankee' yankee_object
91-
bobject set-object root_object '.zulu.yankee.xray' xray_object
92-
bobject set-array root_object '.zulu.yankee.xray.foxtrot' foxtrot_array
89+
bobject set-object --pass-by-ref root_object '.zulu' zulu_object
90+
bobject set-object --pass-by-ref root_object '.zulu.yankee' yankee_object
91+
bobject set-object --pass-by-ref root_object '.zulu.yankee.xray' xray_object
92+
bobject set-array --pass-by-ref root_object '.zulu.yankee.xray.foxtrot' foxtrot_array
9393

9494
bobject get-object root_object '.zulu.yankee.xray'
9595
assert [ "${REPLY[whiskey]}" = victor ]

0 commit comments

Comments
 (0)