class Spud::Driver

Attributes

subprocess_pid[R]

Public Class Methods

new() click to toggle source
# File lib/spud/driver.rb, line 20
def initialize
  @subprocess_pid = nil
end

Public Instance Methods

debug?() click to toggle source
# File lib/spud/driver.rb, line 70
def debug?
  @debug ||= ENV.key?('SPUD_DEBUG') && ENV['SPUD_DEBUG'] != 'false'
end
invoke(name, ordered, named) click to toggle source
# File lib/spud/driver.rb, line 60
def invoke(name, ordered, named)
  get_task(name).invoke(ordered, stringify_keys(named))
end
register_subprocess(pid) click to toggle source
# File lib/spud/driver.rb, line 65
def register_subprocess(pid)
  @subprocess_pid = pid
end
run!() click to toggle source
# File lib/spud/driver.rb, line 25
def run!
  if debug?
    puts "options: #{options.inspect}"
    puts "task: #{args.task}"
    puts "ordered: #{args.ordered}"
    puts "named: #{args.named}"
  end

  if options.help?
    Help.print!
    return
  end

  unless args.task
    lister.list_tasks!
    return
  end

  if options.inspect?
    inspect!
    return
  end

  invoke!
rescue Error => error
  puts error.message
  raise error if debug?
rescue Interrupt => error
  puts "handled interrupt #{error}" if debug?
rescue => error
  puts "fatal: #{error.message}"
  raise error if debug?
end

Private Instance Methods

args() click to toggle source
# File lib/spud/driver.rb, line 122
def args
  @args ||= CLI::Parser.parse!
end
get_task(task_name) click to toggle source
# File lib/spud/driver.rb, line 105
def get_task(task_name)
  task = tasks[task_name]
  raise Error, "no task found for '#{task_name}'" unless task

  task
end
inspect!() click to toggle source
# File lib/spud/driver.rb, line 100
def inspect!
  puts get_task(T.must(args.task)).details
end
invoke!() click to toggle source
# File lib/spud/driver.rb, line 77
def invoke!
  task_name = T.must(args.task)
  task = get_task(task_name)

  watches = options.watches
  watches = task.watches if watches.empty?

  if watches.empty?
    invoke(task_name, args.ordered, args.named)
  else
    raise Error, "watches only supported for Spud tasks" unless task.is_a?(TaskRunners::SpudTaskRunner::Task)

    Watch.run!(
      driver: self,
      task: task_name,
      ordered: args.ordered,
      named: args.named,
      watches: watches,
    )
  end
end
lister() click to toggle source
# File lib/spud/driver.rb, line 127
def lister
  @lister ||= Lister.new(tasks.values)
end
options() click to toggle source
# File lib/spud/driver.rb, line 132
def options
  args.options
end
stringify_keys(hash) click to toggle source
# File lib/spud/driver.rb, line 137
def stringify_keys(hash)
  hash.each_with_object({}) { |(key, value), new_hash| new_hash[key.to_s] = value }
end
tasks() click to toggle source
# File lib/spud/driver.rb, line 113
def tasks
  @tasks ||= TaskRunners.get.each_with_object({}) do |task_runner, tasks|
    task_runner.tasks(self).each do |task|
      tasks[task.name] = task
    end
  end
end