Skip to content

Commit ad8605d

Browse files
committed
- Add the ability to choose .bash as the partials extension
1 parent b551e14 commit ad8605d

File tree

7 files changed

+42
-34
lines changed

7 files changed

+42
-34
lines changed

lib/bashly/commands/generate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ 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}", command.render(:default_initialize_script)
134134

135135
if command.commands.empty?
136136
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/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/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

lib/bashly/templates/settings.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ compact_short_flags: true
3030
# - production generate a smaller script, without file markers
3131
# - development generate with file markers
3232
env: development
33+
34+
# The extension to use when reading/writing partial script snippets.
35+
partials_extension: sh

0 commit comments

Comments
 (0)