lib/licensed/commands/command.rb in licensed-2.4.0 vs lib/licensed/commands/command.rb in licensed-2.5.0

- old
+ new

@@ -4,35 +4,48 @@ class Command attr_reader :config attr_reader :reporter attr_reader :options - def initialize(config:, reporter:) + def initialize(config:) @config = config - @reporter = reporter end # Run the command # # options - Options to run the command with # # Returns whether the command was a success def run(**options) @options = options + @reporter = create_reporter(options) begin - result = reporter.report_run(self) do + result = reporter.report_run(self) do |report| + # allow additional report data to be given by commands + yield report if block_given? + config.apps.sort_by { |app| app["name"] } .map { |app| run_app(app) } .all? end ensure @options = nil + @reporter = nil end result end + # Create a reporter to use during a command run + # + # options - The options the command was run with + # + # Raises an error + def create_reporter(options) + raise "`create_reporter` must be implemented by commands" + end + protected # Run the command for all enabled sources for an application configuration, # recording results in a report. # @@ -41,10 +54,13 @@ # Returns whether the command succeeded for the application. def run_app(app) reporter.report_app(app) do |report| Dir.chdir app.source_path do begin + # allow additional report data to be given by commands + yield report if block_given? + app.sources.select(&:enabled?) .sort_by { |source| source.class.type } .map { |source| run_source(app, source) }.all? rescue Licensed::Shell::Error => err report.errors << err.message @@ -62,10 +78,13 @@ # # Returns whether the command succeeded for the dependency source enumerator def run_source(app, source) reporter.report_source(source) do |report| begin + # allow additional report data to be given by commands + yield report if block_given? + source.dependencies.sort_by { |dependency| dependency.name } .map { |dependency| run_dependency(app, source, dependency) } .all? rescue Licensed::Shell::Error => err report.errors << err.message @@ -92,9 +111,12 @@ report.errors.concat(dependency.errors) return false end begin + # allow additional report data to be given by commands + yield report if block_given? + evaluate_dependency(app, source, dependency, report) rescue Licensed::Shell::Error => err report.errors << err.message false end