File tree Expand file tree Collapse file tree 4 files changed +31
-4
lines changed
Expand file tree Collapse file tree 4 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,10 @@ def indent(offset)
1212 def to_underscore
1313 gsub ( /(.)([A-Z])/ , '\1_\2' ) . gsub ( /[- ]/ , '_' ) . downcase
1414 end
15+
16+ def to_path
17+ gsub ( / / , '/' ) . downcase
18+ end
1519
1620 def wrap ( length = 80 )
1721 strip!
Original file line number Diff line number Diff line change @@ -18,9 +18,15 @@ config_path: "%{source_dir}/bashly.yml"
1818# The path to use for creating the bash script
1919target_dir : .
2020
21- # The path to use for common library files, relative to the source dir
21+ # The path to use for common library files, relative to source_dir
2222lib_dir : lib
2323
24+ # The path to use for command files, relative to source_dir
25+ # When set to nil (~), command files will be placed directly under source_dir
26+ # When set to any other string, command files will be placed under this
27+ # directory, and each command will get its own subdirectory
28+ commands_dir : ~
29+
2430# Configure the bash options that will be added to the initialize function:
2531# strict: true Bash strict mode (set -euo pipefail)
2632# strict: false Only exit on errors (set -e)
Original file line number Diff line number Diff line change @@ -159,10 +159,10 @@ def examples
159159 options [ 'examples' ] . is_a? ( Array ) ? options [ 'examples' ] : [ options [ 'examples' ] ]
160160 end
161161
162- # Returns the bash filename that is expected to hold the user code
163- # for this command
162+ # Returns the filename that is expected to hold the user code for this
163+ # command
164164 def filename
165- options [ 'filename' ] || " #{ action_name . to_underscore } _command. #{ Settings . partials_extension } "
165+ options [ 'filename' ] || implicit_filename
166166 end
167167
168168 # Returns an array of Flags
@@ -314,6 +314,18 @@ def whitelisted_args
314314 def whitelisted_flags
315315 flags . select ( &:allowed )
316316 end
317+
318+ private
319+
320+ # Returns either a flat filename (docker_status_command.sh) or a nested
321+ # path (commands/docker/status.sh)
322+ def implicit_filename
323+ if Settings . commands_dir
324+ "#{ Settings . commands_dir } /#{ action_name . to_path } .#{ Settings . partials_extension } "
325+ else
326+ "#{ action_name . to_underscore } _command.#{ Settings . partials_extension } "
327+ end
328+ end
317329 end
318330 end
319331end
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ class << self
44 include AssetHelper
55
66 attr_writer (
7+ :commands_dir ,
78 :compact_short_flags ,
89 :config_path ,
910 :lib_dir ,
@@ -15,6 +16,10 @@ class << self
1516 :usage_colors
1617 )
1718
19+ def commands_dir
20+ @commands_dir ||= get :commands_dir
21+ end
22+
1823 def compact_short_flags
1924 @compact_short_flags ||= get :compact_short_flags
2025 end
You can’t perform that action at this time.
0 commit comments