Implement verbose mode
This commit is contained in:
@@ -11,6 +11,14 @@ module Producer
|
||||
@env = env
|
||||
@arguments = args
|
||||
end
|
||||
|
||||
def name
|
||||
self.class.name.split('::').last.downcase
|
||||
end
|
||||
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -2,6 +2,10 @@ module Producer
|
||||
module Core
|
||||
module Actions
|
||||
class Echo < Action
|
||||
def name
|
||||
'echo'
|
||||
end
|
||||
|
||||
def apply
|
||||
output.puts arguments.first
|
||||
end
|
||||
|
@@ -2,6 +2,10 @@ module Producer
|
||||
module Core
|
||||
module Actions
|
||||
class FileAppend < Action
|
||||
def name
|
||||
'file_append'
|
||||
end
|
||||
|
||||
def apply
|
||||
fs.file_write path, combined_content
|
||||
end
|
||||
|
@@ -2,6 +2,10 @@ module Producer
|
||||
module Core
|
||||
module Actions
|
||||
class FileReplaceContent < Action
|
||||
def name
|
||||
'file_replace_content'
|
||||
end
|
||||
|
||||
def apply
|
||||
fs.file_write path, replaced_content
|
||||
end
|
||||
|
@@ -2,6 +2,10 @@ module Producer
|
||||
module Core
|
||||
module Actions
|
||||
class FileWriter < Action
|
||||
def name
|
||||
'file_write'
|
||||
end
|
||||
|
||||
def apply
|
||||
case arguments.size
|
||||
when 2
|
||||
|
@@ -2,6 +2,10 @@ module Producer
|
||||
module Core
|
||||
module Actions
|
||||
class Mkdir < Action
|
||||
def name
|
||||
'mkdir'
|
||||
end
|
||||
|
||||
def apply
|
||||
case arguments.size
|
||||
when 1
|
||||
|
@@ -2,6 +2,10 @@ module Producer
|
||||
module Core
|
||||
module Actions
|
||||
class ShellCommand < Action
|
||||
def name
|
||||
'sh'
|
||||
end
|
||||
|
||||
def apply
|
||||
remote.execute(arguments.first, output)
|
||||
end
|
||||
|
@@ -3,7 +3,7 @@ module Producer
|
||||
class CLI
|
||||
ArgumentError = Class.new(::ArgumentError)
|
||||
|
||||
USAGE = "Usage: #{File.basename $0} recipe_file"
|
||||
USAGE = "Usage: #{File.basename $0} [-v] recipe_file"
|
||||
|
||||
EX_USAGE = 64
|
||||
|
||||
@@ -11,6 +11,7 @@ module Producer
|
||||
def run!(arguments, output: $stderr)
|
||||
begin
|
||||
cli = new(arguments)
|
||||
cli.parse_arguments!
|
||||
rescue ArgumentError
|
||||
output.puts USAGE
|
||||
exit EX_USAGE
|
||||
@@ -25,6 +26,19 @@ module Producer
|
||||
@arguments = args
|
||||
@stdout = stdout
|
||||
@env = Env.new(output: stdout)
|
||||
end
|
||||
|
||||
def parse_arguments!
|
||||
@arguments = arguments.inject([]) do |m, e|
|
||||
case e
|
||||
when '-v'
|
||||
env.log_level = Logger::INFO
|
||||
else
|
||||
m << e
|
||||
end
|
||||
m
|
||||
end
|
||||
|
||||
raise ArgumentError unless arguments.any?
|
||||
end
|
||||
|
||||
|
@@ -12,7 +12,16 @@ module Producer
|
||||
end
|
||||
|
||||
def process_task(task)
|
||||
task.actions.each(&:apply) if task.condition_met?
|
||||
env.log "Task: #{task} applying"
|
||||
if task.condition_met?
|
||||
env.log ' condition: met'
|
||||
task.actions.each do |e|
|
||||
env.log " action: #{e} applying"
|
||||
e.apply
|
||||
end
|
||||
else
|
||||
env.log ' condition: NOT met'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user