Skip to content

Commit fa8db80

Browse files
authored
Merge pull request #121 from DannyBen/finalize/pr-114
Finalize #114
2 parents d8a9e2e + 246a605 commit fa8db80

File tree

18 files changed

+105
-23
lines changed

18 files changed

+105
-23
lines changed

lib/bashly/models/script.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,16 @@ def header!
2929
if File.exist? custom_header_path
3030
File.read custom_header_path
3131
else
32-
render('header')
32+
default_header
3333
end
3434
end
3535

36+
def default_header
37+
result = render('header')
38+
result += render('bash3_bouncer') unless function_name
39+
result
40+
end
41+
3642
def body
3743
@body ||= command.render('master_script')
3844
end

lib/bashly/views/command/initialize.erb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,5 @@ initialize() {
44
long_usage=''
55
set -e
66

7-
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
8-
printf "<%= strings[:unsupported_bash_version] -%>\n"
9-
exit 1
10-
fi
11-
127
<%= load_user_file("initialize.sh", placeholder: false).indent 2 %>
138
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# :script.bash3_bouncer
2+
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
3+
printf "<%= strings[:unsupported_bash_version] -%>\n"
4+
exit 1
5+
fi

lib/bashly/views/script/header.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/usr/bin/env bash
22
# This script was generated by bashly (https://github.com/DannyBen/bashly)
33
# Modifying it manually is not recommended
4+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
# This script was generated by bashly (https://github.com/DannyBen/bashly)
3+
# Modifying it manually is not recommended
4+
5+
# :script.wrapper
6+
function() {
7+
8+
# :command.version_command
9+
version_command() {
10+
echo "$version"
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
creating user files in src
2+
skipped src/initialize.sh (exists)
3+
skipped src/test_command.sh (exists)
4+
created ./cli
5+
run ./cli --help to test your bash script
6+
cli - Sample application
7+
8+
Usage:
9+
cli [command]
10+
cli [command] --help | -h
11+
cli --version | -v
12+
13+
Commands:
14+
test Run test
15+

spec/approvals/models/script/code

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
# This script was generated by bashly (https://github.com/DannyBen/bashly)
3+
# Modifying it manually is not recommended
4+
5+
# :script.bash3_bouncer
6+
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
7+
printf "bash version 4 or higher is required\n"
8+
exit 1
9+
fi
10+
11+
# :command.root_command
12+
root_command() {
13+
# :spec/tmp/src/root_command.sh
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
# This script was generated by bashly (https://github.com/DannyBen/bashly)
3+
# Modifying it manually is not recommended
4+
5+
# :script.wrapper
6+
my_super_function() {
7+
# :command.root_command
8+
root_command() {
9+
# :spec/tmp/src/root_command.sh
10+
echo "error: cannot load file"
11+
}
12+
13+
# :command.version_command

spec/bashly/commands/generate_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@
7575
expect(success).to be true
7676
end
7777

78-
it "generates the cli script wrapped in a function" do
78+
it "generates the cli script wrapped in a function without bash3 bouncer" do
7979
expect { subject.run %w[generate -w function] }.to output_approval('cli/generate/wrap-function')
8080
expect(File).to exist(cli_script)
8181
lines = File.readlines cli_script
82-
expect(lines[5]).to eq "function() {\n"
82+
expect(lines[0..10].join).to match_approval('cli/generate/wrap-script')
8383
end
8484
end
8585

spec/bashly/integration/bash_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
before { system "docker pull bash:3 >/dev/null" }
66

77
it "errors gracefully" do
8-
command = "docker run --rm -v $PWD:/app bash:3 bash /app/download"
8+
command = "docker run --rm -v $PWD:/app bash:3 bash /app/cli"
99

10-
Dir.chdir "examples/minimal" do
10+
Dir.chdir "spec/fixtures/workspaces/bash-3-syntax" do
1111
system "bashly generate 2>&1 >/dev/null"
1212
expect(`#{command} 2>&1`).to match_approval('bash/error')
1313
end

0 commit comments

Comments
 (0)