Skip to content

Commit 8048e64

Browse files
committed
- Add ability to override raw input
1 parent 9726e44 commit 8048e64

File tree

7 files changed

+40
-10
lines changed

7 files changed

+40
-10
lines changed

examples/hooks/src/initialize.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@
33
## Any code here will be placed inside the `initialize()` function and called
44
## before running anything else.
55
##
6+
## - The raw command line arguments are available to you here as "$@"
7+
## - If you wish to override the raw arguments before they are processed,
8+
## simply define an array named `input_override`:
9+
##
10+
## declare -g -a input_override=("modified" "args")
11+
##
612
## You can safely delete this file if you do not need it.

lib/bashly/libraries/hooks/initialize.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@
33
## Any code here will be placed inside the `initialize()` function and called
44
## before running anything else.
55
##
6+
## - The raw command line arguments are available to you here as "$@"
7+
## - If you wish to override the raw arguments before they are processed,
8+
## simply define an array named `input_override`:
9+
##
10+
## declare -g -a input_override=("modified" "args")
11+
##
612
## You can safely delete this file if you do not need it.

lib/bashly/views/command/master_script.gtx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
>
1616
if Settings.enabled? :sourcing
1717
> if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
18-
> {{ Settings.function_name :initialize }}
19-
> {{ Settings.function_name :run }} "$@"
18+
= render(:start).indent 2
2019
> fi
2120
else
22-
> {{ Settings.function_name :initialize }}
23-
> {{ Settings.function_name :run }} "$@"
21+
= render :start
2422
end
2523
>

lib/bashly/views/command/start.gtx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
= view_marker
2+
3+
> {{ Settings.function_name :initialize }} "$@"
4+
> if declare -p input_override &>/dev/null; then
5+
> {{ Settings.function_name :run }} "${input_override[@]}"
6+
> else
7+
> {{ Settings.function_name :run }} "$@"
8+
> fi

spec/approvals/examples/stacktrace

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ Examples:
4747

4848
+ ./download something
4949
./download: line 15: no_such_command: command not found
50-
./download:15 in `root_command`: no_such_command
50+
./download:<line> in `root_command`: no_such_command
5151

5252
Stack trace:
53-
from ./download:15 in `root_command`
54-
from ./download:259 in `run`
55-
from ./download:265 in `main`
53+
from ./download:<line> in `root_command`
54+
from ./download:<line> in `run`
55+
from ./download:<line> in `main`

spec/bashly/integration/examples_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
# Allow up to a certain string distance from the approval text in CI
2525
leeway = ENV['CI'] ? 40 : 0
2626

27+
# For certain examples, allow some exceptions (replacements) since they
28+
# are too volatile (e.g. line number changes)
29+
exceptions = {
30+
'examples/stacktrace' => [/download:\d+/, 'download:<line>']
31+
}
32+
2733
test_cases.each do |example|
2834
approval_name = example.gsub 'spec/fixtures/workspaces', 'fixtures'
2935

@@ -41,7 +47,13 @@
4147
# - The "+ ..." shell messages driven by `set -x` have no space
4248
# - The order of our `inspect_args` sometimes differs
4349
# - The result of the `deps` array sometimes differs
44-
expect(output).to match_approval(approval_name).diff(leeway)
50+
# In addition, for some examples we allow exceptions, so the below is
51+
# just a more granular version of:
52+
# expect(output).to match_approval(approval_name).diff(leeway).except(*except)
53+
match_output = match_approval(approval_name).diff(leeway)
54+
except = exceptions[example]
55+
match_output = match_output.except(*except) if except
56+
expect(output).to match_output
4557
end
4658
end
4759
end

spec/bashly/script/wrapper_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
lines = subject.code.split "\n"
1212
expect(lines[0..13].join("\n")).to match_approval('script/wrapper/code')
1313
.except(/\d+\.\d+\.\d+(\.rc\d)?/)
14-
expect(lines[-2]).to eq ' run "$@"'
14+
expect(lines[-3]).to eq ' run "$@"'
1515
end
1616
end
1717

0 commit comments

Comments
 (0)