Skip to content

Commit 3b27d8b

Browse files
authored
Merge pull request #361 from DannyBen/fix/initialize-bash
Fix initialize.bash not being injected
2 parents 9199d9a + 325791c commit 3b27d8b

File tree

11 files changed

+56
-2
lines changed

11 files changed

+56
-2
lines changed

lib/bashly/concerns/renderable.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def view_marker(id = nil)
1818
# Reads a file from the userspace (Settings.source_dir) and returns
1919
# its contents. If the file is not found, returns a string with a hint.
2020
def load_user_file(file, placeholder: true)
21-
path = "#{Settings.source_dir}/#{file}"
21+
path = user_file_path file
2222

2323
content = if File.exist? path
2424
File.read(path).remove_front_matter
@@ -31,6 +31,14 @@ def load_user_file(file, placeholder: true)
3131
Settings.production? ? content : "#{view_marker path}\n#{content}"
3232
end
3333

34+
def user_file_path(file)
35+
path = "#{Settings.source_dir}/#{file}"
36+
ext = ".#{Settings.partials_extension}"
37+
return path if path.end_with? ext
38+
39+
"#{path}#{ext}"
40+
end
41+
3442
private
3543

3644
def view_path(view)

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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,27 @@
332332
end
333333
end
334334

335+
describe '#user_file_path' do
336+
it 'returns the path to the user file' do
337+
expect(subject.user_file_path 'test.sh').to eq 'spec/tmp/src/test.sh'
338+
end
339+
340+
context 'when the file argument does not end with .sh extension' do
341+
it 'returns the path with .sh appended' do
342+
expect(subject.user_file_path 'test').to eq 'spec/tmp/src/test.sh'
343+
end
344+
end
345+
346+
context 'when partials_extension is set and the argument does not end with the selected extension' do
347+
before { Settings.partials_extension = 'bash' }
348+
after { Settings.partials_extension = 'sh' }
349+
350+
it 'returns the path with the selected extension appended' do
351+
expect(subject.user_file_path 'test').to eq 'spec/tmp/src/test.bash'
352+
end
353+
end
354+
end
355+
335356
describe '#required_args' do
336357
it 'returns an array of only the required Argument objects' do
337358
expect(subject.required_args.size).to eq 1
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)