Skip to content

Commit ff1348d

Browse files
author
Kevin Paulisse
committed
Rearrange script select code a bit
1 parent 5a14e20 commit ff1348d

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

lib/octocatalog-diff/util/scriptrunner.rb

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,27 @@ def run(opts = {})
6969
# @param override_script_path [String] Optional directory with override script
7070
# @return [String] Full path to script
7171
def find_script(default_script, override_script_path = nil)
72-
if override_script_path
73-
script_test = File.join(override_script_path, File.basename(default_script))
74-
if File.file?(script_test)
75-
logger.debug "Selecting #{script_test} from override script path"
76-
return script_test
77-
else
78-
logger.debug "Did not find #{script_test} in override script path"
79-
end
80-
end
81-
82-
script = File.expand_path("../../../scripts/#{default_script}", File.dirname(__FILE__))
83-
return script if File.file?(script)
72+
script = find_script_from_override_path(default_script, override_script_path) ||
73+
File.expand_path("../../../scripts/#{default_script}", File.dirname(__FILE__))
74+
raise Errno::ENOENT, "Unable to locate script '#{script}'" unless File.file?(script)
75+
script
76+
end
8477

85-
raise Errno::ENOENT, "Unable to locate default script '#{default_script}'"
78+
# PRIVATE: Find script from override path.
79+
#
80+
# @param default_script [String] Path to script, relative to `scripts` directory
81+
# @param override_script_path [String] Optional directory
82+
# @return [String] Override script if found, else nil
83+
def find_script_from_override_path(default_script, override_script_path = nil)
84+
return unless override_script_path
85+
script_test = File.join(override_script_path, File.basename(default_script))
86+
if File.file?(script_test)
87+
logger.debug "Selecting #{script_test} from override script path"
88+
script_test
89+
else
90+
logger.debug "Did not find #{script_test} in override script path"
91+
nil
92+
end
8693
end
8794

8895
# PRIVATE: Assert that a directory exists (and is a directory). Raise error if not.

0 commit comments

Comments
 (0)