Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions lib/bashly/views/command/initialize.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,5 @@ initialize() {
long_usage=''
set -e

if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
printf "<%= strings[:unsupported_bash_version] -%>\n"
exit 1
fi

<%= load_user_file("initialize.sh", placeholder: false).indent 2 %>
}
5 changes: 5 additions & 0 deletions lib/bashly/views/script/header.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#!/usr/bin/env bash
# This script was generated by bashly (https://github.com/DannyBen/bashly)
# Modifying it manually is not recommended

if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
printf "<%= strings[:unsupported_bash_version] -%>\n"
exit 1
fi
15 changes: 15 additions & 0 deletions spec/approvals/examples/bash-3-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
creating user files in src
skipped src/initialize.sh (exists)
skipped src/test_command.sh (exists)
created ./cli
run ./cli --help to test your bash script
cli - Sample application

Usage:
cli [command]
cli [command] --help | -h
cli --version | -v

Commands:
test Run test

2 changes: 1 addition & 1 deletion spec/bashly/commands/generate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
expect { subject.run %w[generate -w function] }.to output_approval('cli/generate/wrap-function')
expect(File).to exist(cli_script)
lines = File.readlines cli_script
expect(lines[5]).to eq "function() {\n"
expect(lines[10]).to eq "function() {\n"
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/bashly/integration/bash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
before { system "docker pull bash:3 >/dev/null" }

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

Dir.chdir "examples/minimal" do
Dir.chdir "spec/fixtures/workspaces/bash-3-syntax" do
system "bashly generate 2>&1 >/dev/null"
expect(`#{command} 2>&1`).to match_approval('bash/error')
end
Expand Down
6 changes: 3 additions & 3 deletions spec/bashly/models/script_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
lines = subject.code.split "\n"
expect(lines[0]).to eq '#!/usr/bin/env bash'
expect(lines[1]).to start_with '# This script was generated by'
expect(lines[5]).to eq 'root_command() {'
expect(lines[10]).to eq 'root_command() {'
expect(lines[-1]).to eq 'run "$@"'
end
end
Expand All @@ -24,8 +24,8 @@
lines = subject.code.split "\n"
expect(lines[0]).to eq '#!/usr/bin/env bash'
expect(lines[1]).to start_with '# This script was generated by'
expect(lines[5]).to eq 'my_super_function() {'
expect(lines[6]).to eq ' # :command.root_command'
expect(lines[10]).to eq 'my_super_function() {'
expect(lines[11]).to eq ' # :command.root_command'
expect(lines[-1]).to eq '(return 0 2>/dev/null) || my_super_function "$@"'
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/workspaces/bash-3-syntax/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cli
1 change: 1 addition & 0 deletions spec/fixtures/workspaces/bash-3-syntax/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This fixture tests that bash 3 exits with a helpful error even when faced with syntax it doesn't understand
7 changes: 7 additions & 0 deletions spec/fixtures/workspaces/bash-3-syntax/src/bashly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: cli
help: Sample application
version: 0.1.0

commands:
- name: test
help: Run test
6 changes: 6 additions & 0 deletions spec/fixtures/workspaces/bash-3-syntax/src/initialize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code here runs inside the initialize() function
# Use it for anything that you need to run before any other function, like
# setting environment vairables:
# CONFIG_FILE=settings.ini
#
# Feel free to empty (but not delete) this file.
4 changes: 4 additions & 0 deletions spec/fixtures/workspaces/bash-3-syntax/src/test_command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# this syntax (`[[ -v`) cannot be parsed by bash 3
if [[ -v missingno ]]; then
echo the variable was not defined
fi
8 changes: 8 additions & 0 deletions spec/fixtures/workspaces/bash-3-syntax/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

# This fixture tests Bash 4+-only syntax
# It is executed as part of the Runfile examples test

bundle exec bashly generate

./cli
10 changes: 5 additions & 5 deletions spec/fixtures/workspaces/flag-args-with-dash/argflag
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# This script was generated by bashly (https://github.com/DannyBen/bashly)
# Modifying it manually is not recommended

if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
printf "bash version 4 or higher is required\n"
exit 1
fi

# :command.root_command
root_command() {
# :src/root_command.sh
Expand Down Expand Up @@ -170,11 +175,6 @@ initialize() {
long_usage=''
set -e

if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
printf "bash version 4 or higher is required\n"
exit 1
fi

# :src/initialize.sh
# Code here runs inside the initialize() function
# Use it for anything that you need to run before any other function, like
Expand Down