Skip to content

Commit 65107a0

Browse files
authored
Merge pull request #193 from DannyBen/add/lib-path-setting
Add `BASHLY_LIB_DIR` configuration variable
2 parents 4da5054 + 7fdc3cf commit 65107a0

File tree

18 files changed

+103
-16
lines changed

18 files changed

+103
-16
lines changed

lib/bashly/commands/add.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Add < Base
3232
example "bashly add comp script completions.bash"
3333

3434
environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
35+
environment "BASHLY_LIB_DIR", "The path to use for creating the library files, relative to the source dir [default: lib]"
3536

3637
def strings_command
3738
add_lib 'strings'

lib/bashly/commands/generate.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Generate < Base
1313

1414
environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
1515
environment "BASHLY_TARGET_DIR", "The path to use for creating the bash script [default: .]"
16+
environment "BASHLY_LIB_DIR", "The path to use for upgrading library files, relative to the source dir [default: lib]"
1617
environment "BASHLY_STRICT", "When not empty, enable bash strict mode (set -euo pipefail)"
1718

1819
example "bashly generate --force"

lib/bashly/libraries.yml

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

66
config:
77
files:
88
- source: "templates/lib/config.sh"
9-
target: "%{user_source_dir}/lib/config.sh"
9+
target: "%{user_lib_dir}/config.sh"
1010

1111
yaml:
1212
files:
1313
- source: "templates/lib/yaml.sh"
14-
target: "%{user_source_dir}/lib/yaml.sh"
14+
target: "%{user_lib_dir}/yaml.sh"
1515

1616
lib:
1717
files:
1818
- source: "templates/lib/sample_function.sh"
19-
target: "%{user_source_dir}/lib/sample_function.sh"
19+
target: "%{user_lib_dir}/sample_function.sh"
2020

2121
strings:
2222
files:
@@ -41,13 +41,13 @@ test:
4141
validations:
4242
files:
4343
- source: "templates/lib/validations/validate_dir_exists.sh"
44-
target: "%{user_source_dir}/lib/validations/validate_dir_exists.sh"
44+
target: "%{user_lib_dir}/validations/validate_dir_exists.sh"
4545
- source: "templates/lib/validations/validate_file_exists.sh"
46-
target: "%{user_source_dir}/lib/validations/validate_file_exists.sh"
46+
target: "%{user_lib_dir}/validations/validate_file_exists.sh"
4747
- source: "templates/lib/validations/validate_integer.sh"
48-
target: "%{user_source_dir}/lib/validations/validate_integer.sh"
48+
target: "%{user_lib_dir}/validations/validate_integer.sh"
4949
- source: "templates/lib/validations/validate_not_empty.sh"
50-
target: "%{user_source_dir}/lib/validations/validate_not_empty.sh"
50+
target: "%{user_lib_dir}/validations/validate_not_empty.sh"
5151

5252
completions: :CompletionsFunction
5353
completions_script: :CompletionsScript

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 < Completions
44
def files
55
[
66
{
7-
path: "#{Settings.source_dir}/lib/#{function_name}.sh",
7+
path: "#{Settings.full_lib_dir}/#{function_name}.sh",
88
content: completions_function_code(function_name)
99
}
1010
]

lib/bashly/library.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def config
5959
def target_file_args
6060
{
6161
user_source_dir: Settings.source_dir,
62-
user_target_dir: Settings.target_dir
62+
user_target_dir: Settings.target_dir,
63+
user_lib_dir: Settings.full_lib_dir,
6364
}
6465
end
6566
end

lib/bashly/script/command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def usage_string
125125
# This is meant to provide the user with the ability to add custom
126126
# functions
127127
def user_lib
128-
@user_lib ||= Dir["#{Settings.source_dir}/lib/**/*.sh"].sort
128+
@user_lib ||= Dir["#{Settings.full_lib_dir}/**/*.sh"].sort
129129
end
130130

131131
# Raise an exception if there are some serious issues with the command

lib/bashly/settings.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Bashly
22
class Settings
33
class << self
4-
attr_writer :source_dir, :target_dir
4+
attr_writer :source_dir, :target_dir, :lib_dir, :strict
55

66
def source_dir
77
@source_dir ||= ENV['BASHLY_SOURCE_DIR'] || 'src'
@@ -10,6 +10,18 @@ def source_dir
1010
def target_dir
1111
@target_dir ||= ENV['BASHLY_TARGET_DIR'] || '.'
1212
end
13+
14+
def lib_dir
15+
@lib_dir ||= ENV['BASHLY_LIB_DIR'] || 'lib'
16+
end
17+
18+
def strict
19+
@strict ||= ENV['BASHLY_STRICT']
20+
end
21+
22+
def full_lib_dir
23+
"#{source_dir}/#{lib_dir}"
24+
end
1325
end
1426
end
1527
end

lib/bashly/views/command/initialize.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
initialize() {
33
version="<%= version %>"
44
long_usage=''
5-
<%= ENV['BASHLY_STRICT'] ? "set -euo pipefail" : "set -e" %>
5+
<%= Settings.strict ? "set -euo pipefail" : "set -e" %>
66

77
<%= load_user_file("initialize.sh", placeholder: false).indent 2 %>
88
}

spec/approvals/cli/add/help

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ Environment Variables:
6262
BASHLY_SOURCE_DIR
6363
The path containing the bashly configuration and source files [default: src]
6464

65+
BASHLY_LIB_DIR
66+
The path to use for creating the library files, relative to the source dir
67+
[default: lib]
68+
6569
Examples:
6670
bashly add strings --force
6771
bashly add comp function

spec/approvals/cli/generate/help

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ Environment Variables:
2727
BASHLY_TARGET_DIR
2828
The path to use for creating the bash script [default: .]
2929

30+
BASHLY_LIB_DIR
31+
The path to use for upgrading library files, relative to the source dir
32+
[default: lib]
33+
3034
BASHLY_STRICT
3135
When not empty, enable bash strict mode (set -euo pipefail)
3236

0 commit comments

Comments
 (0)