Implement dry run mode

This commit is contained in:
Thibault Jouan
2014-05-25 12:11:38 +00:00
parent 332bb1a416
commit 87a3ead082
8 changed files with 57 additions and 9 deletions

View File

@@ -3,7 +3,7 @@ module Producer
class CLI
ArgumentError = Class.new(::ArgumentError)
USAGE = "Usage: #{File.basename $0} [-v] recipe_file"
USAGE = "Usage: #{File.basename $0} [-v] [-n] recipe_file"
EX_USAGE = 64
@@ -33,6 +33,8 @@ module Producer
case e
when '-v'
env.log_level = Logger::INFO
when '-n'
env.dry_run = true
else
m << e
end

View File

@@ -2,13 +2,14 @@ module Producer
module Core
class Env
attr_reader :input, :output, :registry, :logger
attr_accessor :target
attr_accessor :target, :dry_run
def initialize(input: $stdin, output: $stdout, remote: nil, registry: {})
@input = input
@output = output
@registry = registry
@remote = remote
@dry_run = false
end
def remote
@@ -43,6 +44,10 @@ module Producer
def log_level=(level)
logger.level = level
end
def dry_run?
@dry_run
end
end
end
end

View File

@@ -17,7 +17,7 @@ module Producer
env.log ' condition: met'
task.actions.each do |e|
env.log " action: #{e} applying"
e.apply
e.apply unless env.dry_run?
end
else
env.log ' condition: NOT met'