producer-core 0.4.5 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7369766247b31d978939ca38cea6e1ffda8e7e72
4
- data.tar.gz: f0440319fe4a6c3e3dcf0352ac01a1dd39ed6a9f
3
+ metadata.gz: e8ed5fbac8a4bcce8a96df535139a7661fb6743d
4
+ data.tar.gz: 68fd481da50a32dd5eb6da6132c323588ad678e0
5
5
  SHA512:
6
- metadata.gz: 3cf37a2d16b4e6bb4d42d0204ffc3f3a52016fc52358a625bc0eb86b13209241f75a6f171d29044414ff48dba4f339f6fff454d52b5d9ace33a4027f29d55117
7
- data.tar.gz: 267659f33b453c84df3c0f9188ecb7f82ec08162bcc119afdf1b8da3776cc57d1b8014c846524b41202cb3ecbf3785ed66493e03f86987dc0cc46fd4845dd745
6
+ metadata.gz: ccb2d2a8bd77165bdeb7f37bb8b2f2c0fe2f4f228ac9ae6a703d4bcd9567aa5e71de7f707c545bd77571a712cf969adda2510aedf436b997a0ebdf359cf99814
7
+ data.tar.gz: dcec3e65090d29eb2ba278785bac8004c8826d7bac22d85f984e4bcff4bb49d9f7b7593643973b6cb92c73757d1e89e7c4459b2063adfbd5bd51331d1ee80298
data/README.md CHANGED
@@ -378,9 +378,9 @@ Similar or related code and tools
378
378
 
379
379
 
380
380
 
381
- [badge-version-img]: https://img.shields.io/gem/v/producer-core.svg
381
+ [badge-version-img]: https://img.shields.io/gem/v/producer-core.svg?style=flat-square
382
382
  [badge-version-uri]: https://rubygems.org/gems/producer-core
383
- [badge-build-img]: https://img.shields.io/travis/tjouan/producer-core/master.svg
383
+ [badge-build-img]: https://img.shields.io/travis/tjouan/producer-core/master.svg?style=flat-square
384
384
  [badge-build-uri]: https://travis-ci.org/tjouan/producer-core
385
- [badge-cclimate-img]: https://img.shields.io/codeclimate/github/tjouan/producer-core.svg
385
+ [badge-cclimate-img]: https://img.shields.io/codeclimate/github/tjouan/producer-core.svg?style=flat-square
386
386
  [badge-cclimate-uri]: https://codeclimate.com/github/tjouan/producer-core
@@ -1,9 +1,25 @@
1
+ def run_recipe(remote: false, options: nil, check: false, rargv: nil)
2
+ command = %w[producer recipe.rb]
3
+ case remote
4
+ when :unknown then command += %w[-t unknown_host.test]
5
+ when true then command += %w[-t some_host.test]
6
+ end
7
+ command << options if options
8
+ command << ['--', *rargv] if rargv
9
+
10
+ p command.join(' ')
11
+ run_simple command.join(' '), false
12
+
13
+ assert_exit_status 0 if check
14
+ assert_matching_output '\ASocketError', all_output if remote == :unknown
15
+ end
16
+
1
17
  Given /^a recipe with:$/ do |recipe_body|
2
18
  write_file 'recipe.rb', recipe_body
3
19
  end
4
20
 
5
21
  Given /^a recipe with an error$/ do
6
- write_file 'recipe.rb', "task(:trigger_error) { fail 'some error' }\n"
22
+ write_file 'recipe.rb', "fail 'some error'\n"
7
23
  end
8
24
 
9
25
  Given /^a recipe using a remote$/ do
@@ -15,40 +31,39 @@ Given /^a recipe named "([^"]+)" with:$/ do |recipe_path, recipe_body|
15
31
  end
16
32
 
17
33
  When /^I execute the recipe$/ do
18
- run_simple 'producer recipe.rb', false
34
+ run_recipe
19
35
  end
20
36
 
21
37
  When /^I execute the recipe on remote target$/ do
22
- run_simple 'producer recipe.rb -t some_host.test', false
38
+ run_recipe remote: true
23
39
  end
24
40
 
25
41
  When /^I execute the recipe on unknown remote target$/ do
26
- run_simple 'producer recipe.rb -t #unknown_host.test', false
27
- assert_matching_output '\ASocketError', all_output
42
+ run_recipe remote: :unknown
43
+ end
44
+
45
+ When /^I execute the recipe with options? (-.+)$/ do |options|
46
+ run_recipe options: options
28
47
  end
29
48
 
30
- When /^I execute the recipe on unknown remote target with option (-.+)$/ do |option|
31
- run_simple "producer recipe.rb #{option} -t #unknown_host.test", false
32
- assert_matching_output '\ASocketError', all_output
49
+ When /^I execute the recipe on unknown remote target with options? (-.+)$/ do |options|
50
+ run_recipe remote: :unknown, options: options
33
51
  end
34
52
 
35
53
  When /^I successfully execute the recipe$/ do
36
- step 'I execute the recipe'
37
- assert_exit_status 0
54
+ run_recipe check: true
38
55
  end
39
56
 
40
57
  When /^I successfully execute the recipe on remote target$/ do
41
- step 'I execute the recipe on remote target'
42
- assert_exit_status 0
58
+ run_recipe remote: true, check: true
43
59
  end
44
60
 
45
- When /^I execute the recipe with option (-.+)$/ do |option|
46
- run_simple "producer #{option} recipe.rb", false
61
+ When /^I successfully execute the recipe with option? (-.+)$/ do |options|
62
+ run_recipe options: options, check: true
47
63
  end
48
64
 
49
- When /^I successfully execute the recipe with option (-.+)$/ do |option|
50
- run_simple "producer #{option} recipe.rb", false
51
- assert_exit_status 0
65
+ When /^I successfully execute the recipe with arguments "([^"]+)"$/ do |rargv|
66
+ run_recipe rargv: rargv, check: true
52
67
  end
53
68
 
54
69
  When /^I execute the recipe interactively$/ do
@@ -1,3 +1,9 @@
1
+ def stat_mode(path)
2
+ in_current_dir do
3
+ ('%o' % [File::Stat.new(path).mode])[-4, 4]
4
+ end
5
+ end
6
+
1
7
  Given /^a remote directory named "([^"]+)"$/ do |path|
2
8
  create_dir path
3
9
  end
@@ -26,12 +32,6 @@ Then /^the remote file "([^"]+)" must match \/([^\/]+)\/$/ do |path, pattern|
26
32
  check_file_content path, /#{pattern}/, true
27
33
  end
28
34
 
29
- def stat_mode(path)
30
- in_current_dir do
31
- ('%o' % [File::Stat.new(path).mode])[-4, 4]
32
- end
33
- end
34
-
35
35
  Then /^the remote file "([^"]+)" must have (\d+) mode$/ do |path, mode|
36
36
  expect(stat_mode path).to eq mode
37
37
  end
@@ -0,0 +1,13 @@
1
+ Feature: `recipe_argv' task keyword
2
+
3
+ Background:
4
+ Given a recipe with:
5
+ """
6
+ task :echo_arguments do
7
+ echo recipe_argv
8
+ end
9
+ """
10
+
11
+ Scenario: returns recipe arguments
12
+ When I successfully execute the recipe with arguments "foo bar"
13
+ Then the output must contain exactly "foo\nbar\n"
@@ -8,6 +8,8 @@ module Producer
8
8
  EX_USAGE = 64
9
9
  EX_SOFTWARE = 70
10
10
 
11
+ ARGUMENTS_SEPARATOR = '--'.freeze
12
+
11
13
  class << self
12
14
  def run!(arguments, stdin: $stdin, stdout: $stdout, stderr: $stderr)
13
15
  cli = new(arguments, stdin: stdin, stdout: stdout, stderr: stderr)
@@ -39,6 +41,9 @@ module Producer
39
41
  end
40
42
 
41
43
  def parse_arguments!
44
+ if @arguments.include? ARGUMENTS_SEPARATOR
45
+ @arguments, @env.recipe_argv = split_arguments_lists @arguments
46
+ end
42
47
  option_parser.parse!(@arguments)
43
48
  fail ArgumentError, option_parser if @arguments.empty?
44
49
  end
@@ -60,6 +65,13 @@ module Producer
60
65
  Env.new(input: @stdin, output: @stdout, error_output: @stderr)
61
66
  end
62
67
 
68
+ def split_arguments_lists(arguments)
69
+ arguments
70
+ .chunk { |e| e == ARGUMENTS_SEPARATOR }
71
+ .reject { |b, a| b }
72
+ .map &:last
73
+ end
74
+
63
75
  def option_parser
64
76
  OptionParser.new do |opts|
65
77
  opts.banner = USAGE
@@ -5,7 +5,7 @@ module Producer
5
5
  def_delegators :@registry, :[]=, :key?
6
6
 
7
7
  attr_reader :input, :output, :error_output, :registry, :logger
8
- attr_accessor :target, :verbose, :debug, :dry_run
8
+ attr_accessor :target, :verbose, :debug, :dry_run, :recipe_argv
9
9
 
10
10
  def initialize(input: $stdin, output: $stdout, error_output: $stderr, remote: nil, registry: {})
11
11
  @verbose = @debug = @dry_run = false
@@ -18,6 +18,7 @@ module Producer
18
18
  def_delegators :@env, :target
19
19
  def_delegator :@env, :[], :get
20
20
  def_delegator :@env, :key?, :set?
21
+ def_delegator :@env, :recipe_argv
21
22
 
22
23
  define_action :echo, Actions::Echo
23
24
  define_action :sh, Actions::ShellCommand
@@ -1,5 +1,5 @@
1
1
  module Producer
2
2
  module Core
3
- VERSION = '0.4.5'.freeze
3
+ VERSION = '0.5.0'.freeze
4
4
  end
5
5
  end
@@ -130,6 +130,20 @@ module Producer::Core
130
130
  end
131
131
  end
132
132
 
133
+ context 'with recipe arguments' do
134
+ let(:arguments) { %w[recipe.rb -- foo] }
135
+
136
+ it 'removes recipe arguments' do
137
+ cli.parse_arguments!
138
+ expect(cli.arguments).to eq %w[recipe.rb]
139
+ end
140
+
141
+ it 'assigns env recipe arguments' do
142
+ cli.parse_arguments!
143
+ expect(cli.env.recipe_argv).to eq %w[foo]
144
+ end
145
+ end
146
+
133
147
  context 'when no arguments remains after parsing' do
134
148
  let(:arguments) { [] }
135
149
 
@@ -179,5 +179,13 @@ module Producer::Core
179
179
  expect(task.target).to eq :some_target
180
180
  end
181
181
  end
182
+
183
+ describe '#recipe_argv' do
184
+ before { env.recipe_argv = %w[foo bar] }
185
+
186
+ it 'returns recipe arguments' do
187
+ expect(task.recipe_argv).to eq %w[foo bar]
188
+ end
189
+ end
182
190
  end
183
191
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: producer-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-03 00:00:00.000000000 Z
11
+ date: 2015-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -157,6 +157,7 @@ files:
157
157
  - features/task/ask.feature
158
158
  - features/task/condition.feature
159
159
  - features/task/nested_tasks.feature
160
+ - features/task/recipe_argv.feature
160
161
  - features/task/target.feature
161
162
  - features/task/template.feature
162
163
  - features/tests/dir.feature
@@ -311,6 +312,7 @@ test_files:
311
312
  - features/task/ask.feature
312
313
  - features/task/condition.feature
313
314
  - features/task/nested_tasks.feature
315
+ - features/task/recipe_argv.feature
314
316
  - features/task/target.feature
315
317
  - features/task/template.feature
316
318
  - features/tests/dir.feature