Skip to content

Commit c0ce610

Browse files
committed
- Add 'bashly add hooks' command
1 parent 7665904 commit c0ce610

File tree

6 files changed

+41
-0
lines changed

6 files changed

+41
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## after hook
2+
##
3+
## Any code here will be placed inside an `after_hook()` function and called
4+
## after running any command.
5+
##
6+
## You can safely delete this file if you do not need it.
7+
echo "Thank you for using my script"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## before hook
2+
##
3+
## Any code here will be placed inside a `before_hook()` function and called
4+
## before running any command (but after processing its arguments).
5+
##
6+
## You can safely delete this file if you do not need it.
7+
inspect_args

lib/bashly/libraries/libraries.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ help:
2929
help: Add a help command, in addition to the standard --help flag.
3030
handler: Bashly::Libraries::Help
3131

32+
hooks:
33+
help: Add placeholders for before/after hooks which are executed before/after any command.
34+
files:
35+
- source: "hooks/before.sh"
36+
target: "%{user_source_dir}/before.%{user_ext}"
37+
- source: "hooks/after.sh"
38+
target: "%{user_source_dir}/after.%{user_ext}"
39+
3240
lib:
3341
help: |-
3442
Create the lib directory for any additional user scripts.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
created spec/tmp/src/before.sh
2+
created spec/tmp/src/after.sh

spec/approvals/cli/add/list

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ config
1717
help
1818
Add a help command, in addition to the standard --help flag.
1919

20+
hooks
21+
Add placeholders for before/after hooks which are executed before/after any
22+
command.
23+
2024
lib
2125
Create the lib directory for any additional user scripts.
2226
All *.sh scripts in this directory will be included in the final bash script.

spec/bashly/commands/add_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@
9494
end
9595
end
9696

97+
context 'with hooks command' do
98+
let(:before_hook_file) { "#{source_dir}/before.sh" }
99+
let(:after_hook_file) { "#{source_dir}/after.sh" }
100+
101+
before { reset_tmp_dir init: true }
102+
103+
it 'copies before.sh and after.sh to the user space' do
104+
expect { subject.execute %w[add hooks] }.to output_approval('cli/add/hooks_command')
105+
expect(File).to exist(before_hook_file)
106+
expect(File).to exist(after_hook_file)
107+
end
108+
end
109+
97110
context 'with lib command' do
98111
let(:lib_file) { "#{source_dir}/lib/sample_function.sh" }
99112

0 commit comments

Comments
 (0)