producer-core 0.5.7 → 0.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/Rakefile +6 -3
- data/config/cucumber.yaml +2 -1
- data/features/cli/debug.feature +7 -1
- data/features/cli/dry_run.feature +5 -0
- data/features/cli/error_reporting.feature +1 -1
- data/features/cli/usage.feature +6 -10
- data/features/cli/verbose.feature +5 -0
- data/features/recipe/errors.feature +9 -0
- data/features/ssh/config.feature +1 -1
- data/features/steps/environment_steps.rb +3 -0
- data/lib/producer/core/action.rb +5 -7
- data/lib/producer/core/actions/file_append.rb +1 -1
- data/lib/producer/core/actions/file_writer.rb +1 -2
- data/lib/producer/core/actions/mkdir.rb +4 -4
- data/lib/producer/core/actions/shell_command.rb +1 -1
- data/lib/producer/core/actions/yaml_writer.rb +1 -2
- data/lib/producer/core/cli.rb +48 -37
- data/lib/producer/core/condition.rb +3 -3
- data/lib/producer/core/env.rb +5 -4
- data/lib/producer/core/error_formatter.rb +13 -14
- data/lib/producer/core/errors.rb +1 -0
- data/lib/producer/core/logger_formatter.rb +3 -4
- data/lib/producer/core/prompter.rb +4 -4
- data/lib/producer/core/recipe/file_evaluator.rb +3 -3
- data/lib/producer/core/recipe.rb +10 -10
- data/lib/producer/core/remote/environment.rb +1 -1
- data/lib/producer/core/remote/fs.rb +10 -10
- data/lib/producer/core/remote.rb +13 -7
- data/lib/producer/core/task.rb +15 -9
- data/lib/producer/core/template.rb +9 -10
- data/lib/producer/core/test.rb +1 -1
- data/lib/producer/core/testing/aruba_program_wrapper.rb +2 -2
- data/lib/producer/core/testing/cucumber/output_steps.rb +12 -0
- data/lib/producer/core/testing/cucumber/recipe_steps.rb +5 -5
- data/lib/producer/core/testing/cucumber/remote_steps.rb +8 -8
- data/lib/producer/core/testing/cucumber.rb +3 -3
- data/lib/producer/core/testing/mock_remote.rb +27 -25
- data/lib/producer/core/tests/condition_test.rb +1 -1
- data/lib/producer/core/tests/file_contains.rb +2 -3
- data/lib/producer/core/tests/file_eq.rb +1 -2
- data/lib/producer/core/tests/file_match.rb +1 -2
- data/lib/producer/core/tests/has_env.rb +3 -6
- data/lib/producer/core/tests/has_executable.rb +1 -1
- data/lib/producer/core/tests/shell_command_status.rb +1 -1
- data/lib/producer/core/version.rb +1 -1
- data/lib/producer/core/worker.rb +7 -7
- data/lib/producer/core.rb +0 -1
- data/producer-core.gemspec +2 -2
- data/spec/producer/core/cli_spec.rb +29 -4
- data/spec/producer/core/remote_spec.rb +9 -1
- data/spec/producer/core/testing/mock_remote_spec.rb +5 -4
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 928f078bd25c17856fcd95f5f95b1cf5f62cc2f6
|
4
|
+
data.tar.gz: 795822a79e878ed17e775216ecb75e4760739435
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 537ca3e1729156f2ea60a7e9a7cf975a7fdc88b807670be525e49c7a56b6c7372adc7c5dacd0af18174ec96b9a8ecb46041d139f59f7132ab6f3dc3ba68ab911
|
7
|
+
data.tar.gz: b7a099e4ffb7438e8a02336fac5f36cd58960e29009946546bd7fbf47ea96fc15b5dc45e838f15214d0f090d0ac8172380fc746e4e0aeba1878e57b013b6d08c
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -5,12 +5,15 @@ task default: %i[features spec]
|
|
5
5
|
|
6
6
|
Cucumber::Rake::Task.new(:features)
|
7
7
|
|
8
|
-
Cucumber::Rake::Task.new(:
|
8
|
+
Cucumber::Rake::Task.new(:features_ci) do |t|
|
9
9
|
t.instance_eval { @desc << ' excluding @ci_skip' }
|
10
10
|
t.cucumber_opts = '--tags ~@ci_skip'
|
11
|
+
t.profile = 'quiet' if ENV.key? 'TRAVIS'
|
11
12
|
end
|
12
13
|
|
13
|
-
RSpec::Core::RakeTask.new
|
14
|
+
RSpec::Core::RakeTask.new do |t|
|
15
|
+
t.rspec_opts = '--format progress' if ENV.key? 'TRAVIS'
|
16
|
+
end
|
14
17
|
|
15
18
|
desc 'Run CI test suite'
|
16
|
-
task ci: %i[
|
19
|
+
task ci: %i[features_ci spec]
|
data/config/cucumber.yaml
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
default: --require features/support --require features/steps
|
1
|
+
default: --require features/support --require features/steps --no-source
|
2
|
+
quiet: --format progress
|
data/features/cli/debug.feature
CHANGED
@@ -3,7 +3,7 @@ Feature: CLI debug option
|
|
3
3
|
Scenario: reports recipe errors with their cause
|
4
4
|
Given a recipe with an error
|
5
5
|
When I execute the recipe with option -d
|
6
|
-
Then the output must match /\
|
6
|
+
Then the output must match /\ARecipeEvaluationError:.*\n\ncause:\nRuntimeError:/
|
7
7
|
|
8
8
|
Scenario: does not exclude anything from backtrace
|
9
9
|
Given a recipe using a remote
|
@@ -11,3 +11,9 @@ Feature: CLI debug option
|
|
11
11
|
Then the output must contain "producer"
|
12
12
|
And the output must contain "net-ssh"
|
13
13
|
And the output must contain ruby lib directory
|
14
|
+
|
15
|
+
Scenario: enables debug mode from the environment
|
16
|
+
Given a recipe with an error
|
17
|
+
And I set the environment variable "PRODUCER_DEBUG"
|
18
|
+
When I execute the recipe
|
19
|
+
Then the output must contain "producer"
|
@@ -15,3 +15,8 @@ Feature: CLI dry run option
|
|
15
15
|
Scenario: prints a warning before any output
|
16
16
|
When I successfully execute the recipe with option -n
|
17
17
|
Then the output must match /\AWarning: running in dry run mode, actions will NOT be applied/
|
18
|
+
|
19
|
+
Scenario: enables dry run mode from the environment
|
20
|
+
Given I set the environment variable "PRODUCER_DRYRUN"
|
21
|
+
When I successfully execute the recipe
|
22
|
+
Then the output must contain "running in dry run"
|
@@ -4,7 +4,7 @@ Feature: CLI error reporting
|
|
4
4
|
Given a recipe with an error
|
5
5
|
When I execute the recipe
|
6
6
|
Then the exit status must be 70
|
7
|
-
And the output must match /\
|
7
|
+
And the output must match /\ARecipeEvaluationError: some error\n/
|
8
8
|
|
9
9
|
Scenario: reports errors with a backtrace
|
10
10
|
Given a recipe with an error
|
data/features/cli/usage.feature
CHANGED
@@ -4,14 +4,10 @@ Feature: CLI usage
|
|
4
4
|
Scenario: prints the usage when an argument is missing
|
5
5
|
When I run `producer`
|
6
6
|
Then the exit status must be 64
|
7
|
-
And the output must contain exactly
|
8
|
-
"""
|
9
|
-
Usage: producer [options] [recipes]
|
7
|
+
And the output must contain exactly the usage
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
"""
|
9
|
+
@exec
|
10
|
+
Scenario: prints the usage when unknown option switch is given
|
11
|
+
When I run `producer --unknown-option`
|
12
|
+
Then the exit status must be 64
|
13
|
+
And the output must contain exactly the usage
|
@@ -41,3 +41,8 @@ Feature: CLI verbose option
|
|
41
41
|
"""
|
42
42
|
When I successfully execute the recipe with option -v
|
43
43
|
Then the output must match /action: .{,70}$/
|
44
|
+
|
45
|
+
Scenario: enables verbose mode from the environment
|
46
|
+
Given I set the environment variable "PRODUCER_VERBOSE"
|
47
|
+
When I successfully execute the recipe
|
48
|
+
Then the output must contain "Task"
|
data/features/ssh/config.feature
CHANGED
@@ -14,7 +14,7 @@ Feature: SSH settings
|
|
14
14
|
When I successfully execute the recipe
|
15
15
|
Then the output must contain my current login name
|
16
16
|
|
17
|
-
@
|
17
|
+
@mocked-home-directory
|
18
18
|
Scenario: uses configured SSH user name for a given host
|
19
19
|
Given an SSH config with:
|
20
20
|
"""
|
data/lib/producer/core/action.rb
CHANGED
@@ -9,7 +9,7 @@ module Producer
|
|
9
9
|
|
10
10
|
attr_reader :env, :arguments, :options
|
11
11
|
|
12
|
-
def initialize
|
12
|
+
def initialize env, *args, **options
|
13
13
|
@env = env
|
14
14
|
@arguments = args
|
15
15
|
@options = options
|
@@ -24,17 +24,15 @@ module Producer
|
|
24
24
|
[name, inspect_arguments].join ' '
|
25
25
|
end
|
26
26
|
|
27
|
-
|
28
|
-
private
|
27
|
+
private
|
29
28
|
|
30
29
|
def inspect_arguments
|
31
30
|
@arguments.inspect[0, INSPECT_ARGUMENTS_SUM_LEN - name.length]
|
32
31
|
end
|
33
32
|
|
34
|
-
def check_arguments_size!
|
35
|
-
if arguments.compact.size
|
36
|
-
|
37
|
-
end
|
33
|
+
def check_arguments_size! size
|
34
|
+
return if arguments.compact.size == size
|
35
|
+
fail ArgumentError, '`%s\' action requires %d arguments' % [name, size]
|
38
36
|
end
|
39
37
|
end
|
40
38
|
end
|
@@ -14,10 +14,10 @@ module Producer
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def apply
|
17
|
-
@path.descend do |
|
18
|
-
next if fs.dir?
|
19
|
-
fs.mkdir
|
20
|
-
fs.setstat
|
17
|
+
@path.descend do |path|
|
18
|
+
next if fs.dir? path
|
19
|
+
fs.mkdir path.to_s
|
20
|
+
fs.setstat path.to_s, @options unless @options.empty?
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/producer/core/cli.rb
CHANGED
@@ -1,54 +1,63 @@
|
|
1
1
|
module Producer
|
2
2
|
module Core
|
3
3
|
class CLI
|
4
|
-
ArgumentError = Class.new(
|
4
|
+
ArgumentError = Class.new(ArgumentError)
|
5
5
|
|
6
|
-
USAGE =
|
6
|
+
USAGE =
|
7
|
+
"Usage: #{File.basename $0} [options] [recipes] [-- recipe_argument...]"
|
8
|
+
.freeze
|
7
9
|
|
8
10
|
EX_USAGE = 64
|
9
11
|
EX_SOFTWARE = 70
|
10
12
|
|
11
13
|
ARGUMENTS_SEPARATOR = '--'.freeze
|
12
14
|
|
15
|
+
ENV_VERBOSE_KEY = 'PRODUCER_VERBOSE'.freeze
|
16
|
+
ENV_DEBUG_KEY = 'PRODUCER_DEBUG'.freeze
|
17
|
+
ENV_DRYRUN_KEY = 'PRODUCER_DRYRUN'.freeze
|
18
|
+
|
13
19
|
class << self
|
14
|
-
def run!
|
15
|
-
cli = new
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
exit EX_SOFTWARE
|
29
|
-
end
|
20
|
+
def run! arguments, stdin: $stdin, stdout: $stdout, stderr: $stderr
|
21
|
+
cli = new arguments, ENV, stdin: stdin, stdout: stdout, stderr: stderr
|
22
|
+
cli.parse_arguments!
|
23
|
+
cli.run
|
24
|
+
rescue ArgumentError => e
|
25
|
+
stderr.puts e.message
|
26
|
+
exit EX_USAGE
|
27
|
+
rescue StandardError => e
|
28
|
+
ef = ErrorFormatter.new(
|
29
|
+
debug: cli.env.debug?,
|
30
|
+
force_cause: [RecipeEvaluationError]
|
31
|
+
)
|
32
|
+
stderr.puts ef.format e
|
33
|
+
exit EX_SOFTWARE
|
30
34
|
end
|
31
35
|
end
|
32
36
|
|
33
37
|
attr_reader :arguments, :stdin, :stdout, :stderr, :env
|
34
38
|
|
35
|
-
def initialize
|
39
|
+
def initialize args, environment, stdin: $stdin, stdout: $stdout,
|
40
|
+
stderr: $stderr
|
36
41
|
@arguments = args
|
37
42
|
@stdin = stdin
|
38
43
|
@stdout = stdout
|
39
44
|
@stderr = stderr
|
40
45
|
@env = build_env
|
46
|
+
|
47
|
+
configure_environment! environment
|
41
48
|
end
|
42
49
|
|
43
50
|
def parse_arguments!
|
44
51
|
if @arguments.include? ARGUMENTS_SEPARATOR
|
45
52
|
@arguments, @env.recipe_argv = split_arguments_lists @arguments
|
46
53
|
end
|
47
|
-
option_parser.parse!
|
54
|
+
option_parser.parse! @arguments
|
48
55
|
fail ArgumentError, option_parser if @arguments.empty?
|
56
|
+
rescue OptionParser::InvalidOption
|
57
|
+
raise ArgumentError, option_parser
|
49
58
|
end
|
50
59
|
|
51
|
-
def run
|
60
|
+
def run worker: Worker.new(@env)
|
52
61
|
evaluate_recipes.each { |recipe| worker.process recipe.tasks }
|
53
62
|
ensure
|
54
63
|
@env.cleanup
|
@@ -58,17 +67,22 @@ module Producer
|
|
58
67
|
@arguments.map { |e| Recipe::FileEvaluator.evaluate(e, @env) }
|
59
68
|
end
|
60
69
|
|
61
|
-
|
62
|
-
private
|
70
|
+
private
|
63
71
|
|
64
72
|
def build_env
|
65
73
|
Env.new(input: @stdin, output: @stdout, error_output: @stderr)
|
66
74
|
end
|
67
75
|
|
68
|
-
def
|
76
|
+
def configure_environment! environment
|
77
|
+
@env.verbose = true if environment.key? ENV_VERBOSE_KEY
|
78
|
+
@env.debug = true if environment.key? ENV_DEBUG_KEY
|
79
|
+
@env.dry_run = true if environment.key? ENV_DRYRUN_KEY
|
80
|
+
end
|
81
|
+
|
82
|
+
def split_arguments_lists arguments
|
69
83
|
arguments
|
70
84
|
.chunk { |e| e == ARGUMENTS_SEPARATOR }
|
71
|
-
.reject { |
|
85
|
+
.reject { |a, _| a }
|
72
86
|
.map &:last
|
73
87
|
end
|
74
88
|
|
@@ -78,23 +92,20 @@ module Producer
|
|
78
92
|
opts.separator ''
|
79
93
|
opts.separator 'options:'
|
80
94
|
|
81
|
-
opts
|
82
|
-
env.verbose = true
|
83
|
-
end
|
84
|
-
|
85
|
-
opts.on '-d', '--debug', 'enable debug mode' do |e|
|
86
|
-
env.debug = true
|
87
|
-
end
|
88
|
-
|
89
|
-
opts.on '-n', '--dry-run', 'enable dry run mode' do |e|
|
90
|
-
env.dry_run = true
|
91
|
-
end
|
92
|
-
|
95
|
+
option_parser_add_boolean_options opts
|
93
96
|
opts.on '-t', '--target HOST', 'target host' do |e|
|
94
97
|
env.target = e
|
95
98
|
end
|
96
99
|
end
|
97
100
|
end
|
101
|
+
|
102
|
+
def option_parser_add_boolean_options opts
|
103
|
+
{ v: 'verbose', d: 'debug', n: 'dry run' }.each do |k, v|
|
104
|
+
opts.on "-#{k}", "--#{v.tr ' ', '-'}", "enable #{v} mode" do
|
105
|
+
env.send "#{v.tr ' ', '_'}=", true
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
98
109
|
end
|
99
110
|
end
|
100
111
|
end
|
@@ -2,7 +2,7 @@ module Producer
|
|
2
2
|
module Core
|
3
3
|
class Condition
|
4
4
|
class << self
|
5
|
-
def define_test
|
5
|
+
def define_test keyword, test
|
6
6
|
{
|
7
7
|
keyword => false,
|
8
8
|
"no_#{keyword}" => true
|
@@ -19,7 +19,7 @@ module Producer
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def evaluate
|
22
|
+
def evaluate env, *args, &block
|
23
23
|
new.tap do |o|
|
24
24
|
o.instance_eval { @env = env }
|
25
25
|
return_value = o.instance_exec *args, &block
|
@@ -44,7 +44,7 @@ module Producer
|
|
44
44
|
|
45
45
|
attr_reader :tests, :return_value
|
46
46
|
|
47
|
-
def initialize
|
47
|
+
def initialize tests = [], return_value = nil
|
48
48
|
@tests = tests
|
49
49
|
@return_value = return_value
|
50
50
|
end
|
data/lib/producer/core/env.rb
CHANGED
@@ -7,7 +7,8 @@ module Producer
|
|
7
7
|
attr_reader :input, :output, :error_output, :registry, :logger
|
8
8
|
attr_accessor :target, :verbose, :debug, :dry_run, :recipe_argv
|
9
9
|
|
10
|
-
def initialize
|
10
|
+
def initialize input: $stdin, output: $stdout, error_output: $stderr,
|
11
|
+
remote: nil, registry: {}
|
11
12
|
@verbose = @debug = @dry_run = false
|
12
13
|
@input = input
|
13
14
|
@output = output
|
@@ -20,10 +21,10 @@ module Producer
|
|
20
21
|
@remote ||= Remote.new(target)
|
21
22
|
end
|
22
23
|
|
23
|
-
def []
|
24
|
+
def [] *args
|
24
25
|
@registry.fetch *args
|
25
26
|
rescue KeyError
|
26
|
-
|
27
|
+
raise RegistryKeyError, args.first.inspect
|
27
28
|
end
|
28
29
|
alias get []
|
29
30
|
|
@@ -34,7 +35,7 @@ module Producer
|
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
37
|
-
def log
|
38
|
+
def log message, severity = :info
|
38
39
|
logger.send severity, message
|
39
40
|
end
|
40
41
|
|
@@ -8,7 +8,7 @@ module Producer
|
|
8
8
|
/\/net-sftp/
|
9
9
|
].freeze
|
10
10
|
|
11
|
-
def initialize
|
11
|
+
def initialize debug: false, force_cause: []
|
12
12
|
@debug = debug
|
13
13
|
@force_cause = force_cause
|
14
14
|
end
|
@@ -17,46 +17,45 @@ module Producer
|
|
17
17
|
!!@debug
|
18
18
|
end
|
19
19
|
|
20
|
-
def format
|
21
|
-
lines = format_exception exception, filter: !debug?
|
22
|
-
|
20
|
+
def format exception
|
23
21
|
if debug? && exception.cause
|
22
|
+
lines = format_exception exception, filter: true
|
24
23
|
lines << ''
|
25
24
|
lines << 'cause:'
|
26
25
|
lines << format_exception(exception.cause, filter: false)
|
26
|
+
else
|
27
|
+
lines = format_exception exception, filter: !debug?
|
27
28
|
end
|
28
29
|
|
29
|
-
lines.join
|
30
|
+
lines.join "\n"
|
30
31
|
end
|
31
32
|
|
33
|
+
private
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
def format_exception(exception, filter: true)
|
35
|
+
def format_exception exception, filter: true
|
36
36
|
[
|
37
37
|
format_message(exception),
|
38
38
|
*format_backtrace(exception.backtrace, filter: filter)
|
39
39
|
]
|
40
40
|
end
|
41
41
|
|
42
|
-
def format_message
|
43
|
-
exception = exception.cause if @force_cause.include? exception.class
|
42
|
+
def format_message exception
|
44
43
|
"#{exception.class.name.split('::').last}: #{exception.message}"
|
45
44
|
end
|
46
45
|
|
47
|
-
def format_backtrace
|
46
|
+
def format_backtrace backtrace, filter: true
|
48
47
|
backtrace = filter_backtrace backtrace if filter
|
49
48
|
indent_backtrace backtrace
|
50
49
|
end
|
51
50
|
|
52
|
-
def filter_backtrace
|
51
|
+
def filter_backtrace backtrace
|
53
52
|
backtrace.reject do |line|
|
54
53
|
FILTERS.any? { |filter| line =~ filter }
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
58
|
-
def indent_backtrace
|
59
|
-
backtrace.map { |e| '
|
57
|
+
def indent_backtrace backtrace
|
58
|
+
backtrace.map { |e| ' ' + e }
|
60
59
|
end
|
61
60
|
end
|
62
61
|
end
|
data/lib/producer/core/errors.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
module Producer
|
2
2
|
module Core
|
3
3
|
class LoggerFormatter < Logger::Formatter
|
4
|
-
def call
|
4
|
+
def call severity, _datetime, _progname, message
|
5
5
|
prefix(severity) + message + "\n"
|
6
6
|
end
|
7
7
|
|
8
|
+
private
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
def prefix(severity)
|
10
|
+
def prefix severity
|
12
11
|
severity == 'WARN' ? 'Warning: ' : ''
|
13
12
|
end
|
14
13
|
end
|
@@ -3,14 +3,14 @@ module Producer
|
|
3
3
|
class Prompter
|
4
4
|
attr_reader :input, :output
|
5
5
|
|
6
|
-
def initialize
|
6
|
+
def initialize input, output
|
7
7
|
@input = input
|
8
8
|
@output = output
|
9
9
|
end
|
10
10
|
|
11
|
-
def prompt
|
12
|
-
cs = choices.each_with_index.inject
|
13
|
-
m
|
11
|
+
def prompt question, choices
|
12
|
+
cs = choices.each_with_index.inject '' do |m, (c, i)|
|
13
|
+
m + "#{i}: #{c.last}\n"
|
14
14
|
end
|
15
15
|
output.puts "#{question}\n#{cs}Choice:"
|
16
16
|
choice = input.gets
|
@@ -3,12 +3,12 @@ module Producer
|
|
3
3
|
class Recipe
|
4
4
|
class FileEvaluator
|
5
5
|
class << self
|
6
|
-
def evaluate
|
6
|
+
def evaluate file_path, env
|
7
7
|
content = File.read(file_path)
|
8
8
|
begin
|
9
9
|
Recipe.new(env).tap { |o| o.instance_eval content, file_path }
|
10
|
-
rescue
|
11
|
-
|
10
|
+
rescue ::StandardError, ::ScriptError => e
|
11
|
+
raise RecipeEvaluationError, e.message, [
|
12
12
|
'%s (recipe)' % file_path,
|
13
13
|
*e.backtrace
|
14
14
|
]
|
data/lib/producer/core/recipe.rb
CHANGED
@@ -2,7 +2,7 @@ module Producer
|
|
2
2
|
module Core
|
3
3
|
class Recipe
|
4
4
|
class << self
|
5
|
-
def define_macro
|
5
|
+
def define_macro name, block
|
6
6
|
[self, Task].each do |klass|
|
7
7
|
klass.class_eval do
|
8
8
|
define_method(name) { |*args| task name, *args, &block }
|
@@ -10,7 +10,7 @@ module Producer
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
def compose_macro
|
13
|
+
def compose_macro name, macro, *base_args
|
14
14
|
[self, Task].each do |klass|
|
15
15
|
klass.class_eval do
|
16
16
|
define_method(name) { |*args| send macro, *(base_args + args) }
|
@@ -24,32 +24,32 @@ module Producer
|
|
24
24
|
def_delegator :@env, :[], :get
|
25
25
|
attr_reader :env, :tasks
|
26
26
|
|
27
|
-
def initialize
|
27
|
+
def initialize env
|
28
28
|
@env = env
|
29
29
|
@tasks = []
|
30
30
|
end
|
31
31
|
|
32
|
-
def source
|
32
|
+
def source filepath
|
33
33
|
instance_eval File.read("./#{filepath}.rb"), "#{filepath}.rb"
|
34
34
|
end
|
35
35
|
|
36
|
-
def target
|
36
|
+
def target hostname = nil
|
37
37
|
if hostname then env.target ||= hostname else env.target end
|
38
38
|
end
|
39
39
|
|
40
|
-
def task
|
40
|
+
def task name, *args, &block
|
41
41
|
Task.evaluate(env, name, *args, &block).tap { |o| @tasks << o }
|
42
42
|
end
|
43
43
|
|
44
|
-
def macro
|
44
|
+
def macro name, &block
|
45
45
|
self.class.class_eval { define_macro name, block }
|
46
46
|
end
|
47
47
|
|
48
|
-
def compose_macro
|
49
|
-
self.class.class_eval { compose_macro name, macro, *base_args}
|
48
|
+
def compose_macro name, macro, *base_args
|
49
|
+
self.class.class_eval { compose_macro name, macro, *base_args }
|
50
50
|
end
|
51
51
|
|
52
|
-
def test_macro
|
52
|
+
def test_macro name, &block
|
53
53
|
Condition.define_test(name, block)
|
54
54
|
end
|
55
55
|
end
|