Skip to content

Commit 35d99ed

Browse files
committed
- Fix initialize.bash not being injected
1 parent 9199d9a commit 35d99ed

File tree

11 files changed

+34
-1
lines changed

11 files changed

+34
-1
lines changed

lib/bashly/concerns/renderable.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def view_marker(id = nil)
1919
# its contents. If the file is not found, returns a string with a hint.
2020
def load_user_file(file, placeholder: true)
2121
path = "#{Settings.source_dir}/#{file}"
22+
ext = ".#{Settings.partials_extension}"
23+
path += ext unless path.end_with? ext
2224

2325
content = if File.exist? path
2426
File.read(path).remove_front_matter

lib/bashly/views/command/initialize.gtx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if root_command?
1010
= render(:environment_variables_default).indent 2
1111
end
1212

13-
= load_user_file("initialize.sh", placeholder: false).indent 2
13+
= load_user_file("initialize", placeholder: false).indent 2
1414

1515
> }
1616
>

spec/approvals/fixtures/initialize

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
+ bundle exec bashly generate
2+
creating user files in src
3+
skipped src/initialize.bash (exists)
4+
skipped src/root_command.bash (exists)
5+
created ./initialize
6+
run ./initialize --help to test your bash script
7+
+ ./initialize
8+
initialize called
9+
root_command called

spec/bashly/script/command_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,12 @@
330330
.to eq "# spec/tmp/src/notfound.sh\necho \"error: cannot load file\""
331331
end
332332
end
333+
334+
context 'when the provided file does not include an extension' do
335+
it 'adds the partials_extension to it' do
336+
expect(subject.load_user_file('test')).to eq "# spec/tmp/src/test.sh\nhello Command#load_user_file"
337+
end
338+
end
333339
end
334340

335341
describe '#required_args' do
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
initialize
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This fixture tests that the initialize file is included when using a custom
2+
partials_extension setting.
3+
ref: https://github.com/DannyBen/bashly/issues/360
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
partials_extension: bash
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: initialize
2+
help: Test that initialize is included when using bash extension
3+
version: 0.1.0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo "initialize called"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo "root_command called"

0 commit comments

Comments
 (0)