diff --git a/features/task_nested_tasks.feature b/features/task_nested_tasks.feature index cf9c850..95dc6ed 100644 --- a/features/task_nested_tasks.feature +++ b/features/task_nested_tasks.feature @@ -13,3 +13,8 @@ Feature: nested tasks Scenario: applies nested tasks When I successfully execute the recipe Then the output must match /\AOK/ + + Scenario: indents logging from nested tasks + When I successfully execute the recipe with option -v + Then the output must match /^ Task:.+/ + And the output must match /^ action:.+/ diff --git a/lib/producer/core/worker.rb b/lib/producer/core/worker.rb index 8d4cc70..7460992 100644 --- a/lib/producer/core/worker.rb +++ b/lib/producer/core/worker.rb @@ -14,21 +14,29 @@ module Producer tasks.each { |t| process_task t } end - def process_task(task) + def process_task(task, indent_level = 0) if task.condition_met? - @env.log "Task: `#{task}' applying..." + log "Task: `#{task}' applying...", indent_level task.actions.each do |e| case e - when Task then process_task e + when Task then process_task e, indent_level + 2 else - @env.log " action: #{e}" + log " action: #{e}", indent_level e.apply unless @env.dry_run? end end else - @env.log "Task: `#{task}' skipped" + log "Task: `#{task}' skipped", indent_level end end + + + private + + def log(message, indent_level) + message = [' ' * indent_level, message].join + @env.log message + end end end end