Skip to content

Commit b5c3ec6

Browse files
authored
Merge pull request #353 from DannyBen/change/strict
Change settings.strict to allow any string
2 parents dfed541 + 46ef6f1 commit b5c3ec6

File tree

5 files changed

+51
-7
lines changed

5 files changed

+51
-7
lines changed

lib/bashly/libraries/settings/settings.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ config_path: "%{source_dir}/bashly.yml"
1818
# The path to use for creating the bash script
1919
target_dir: .
2020

21-
# The path to use for upgrading library files, relative to the source dir
21+
# The path to use for common library files, relative to the source dir
2222
lib_dir: lib
2323

24-
# When true, enable bash strict mode (set -euo pipefail)
24+
# Configure the bash options that will be added to the initialize function:
25+
# strict: true Bash strict mode (set -euo pipefail)
26+
# strict: false Only exit on errors (set -e)
27+
# strict: '' Do not add any 'set' directive
28+
# strict: <string> Add any other custom 'set' directive
2529
strict: false
2630

2731
# When true, the generated script will use tab indentation instead of spaces
@@ -33,11 +37,11 @@ tab_indent: false
3337
compact_short_flags: true
3438

3539
# Set to 'production' or 'development':
36-
# - production generate a smaller script, without file markers
37-
# - development generate with file markers
40+
# env: production Generate a smaller script, without file markers
41+
# env: development Generate with file markers
3842
env: development
3943

40-
# The extension to use when reading/writing partial script snippets.
44+
# The extension to use when reading/writing partial script snippets
4145
partials_extension: sh
4246

4347
# Display various usage elements in color by providing the name of the color

lib/bashly/settings.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ def strict
5555
@strict ||= get :strict
5656
end
5757

58+
def strict_string
59+
if Settings.strict.is_a? String
60+
Settings.strict
61+
elsif Settings.strict
62+
'set -euo pipefail'
63+
else
64+
'set -e'
65+
end
66+
end
67+
5868
def tab_indent
5969
@tab_indent ||= get :tab_indent
6070
end

lib/bashly/views/command/initialize.gtx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
> initialize() {
44
> version="<%= version %>"
55
> long_usage=''
6-
> {{ Settings.strict ? "set -euo pipefail" : "set -e" }}
6+
> {{ Settings.strict_string }}
77
>
88

99
if root_command?

spec/bashly/settings_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,34 @@
5555
end
5656
end
5757
end
58+
59+
describe 'strict_string' do
60+
original_value = Settings.strict
61+
62+
after { subject.strict = original_value }
63+
64+
context 'when strict is true' do
65+
before { subject.strict = true }
66+
67+
it 'returns "set -euo pipefail"' do
68+
expect(subject.strict_string).to eq 'set -euo pipefail'
69+
end
70+
end
71+
72+
context 'when strict is false' do
73+
before { subject.strict = false }
74+
75+
it 'returns "set -e"' do
76+
expect(subject.strict_string).to eq 'set -e'
77+
end
78+
end
79+
80+
context 'when strict is string' do
81+
before { subject.strict = 'set -o pipefail' }
82+
83+
it 'returns the string as is' do
84+
expect(subject.strict_string).to eq 'set -o pipefail'
85+
end
86+
end
87+
end
5888
end

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# Set up working directory for the specs
3131
Settings.source_dir = 'spec/tmp/src'
3232
Settings.target_dir = 'spec/tmp'
33-
Settings.strict = '1' # generate scripts with `set -euo pipefile`
33+
Settings.strict = true # generate scripts with `set -euo pipefail`
3434
Settings.env = :development
3535
reset_tmp_dir
3636

0 commit comments

Comments
 (0)