Thibault Jouan f0e144cebd Refactor and simplify recipe DSL evaluation usages:
Remove most of recipe evaluation code in Recipe class, and rely on
Recipe::DSL to get evaluated recipes.

* Remove Recipe#evaluate call from CLI, rely on
  Recipe.evaluate_from_file to get the evaluated recipe;
* Implement Recipe.evaluate_from_file(filepath, env);
* Implement Recipe::DSL.evaluate(code, env);
* Remove code and filepath accessor on Recipe;
* Remove Recipe.from_file and Recipe#evaluate methods;
* Move task evaluations in Recipe::DSL#evaluate;
* Modify Recipe constructor so that it accepts tasks as argument.
2013-08-14 19:48:43 +00:00

44 lines
776 B
Ruby

module Producer
module Core
class CLI
attr_reader :arguments
USAGE = "Usage: #{File.basename $0} recipe_file"
def initialize(arguments, stdout = $stdout)
@stdout = stdout
@arguments = arguments
end
def run!
check_arguments!
worker.process recipe.tasks
end
def check_arguments!
print_usage_and_exit(64) unless @arguments.length == 1
end
def env
@env ||= Env.new
end
def recipe
@recipe ||= Recipe.evaluate_from_file(@arguments.first, env)
end
def worker
@worker ||= Worker.new
end
private
def print_usage_and_exit(status)
@stdout.puts USAGE
exit status
end
end
end
end