-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathsettings.rb
178 lines (144 loc) · 3.93 KB
/
settings.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
module Bashly
class Settings
class << self
include AssetHelper
attr_writer(
:commands_dir,
:compact_short_flags,
:conjoined_flag_args,
:config_path,
:enable_bash3_bouncer,
:enable_deps_array,
:enable_env_var_names_array,
:enable_header_comment,
:enable_inspect_args,
:enable_view_markers,
:lib_dir,
:partials_extension,
:private_reveal_key,
:show_examples_on_error,
:source_dir,
:strict,
:tab_indent,
:target_dir,
:usage_colors
)
def commands_dir
@commands_dir ||= get :commands_dir
end
def compact_short_flags
@compact_short_flags ||= get :compact_short_flags
end
def conjoined_flag_args
@conjoined_flag_args ||= get :conjoined_flag_args
end
def config_path
@config_path ||= get(:config_path) % { source_dir: source_dir }
end
def enabled?(feature)
send(:"enable_#{feature}") == 'always' ||
(send(:"enable_#{feature}") == 'production' && production?) ||
(send(:"enable_#{feature}") == 'development' && !production?)
end
def enable_header_comment
@enable_header_comment ||= get :enable_header_comment
end
def enable_bash3_bouncer
@enable_bash3_bouncer ||= get :enable_bash3_bouncer
end
def enable_view_markers
@enable_view_markers ||= get :enable_view_markers
end
def enable_inspect_args
@enable_inspect_args ||= get :enable_inspect_args
end
def enable_deps_array
@enable_deps_array ||= get :enable_deps_array
end
def enable_env_var_names_array
@enable_env_var_names_array ||= get :enable_env_var_names_array
end
def env
@env ||= get(:env)&.to_sym
end
def env=(value)
@env = value&.to_sym
end
def full_lib_dir
"#{source_dir}/#{lib_dir}"
end
def lib_dir
@lib_dir ||= get :lib_dir
end
def partials_extension
@partials_extension ||= get :partials_extension
end
def private_reveal_key
@private_reveal_key ||= get :private_reveal_key
end
def production?
env == :production
end
def show_examples_on_error
@show_examples_on_error ||= get :show_examples_on_error
end
def source_dir
@source_dir ||= get :source_dir
end
def strict
@strict ||= get :strict
end
def strict_string
if strict.is_a? String
strict
elsif strict
'set -euo pipefail'
else
'set -e'
end
end
def tab_indent
@tab_indent ||= get :tab_indent
end
def target_dir
@target_dir ||= get :target_dir
end
def usage_colors
@usage_colors ||= get :usage_colors
end
private
def get(key)
case env_value key
when nil then config[key.to_s]
when '0', 'false', 'no' then false
when '1', 'true', 'yes' then true
else env_value key
end
end
def env_value(key)
ENV["BASHLY_#{key.upcase}"]
end
def config
@config ||= defsult_settings.merge user_settings
end
def user_settings
@user_settings ||= File.exist?(user_settings_path) ? Config.new(user_settings_path) : {}
end
def user_settings_path
@user_settings_path ||= if ENV['BASHLY_SETTINGS_PATH']
ENV['BASHLY_SETTINGS_PATH']
elsif File.exist? 'bashly-settings.yml'
'bashly-settings.yml'
else
'settings.yml'
end
end
def defsult_settings
@defsult_settings ||= Config.new default_settings_path
end
def default_settings_path
asset 'libraries/settings/settings.yml'
end
end
end
end