Skip to content

Commit eb08b55

Browse files
authored
Merge pull request #308 from DannyBen/add/configurable-extension
Add the ability to choose .bash as the partials extension
2 parents b551e14 + 7bf5e35 commit eb08b55

File tree

17 files changed

+201
-42
lines changed

17 files changed

+201
-42
lines changed

.rubocop.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ inherit_gem:
99

1010
AllCops:
1111
TargetRubyVersion: 2.7
12-
SuggestExtensions: false
12+
Exclude:
13+
- debug.rb
14+
- dev/**/*
1315

1416
# The `ConfigValidator` class is a DSL, let it be
1517
Metrics/AbcSize: { Exclude: [lib/bashly/config_validator.rb] }

lib/bashly/commands/add.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ class Add < Base
3434
command 'comp', 'Generate a bash completions script or function.'
3535
command 'config', 'Add standard functions for handling INI files to the lib directory.'
3636
command 'help', 'Add a help command, in addition to the standard --help flag.'
37-
command 'lib', 'Create the additional lib directory for additional user scripts. All *.sh scripts in this ' \
38-
'folder will be included in the final bash script.'
37+
command 'lib', <<~USAGE
38+
Create the lib directory for any additional user scripts.
39+
All *.sh scripts in this directory will be included in the final bash script.
40+
Note that if you configured a different partials_extension, then the extensions of the files in this directory need to match.
41+
USAGE
3942

4043
command 'settings', 'Copy a sample settings.yml file to your project, allowing you to customize some ' \
4144
'bashly options.'

lib/bashly/commands/generate.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ def upgrade!(existing_file, library_name, *args)
130130
def create_user_files
131131
quiet_say "creating user files in !txtgrn!#{Settings.source_dir}"
132132

133-
create_file "#{Settings.source_dir}/initialize.sh", command.render(:default_initialize_script)
133+
create_file "#{Settings.source_dir}/initialize.#{Settings.partials_extension}",
134+
command.render(:default_initialize_script)
134135

135136
if command.commands.empty?
136137
create_root_command_file

lib/bashly/libraries.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
colors:
22
files:
33
- source: "templates/lib/colors.sh"
4-
target: "%{user_lib_dir}/colors.sh"
4+
target: "%{user_lib_dir}/colors.%{user_ext}"
55

66
completions: :CompletionsFunction
77
completions_script: :CompletionsScript
@@ -10,14 +10,14 @@ completions_yaml: :CompletionsYAML
1010
config:
1111
files:
1212
- source: "templates/lib/config.sh"
13-
target: "%{user_lib_dir}/config.sh"
13+
target: "%{user_lib_dir}/config.%{user_ext}"
1414

1515
help: :Help
1616

1717
lib:
1818
files:
1919
- source: "templates/lib/sample_function.sh"
20-
target: "%{user_lib_dir}/sample_function.sh"
20+
target: "%{user_lib_dir}/sample_function.%{user_ext}"
2121

2222
settings:
2323
files:
@@ -46,15 +46,15 @@ test:
4646
validations:
4747
files:
4848
- source: "templates/lib/validations/validate_dir_exists.sh"
49-
target: "%{user_lib_dir}/validations/validate_dir_exists.sh"
49+
target: "%{user_lib_dir}/validations/validate_dir_exists.%{user_ext}"
5050
- source: "templates/lib/validations/validate_file_exists.sh"
51-
target: "%{user_lib_dir}/validations/validate_file_exists.sh"
51+
target: "%{user_lib_dir}/validations/validate_file_exists.%{user_ext}"
5252
- source: "templates/lib/validations/validate_integer.sh"
53-
target: "%{user_lib_dir}/validations/validate_integer.sh"
53+
target: "%{user_lib_dir}/validations/validate_integer.%{user_ext}"
5454
- source: "templates/lib/validations/validate_not_empty.sh"
55-
target: "%{user_lib_dir}/validations/validate_not_empty.sh"
55+
target: "%{user_lib_dir}/validations/validate_not_empty.%{user_ext}"
5656

5757
yaml:
5858
files:
5959
- source: "templates/lib/yaml.sh"
60-
target: "%{user_lib_dir}/yaml.sh"
60+
target: "%{user_lib_dir}/yaml.%{user_ext}"

lib/bashly/libraries/completions_function.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class CompletionsFunction < Base
44
def files
55
[
66
{
7-
path: "#{Settings.full_lib_dir}/#{function_name}.sh",
7+
path: "#{Settings.full_lib_dir}/#{function_name}.#{Settings.partials_extension}",
88
content: completions_function_code(function_name),
99
},
1010
]

lib/bashly/libraries/help.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Help < Base
66
def files
77
[
88
{
9-
path: "#{Settings.source_dir}/help_command.sh",
9+
path: "#{Settings.source_dir}/help_command.#{Settings.partials_extension}",
1010
content: help_command,
1111
},
1212
]

lib/bashly/library.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def target_file_args
6363
user_source_dir: Settings.source_dir,
6464
user_target_dir: Settings.target_dir,
6565
user_lib_dir: Settings.full_lib_dir,
66+
user_ext: Settings.partials_extension,
6667
}
6768
end
6869
end

lib/bashly/script/command.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def examples
156156
# Returns the bash filename that is expected to hold the user code
157157
# for this command
158158
def filename
159-
options['filename'] || "#{action_name.to_underscore}_command.sh"
159+
options['filename'] || "#{action_name.to_underscore}_command.#{Settings.partials_extension}"
160160
end
161161

162162
# Returns an array of Flags
@@ -281,7 +281,7 @@ def usage_string_args
281281
# This is meant to provide the user with the ability to add custom
282282
# functions
283283
def user_lib
284-
@user_lib ||= Dir["#{Settings.full_lib_dir}/**/*.sh"].sort
284+
@user_lib ||= Dir["#{Settings.full_lib_dir}/**/*.#{Settings.partials_extension}"].sort
285285
end
286286

287287
# Returns an array of all the args with a whitelist

lib/bashly/script/wrapper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def body
4949
end
5050

5151
def custom_header_path
52-
@custom_header_path ||= "#{Settings.source_dir}/header.sh"
52+
@custom_header_path ||= "#{Settings.source_dir}/header.#{Settings.partials_extension}"
5353
end
5454
end
5555
end

lib/bashly/settings.rb

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,51 @@ class Settings
33
class << self
44
include AssetHelper
55

6-
attr_writer :compact_short_flags, :source_dir, :target_dir,
7-
:lib_dir, :strict, :tab_indent
6+
attr_writer :compact_short_flags, :lib_dir, :partials_extension,
7+
:source_dir, :strict, :tab_indent, :target_dir
88

9-
def source_dir
10-
@source_dir ||= get :source_dir
9+
def compact_short_flags
10+
@compact_short_flags ||= get :compact_short_flags
1111
end
1212

13-
def target_dir
14-
@target_dir ||= get :target_dir
13+
def env
14+
@env ||= get(:env)&.to_sym
1515
end
1616

17-
def lib_dir
18-
@lib_dir ||= get :lib_dir
17+
def env=(value)
18+
@env = value&.to_sym
1919
end
2020

21-
def strict
22-
@strict ||= get :strict
21+
def full_lib_dir
22+
"#{source_dir}/#{lib_dir}"
2323
end
2424

25-
def tab_indent
26-
@tab_indent ||= get :tab_indent
25+
def lib_dir
26+
@lib_dir ||= get :lib_dir
2727
end
2828

29-
def compact_short_flags
30-
@compact_short_flags ||= get :compact_short_flags
29+
def partials_extension
30+
@partials_extension ||= get :partials_extension
3131
end
3232

33-
def env
34-
@env ||= get(:env)&.to_sym
33+
def production?
34+
env == :production
3535
end
3636

37-
def env=(value)
38-
@env = value&.to_sym
37+
def source_dir
38+
@source_dir ||= get :source_dir
3939
end
4040

41-
def production?
42-
env == :production
41+
def strict
42+
@strict ||= get :strict
4343
end
4444

45-
def full_lib_dir
46-
"#{source_dir}/#{lib_dir}"
45+
def tab_indent
46+
@tab_indent ||= get :tab_indent
47+
end
48+
49+
def target_dir
50+
@target_dir ||= get :target_dir
4751
end
4852

4953
private

0 commit comments

Comments
 (0)