orats 0.7.3 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Gemfile +1 -1
  4. data/{LICENSE.txt → LICENSE} +21 -21
  5. data/README.md +51 -346
  6. data/Rakefile +1 -1
  7. data/bin/orats +5 -2
  8. data/lib/orats/argv_adjust.rb +61 -0
  9. data/lib/orats/cli.rb +53 -141
  10. data/lib/orats/cli_help/new +27 -0
  11. data/lib/orats/cli_help/nuke +19 -0
  12. data/lib/orats/commands/new/exec.rb +59 -0
  13. data/lib/orats/commands/new/rails.rb +197 -0
  14. data/lib/orats/commands/new/server.rb +67 -0
  15. data/lib/orats/commands/nuke.rb +66 -44
  16. data/lib/orats/common.rb +76 -0
  17. data/lib/orats/postgres.rb +90 -0
  18. data/lib/orats/process.rb +35 -0
  19. data/lib/orats/redis.rb +25 -0
  20. data/lib/orats/shell.rb +12 -0
  21. data/lib/orats/templates/auth.rb +96 -82
  22. data/lib/orats/templates/base.rb +115 -110
  23. data/lib/orats/templates/includes/new/rails/.env +28 -28
  24. data/lib/orats/templates/includes/new/rails/Gemfile +4 -4
  25. data/lib/orats/templates/includes/new/rails/config/{whenever.rb → schedule.rb} +0 -0
  26. data/lib/orats/ui.rb +33 -0
  27. data/lib/orats/version.rb +3 -2
  28. data/lib/orats.rb +2 -1
  29. data/orats.gemspec +7 -5
  30. data/test/integration/cli_test.rb +28 -177
  31. data/test/test_helper.rb +24 -9
  32. metadata +17 -29
  33. data/lib/orats/commands/common.rb +0 -146
  34. data/lib/orats/commands/diff/compare.rb +0 -106
  35. data/lib/orats/commands/diff/exec.rb +0 -60
  36. data/lib/orats/commands/diff/parse.rb +0 -66
  37. data/lib/orats/commands/inventory.rb +0 -100
  38. data/lib/orats/commands/playbook.rb +0 -60
  39. data/lib/orats/commands/project/exec.rb +0 -74
  40. data/lib/orats/commands/project/rails.rb +0 -162
  41. data/lib/orats/commands/project/server.rb +0 -57
  42. data/lib/orats/commands/role.rb +0 -70
  43. data/lib/orats/commands/ui.rb +0 -47
  44. data/lib/orats/templates/includes/inventory/group_vars/all.yml +0 -202
  45. data/lib/orats/templates/includes/inventory/hosts +0 -8
  46. data/lib/orats/templates/includes/playbook/Galaxyfile +0 -15
  47. data/lib/orats/templates/includes/playbook/common.yml +0 -23
  48. data/lib/orats/templates/includes/playbook/site.yml +0 -36
  49. data/lib/orats/templates/includes/role/.travis.yml +0 -19
  50. data/lib/orats/templates/includes/role/README.md +0 -62
  51. data/lib/orats/templates/includes/role/meta/main.yml +0 -123
  52. data/lib/orats/templates/includes/role/tests/inventory +0 -1
  53. data/lib/orats/templates/includes/role/tests/main.yml +0 -7
  54. data/lib/orats/templates/playbook.rb +0 -119
  55. data/lib/orats/templates/role.rb +0 -144
@@ -1,6 +1,6 @@
1
- require 'yaml'
2
1
  require_relative '../test_helper'
3
2
 
3
+ # integration tests for the orats cli
4
4
  class TestCLI < Minitest::Test
5
5
  include Orats::Test
6
6
 
@@ -15,104 +15,23 @@ class TestCLI < Minitest::Test
15
15
  assert_nuked unless @target_path.nil?
16
16
  end
17
17
 
18
- def test_project
19
- assert_project ansible: :assert
18
+ def test_new
19
+ assert_new
20
20
  end
21
21
 
22
- def test_project_with_auth
23
- assert_project '--template auth', ansible: :assert
22
+ def test_new_with_auth
23
+ assert_new '--template auth'
24
24
  end
25
25
 
26
- def test_project_without_ansible
27
- assert_project '--skip-ansible', ansible: :refute
28
- end
29
-
30
- def test_project_with_invalid_template
26
+ def test_new_with_invalid_template
31
27
  @target_path = generate_app_name
32
28
  @extra_flags = "#{ORATS_NEW_FLAGS} --template foo"
33
29
 
34
- assert_orats 'project', 'not a valid template'
35
- end
36
-
37
- def test_inventory
38
- assert_inventory
39
- end
40
-
41
- def test_playbook
42
- assert_playbook
43
- end
44
-
45
- def test_playbook_update_roles
46
- target_path = generate_app_name
47
-
48
- assert_playbook target_path
49
- assert_playbook target_path
50
- end
51
-
52
- def test_role
53
- @target_path = 'githubname.myrole'
54
- @extra_flags = '-r ansible-myrole'
55
-
56
- out, err = capture_orats('role')
57
-
58
- assert_match /success/, out, err
59
-
60
- absolute_target_path = "#{TEST_PATH}/#{@target_path}"
61
-
62
- assert_path "#{absolute_target_path}/.gitignore"
63
- assert_path "#{absolute_target_path}/.travis.yml"
64
- assert_path "#{absolute_target_path}/README.md"
65
- assert_path "#{absolute_target_path}/LICENSE"
66
- assert_path "#{absolute_target_path}/tests"
67
- assert_path "#{absolute_target_path}/tests/main.yml"
68
- assert_path "#{absolute_target_path}/tests/inventory"
69
- refute_path "#{absolute_target_path}/files/main.yml"
70
- refute_path "#{absolute_target_path}/templates/main.yml"
71
-
72
- meta_main = IO.read("#{absolute_target_path}/meta/main.yml")
73
- readme = IO.read("#{absolute_target_path}/README.md")
74
- tests_main = IO.read("#{absolute_target_path}/tests/main.yml")
75
-
76
- refute meta_main.include?('author_name')
77
- assert_count readme, 'githubname.myrole', 2
78
- assert_count readme, 'ansible-myrole', 3
79
- assert_count tests_main, 'myrole', 1
80
- end
81
-
82
- def test_diff
83
- assert_diff
84
-
85
- out, err = capture_orats('diff')
86
-
87
- assert_count out, 'gem', 1
88
- assert_count out, 'missing', 0
89
- assert_count out, 'outdated', 0
90
- assert_count out, 'extra', 0
91
- end
92
-
93
- def test_diff_with_differences
94
- file_paths = assert_diff
95
-
96
- hosts_path = "#{file_paths[0]}/hosts"
97
- inventory_path = "#{file_paths[0]}/group_vars/all.yml"
98
- galaxyfile_path = "#{file_paths[1]}/Galaxyfile"
99
- site_path = "#{file_paths[1]}/site.yml"
100
-
101
- gsub_file(hosts_path, '[cache]', '[something]')
102
- gsub_file(inventory_path, 'postgres_user', 'hello_world')
103
- gsub_file(galaxyfile_path, /nickjj.ruby,v.*$/, "nickjj.ruby,v0.1.2\nfoo")
104
- gsub_file(site_path, 'nickjj.whenever', 'bar')
105
-
106
- out, err = capture_orats('diff')
107
-
108
- assert_count out, 'gem', 1
109
- assert_count out, 'missing', 3
110
- assert_count out, 'outdated', 1
111
- assert_count out, 'extra', 4
30
+ assert_orats 'new', 'not a valid template'
112
31
  end
113
32
 
114
33
  def test_templates
115
- assert_orats 'templates', '--template auth'
34
+ assert_orats 'templates', 'auth'
116
35
  end
117
36
 
118
37
  def test_version
@@ -121,30 +40,22 @@ class TestCLI < Minitest::Test
121
40
 
122
41
  private
123
42
 
124
- def assert_orats(command, match_regex, ansible: nil)
43
+ def assert_orats(command, match_regex)
125
44
  out, err = capture_orats(command)
126
45
 
127
- assert_match /#{match_regex}/, out, err unless match_regex.empty?
128
-
129
- assert_or_refute_ansible ansible if ansible
46
+ assert_match(/#{match_regex}/, out, err) unless match_regex.empty?
130
47
  end
131
48
 
132
- def assert_project(flags = '', ansible: nil)
49
+ def assert_new(flags = '')
133
50
  @target_path = generate_app_name
134
- absolute_target_path = "#{TEST_PATH}/#{@target_path}"
135
51
  @extra_flags = "#{ORATS_NEW_FLAGS} #{flags}"
52
+ absolute_target_path = "#{TEST_PATH}/#{@target_path}"
136
53
 
137
- assert_orats 'project', 'Start your server', ansible: ansible
138
-
139
- if ansible == :assert
140
- assert_ansible_yaml "#{absolute_target_path}/inventory/group_vars/all.yml"
141
- end
142
-
143
- absolute_target_path << "/services/#{@target_path}"
144
- assert_project_tests_pass absolute_target_path
54
+ assert_orats 'new', 'Start your server'
55
+ assert_new_tests_pass absolute_target_path
145
56
  end
146
57
 
147
- def assert_project_tests_pass(target_path)
58
+ def assert_new_tests_pass(target_path)
148
59
  out, err = capture_subprocess_io do
149
60
  system "cd #{target_path} && bundle exec rake test"
150
61
  end
@@ -153,87 +64,32 @@ class TestCLI < Minitest::Test
153
64
  assert out.include?('0 failures') && out.include?('0 errors'), err
154
65
  end
155
66
 
156
- def assert_inventory
157
- @target_path = generate_app_name
158
-
159
- assert_orats 'inventory', 'success'
160
- assert_path "#{TEST_PATH}/#{@target_path}/inventory/hosts"
161
- assert_ansible_yaml "#{TEST_PATH}/#{@target_path}/inventory/group_vars/all.yml"
162
- end
163
-
164
- def assert_playbook(target_path = generate_app_name)
165
- @target_path = target_path
166
-
167
- assert_orats 'playbook', 'success'
168
- assert_path "#{TEST_PATH}/#{@target_path}/Galaxyfile"
169
- assert_ansible_yaml "#{TEST_PATH}/#{@target_path}/common.yml"
170
- assert_ansible_yaml "#{TEST_PATH}/#{@target_path}/site.yml"
171
- end
172
-
173
- def assert_diff
174
- assert_inventory
175
- inventory_path = "#{TEST_PATH}/#{@target_path}/inventory"
176
-
177
- assert_playbook
178
- playbook_path = "#{TEST_PATH}/#{@target_path}"
179
-
180
- @target_path = ''
181
- @extra_flags = "-i #{inventory_path} -p #{playbook_path}"
182
-
183
- [inventory_path, playbook_path]
184
- end
185
-
186
67
  def assert_nuked(options = {})
187
- out, err = capture_subprocess_io do
68
+ out, _ = capture_subprocess_io do
188
69
  orats "nuke #{@target_path}", flags: options[:flags], answer: 'y'
189
70
  end
190
71
 
191
- assert_match /#{@target_path}/, out
72
+ assert_match(/#{@target_path}/, out)
192
73
  system "rm -rf #{TEST_PATH}"
193
74
  end
194
75
 
195
76
  def assert_count(input, regex, expected)
196
77
  assert input.scan(regex).size == expected,
197
- "Found #{input.scan(regex).size} matches for '#{regex}' but expected #{expected}"
78
+ "Found #{input.scan(regex).size} matches for '#{regex}' but " + \
79
+ "expected #{expected}"
198
80
  end
199
81
 
200
82
  def assert_in_file(file_path, match_regex)
201
83
  file_contents = `cat #{file_path}`
202
- assert_match /#{match_regex}/, file_contents
84
+ assert_match(/#{match_regex}/, file_contents)
203
85
  end
204
86
 
205
87
  def assert_path(file_or_dir)
206
- assert File.exists?(file_or_dir), "Expected path '#{file_or_dir}' to exist"
88
+ assert File.exist?(file_or_dir), "Expected path '#{file_or_dir}' to exist"
207
89
  end
208
90
 
209
91
  def refute_path(file_or_dir)
210
- refute File.exists?(file_or_dir), "Expected path '#{file_or_dir}' to exist"
211
- end
212
-
213
- def assert_or_refute_ansible(assert_or_refute)
214
- absolute_target_path = "#{TEST_PATH}/#{@target_path}"
215
-
216
- assert_path "#{absolute_target_path}/services"
217
- send("#{assert_or_refute.to_s}_path",
218
- "#{absolute_target_path}/inventory")
219
- send("#{assert_or_refute.to_s}_path",
220
- "#{absolute_target_path}/secrets")
221
- end
222
-
223
- def assert_ansible_yaml(file_path)
224
- begin
225
- file = IO.read(file_path)
226
- invalid_ansible_yaml = file.match(/^([^#].\w): {/)
227
-
228
- if invalid_ansible_yaml
229
- assert false, "Invalid yaml syntax found near:\n #{invalid_ansible_yaml}\n\nYou need to include quotes around values that start with jinja template tags:\n Example, foo: '{{ bar }}'"
230
- return
231
- end
232
-
233
- assert YAML.load(file)
234
- rescue Psych::SyntaxError => ex
235
- assert false, ex.message
236
- end
92
+ refute File.exist?(file_or_dir), "Expected path '#{file_or_dir}' to exist"
237
93
  end
238
94
 
239
95
  def capture_orats(command)
@@ -252,20 +108,15 @@ class TestCLI < Minitest::Test
252
108
  line.include?('Running') || line.include?('Run options') ||
253
109
  line.empty?
254
110
  end
111
+ end
255
112
 
113
+ def print_rails_test_results(out)
256
114
  puts
257
- puts '-'*80
115
+ puts '-' * 80
258
116
  puts 'Results of running `bundle exec rake test` on the generated test app:'
259
- puts '-'*80
260
- puts out_lines.join("\n\n").rstrip
261
- puts '-'*80
117
+ puts '-' * 80
118
+ puts out.join("\n\n").rstrip
119
+ puts '-' * 80
262
120
  puts
263
121
  end
264
-
265
- def gsub_file(file_path, replace, with)
266
- IO.write(file_path, File.open(file_path) do |f|
267
- f.read.gsub(replace, with)
268
- end
269
- )
270
- end
271
122
  end
data/test/test_helper.rb CHANGED
@@ -1,19 +1,25 @@
1
1
  require 'minitest/autorun'
2
2
  require 'securerandom'
3
- require_relative '../lib/orats/commands/project/server'
3
+ require_relative '../lib/orats/commands/new/server'
4
4
 
5
5
  module Orats
6
+ # test helpers
6
7
  module Test
7
- include Commands::Project::Server
8
+ include Commands::New::Server
9
+
10
+ # creating and destroying databases needs to be done with raw psql
11
+ # commands when the host isn't localhost or 127.0.0.1
8
12
 
9
13
  TEST_PATH = ENV['TEST_PATH'] || '/tmp/orats'
10
14
  POSTGRES_LOCATION = ENV['POSTGRES_LOCATION'] || 'localhost'
11
15
  POSTGRES_USERNAME = ENV['POSTGRES_USERNAME'] || 'postgres'
12
- POSTGRES_PASSWORD = ENV['POSTGRES_PASSWORD'] || 'pleasedonthackme'
16
+ POSTGRES_PASSWORD = ENV['POSTGRES_PASSWORD'] || ''
13
17
  REDIS_LOCATION = ENV['REDIS_LOCATION'] || 'localhost'
14
18
  REDIS_PASSWORD = ENV['REDIS_PASSWORD'] || ''
15
19
 
16
- CREDENTIALS = "-l #{POSTGRES_LOCATION} -u #{POSTGRES_USERNAME} -p #{POSTGRES_PASSWORD} -n #{REDIS_LOCATION} -d #{REDIS_PASSWORD}"
20
+ CREDENTIALS = "-l #{POSTGRES_LOCATION} -u #{POSTGRES_USERNAME} " + \
21
+ " -p #{POSTGRES_PASSWORD} " + \
22
+ " -n #{REDIS_LOCATION} -d #{REDIS_PASSWORD}"
17
23
 
18
24
  INCLUDES_PATH = File.absolute_path('../../lib/orats/templates/includes',
19
25
  __FILE__)
@@ -22,14 +28,13 @@ module Orats
22
28
 
23
29
  def orats(command, options = {})
24
30
  cmd, app_name = command.split(' ')
25
- prepend_command = ''
26
31
  command = "#{cmd} #{TEST_PATH}/#{app_name}" unless app_name.nil?
27
32
 
28
- if options.has_key?(:answer)
29
- options[:answer] == 'y' || options[:answer] == 'yes' ?
30
- insert_answer = 'yes' : insert_answer = 'echo'
31
-
33
+ insert_answer = answer(options)
34
+ if insert_answer
32
35
  prepend_command = "#{insert_answer} | "
36
+ else
37
+ prepend_command = ''
33
38
  end
34
39
 
35
40
  system "#{prepend_command} #{BINARY_PATH} #{command} #{options[:flags]}"
@@ -37,6 +42,16 @@ module Orats
37
42
 
38
43
  private
39
44
 
45
+ def answer(options)
46
+ return unless options.key?(:answer)
47
+
48
+ if options[:answer] == 'y' || options[:answer] == 'yes'
49
+ 'yes'
50
+ else
51
+ 'no'
52
+ end
53
+ end
54
+
40
55
  def generate_app_name
41
56
  "a_#{SecureRandom.hex(8)}"
42
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Janetakis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-29 00:00:00.000000000 Z
11
+ date: 2014-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -66,8 +66,7 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '5.3'
69
- description: A collection of rails application templates using modern versions of
70
- Ruby on Rails. Launch new applications and the infrastructure to run them in seconds.
69
+ description: Generate modern Ruby on Rails applications using best practices.
71
70
  email:
72
71
  - nick.janetakis@gmail.com
73
72
  executables:
@@ -77,30 +76,28 @@ extra_rdoc_files: []
77
76
  files:
78
77
  - ".gitignore"
79
78
  - Gemfile
80
- - LICENSE.txt
79
+ - LICENSE
81
80
  - README.md
82
81
  - Rakefile
83
82
  - bin/orats
84
83
  - lib/orats.rb
84
+ - lib/orats/argv_adjust.rb
85
85
  - lib/orats/cli.rb
86
- - lib/orats/commands/common.rb
87
- - lib/orats/commands/diff/compare.rb
88
- - lib/orats/commands/diff/exec.rb
89
- - lib/orats/commands/diff/parse.rb
90
- - lib/orats/commands/inventory.rb
86
+ - lib/orats/cli_help/new
87
+ - lib/orats/cli_help/nuke
88
+ - lib/orats/commands/new/exec.rb
89
+ - lib/orats/commands/new/rails.rb
90
+ - lib/orats/commands/new/server.rb
91
91
  - lib/orats/commands/nuke.rb
92
- - lib/orats/commands/playbook.rb
93
- - lib/orats/commands/project/exec.rb
94
- - lib/orats/commands/project/rails.rb
95
- - lib/orats/commands/project/server.rb
96
- - lib/orats/commands/role.rb
97
- - lib/orats/commands/ui.rb
92
+ - lib/orats/common.rb
93
+ - lib/orats/postgres.rb
94
+ - lib/orats/process.rb
95
+ - lib/orats/redis.rb
96
+ - lib/orats/shell.rb
98
97
  - lib/orats/templates/auth.rb
99
98
  - lib/orats/templates/base.rb
100
99
  - lib/orats/templates/includes/common/.gitignore
101
100
  - lib/orats/templates/includes/common/LICENSE
102
- - lib/orats/templates/includes/inventory/group_vars/all.yml
103
- - lib/orats/templates/includes/inventory/hosts
104
101
  - lib/orats/templates/includes/new/rails/.env
105
102
  - lib/orats/templates/includes/new/rails/Gemfile
106
103
  - lib/orats/templates/includes/new/rails/Procfile
@@ -136,10 +133,10 @@ files:
136
133
  - lib/orats/templates/includes/new/rails/config/initializers/mini_profiler.rb
137
134
  - lib/orats/templates/includes/new/rails/config/initializers/sidekiq.rb
138
135
  - lib/orats/templates/includes/new/rails/config/puma.rb
136
+ - lib/orats/templates/includes/new/rails/config/schedule.rb
139
137
  - lib/orats/templates/includes/new/rails/config/secrets.yml
140
138
  - lib/orats/templates/includes/new/rails/config/sidekiq.yml
141
139
  - lib/orats/templates/includes/new/rails/config/sitemap.rb
142
- - lib/orats/templates/includes/new/rails/config/whenever.rb
143
140
  - lib/orats/templates/includes/new/rails/lib/backup/config.rb
144
141
  - lib/orats/templates/includes/new/rails/lib/backup/models/backup.rb
145
142
  - lib/orats/templates/includes/new/rails/lib/tasks/orats/backup.rake
@@ -150,16 +147,7 @@ files:
150
147
  - lib/orats/templates/includes/new/rails/public/502.html
151
148
  - lib/orats/templates/includes/new/rails/test/fixtures/accounts.yml
152
149
  - lib/orats/templates/includes/new/rails/test/models/account_test.rb
153
- - lib/orats/templates/includes/playbook/Galaxyfile
154
- - lib/orats/templates/includes/playbook/common.yml
155
- - lib/orats/templates/includes/playbook/site.yml
156
- - lib/orats/templates/includes/role/.travis.yml
157
- - lib/orats/templates/includes/role/README.md
158
- - lib/orats/templates/includes/role/meta/main.yml
159
- - lib/orats/templates/includes/role/tests/inventory
160
- - lib/orats/templates/includes/role/tests/main.yml
161
- - lib/orats/templates/playbook.rb
162
- - lib/orats/templates/role.rb
150
+ - lib/orats/ui.rb
163
151
  - lib/orats/version.rb
164
152
  - orats.gemspec
165
153
  - test/integration/cli_test.rb
@@ -1,146 +0,0 @@
1
- require 'orats/commands/ui'
2
- require 'orats/commands/diff/parse'
3
-
4
- module Orats
5
- module Commands
6
- class Common
7
- include Thor::Base
8
- include Thor::Shell
9
- include Thor::Actions
10
- include UI
11
- include Diff::Parse
12
-
13
- RELATIVE_PATHS = {
14
- galaxyfile: 'templates/includes/playbook/Galaxyfile',
15
- playbook: 'templates/includes/playbook/site.yml',
16
- hosts: 'templates/includes/inventory/hosts',
17
- inventory: 'templates/includes/inventory/group_vars/all.yml',
18
- version: 'version.rb'
19
- }
20
-
21
- attr_accessor :remote_gem_version, :remote_paths, :local_paths
22
-
23
- def initialize(target_path = '', options = {})
24
- @target_path = target_path
25
- @options = options
26
- @active_path = @target_path
27
-
28
- @local_paths = {}
29
- @remote_paths = {}
30
-
31
- build_common_paths
32
-
33
- self.destination_root = Dir.pwd
34
- @behavior = :invoke
35
- end
36
-
37
- def self.copy_from_local_gem(source, dest)
38
- base_path = File.join(File.expand_path(File.dirname(__FILE__)),
39
- '..')
40
- template_path = "#{base_path}/templates/includes"
41
-
42
- system "mkdir -p #{File.dirname(dest)}" unless Dir.exist?(File.dirname(dest))
43
- system "cp #{template_path}/#{source} #{dest}"
44
- end
45
-
46
- def base_path
47
- File.join(File.expand_path(File.dirname(__FILE__)), '..')
48
- end
49
-
50
- def repo_path
51
- %w(https://raw.githubusercontent.com/nickjj/orats lib/orats)
52
- end
53
-
54
- def url_to_string(url)
55
- begin
56
- open(url).read
57
- rescue *[OpenURI::HTTPError, SocketError] => ex
58
- log_error 'error', "Error accessing URL #{url}",
59
- 'message', ex
60
- exit 1
61
- end
62
- end
63
-
64
- def file_to_string(path)
65
- if File.exist?(path) && File.file?(path)
66
- IO.read(path)
67
- else
68
- log_error 'error', 'Error finding file',
69
- 'message', path
70
- exit 1
71
- end
72
- end
73
-
74
- def exit_if_path_exists(extend_path='')
75
- log_task 'Check if this path exists'
76
-
77
- extended_path = @active_path.dup
78
- extended_path = File.join(extended_path, extend_path) unless extend_path
79
- .empty?
80
-
81
- if Dir.exist?(extended_path) || File.exist?(extended_path)
82
- log_error 'error', 'A file or directory already exists at this location', 'path', extended_path
83
- exit 1
84
- end
85
- end
86
-
87
- def exit_if_process(check_for, *processes)
88
- case check_for
89
- when :not_found
90
- command = 'which'
91
- phrase = 'on your system path'
92
- when :not_running
93
- command = 'ps cax | grep'
94
- phrase = 'running'
95
- else
96
- command = ''
97
- phrase = ''
98
- end
99
-
100
- processes.each do |process|
101
- log_task "Check if #{process} is #{phrase}"
102
-
103
- exit 1 if process_unusable?("#{command} #{process}", process, phrase)
104
- end
105
- end
106
-
107
- private
108
-
109
- def build_common_paths
110
- @remote_paths[:version] = select_branch 'master', RELATIVE_PATHS[:version]
111
- @remote_gem_version = gem_version
112
-
113
- RELATIVE_PATHS.each_pair do |key, value|
114
- @local_paths[key] = "#{base_path}/#{value}"
115
- @remote_paths[key] = select_branch @remote_gem_version,
116
- check_old_remote_file_paths(value)
117
- end
118
- end
119
-
120
- def check_old_remote_file_paths(url)
121
- new_url = url.dup
122
-
123
- if @remote_gem_version[1..-1] < '0.6.6'
124
- new_url.gsub!('playbook/', '')
125
- new_url.gsub!('includes/site.yml', 'play.rb')
126
- end
127
-
128
- new_url
129
- end
130
-
131
- def select_branch(branch, value)
132
- "#{repo_path[0]}/#{branch}/#{repo_path[1]}/#{value}"
133
- end
134
-
135
- def process_unusable?(command, process, phrase)
136
- command_output = run(command, capture: true)
137
-
138
- log_error 'error', "Cannot detect #{process}", 'question', "Are you sure #{process} is #{phrase}?", true do
139
- log_status_bottom 'tip', "#{process} must be #{phrase} before running this orats command", :white
140
- end if command_output.empty?
141
-
142
- command_output.empty?
143
- end
144
- end
145
- end
146
- end
@@ -1,106 +0,0 @@
1
- module Orats
2
- module Commands
3
- module Diff
4
- module Compare
5
- def remote_gem_vs_yours
6
- log_remote_info 'gem',
7
- 'Compare your orats version to the latest version',
8
- 'version',
9
- "You have v#{VERSION} and the latest version is #{@remote_gem_version}"
10
- end
11
-
12
- def remote_vs_yours(label, remote, yours, exact_match)
13
- log_remote_info label,
14
- "Compare your #{label} to the latest version (#{@remote_gem_version})",
15
- 'file', File.basename(Common::RELATIVE_PATHS[label
16
- .to_sym])
17
-
18
- outdated_and_missing = difference(remote, yours, exact_match, true)
19
- extras = difference(yours, remote, exact_match)
20
- both_lists = outdated_and_missing + extras
21
- sorted_diff = sort_difference(both_lists).uniq { |item| item[:name] }
22
-
23
- if sorted_diff.empty?
24
- log_status_bottom 'results', 'no differences were found',
25
- :magenta, true
26
- else
27
- padded_length = pad_by(sorted_diff)
28
-
29
- sorted_diff.each do |item|
30
- name = sorted_diff.empty? ? item[:name] : item[:name].ljust(padded_length)
31
- version = item[:version].empty? ? '' : "#{set_color('|',
32
- :cyan)} #{item[:version]}"
33
-
34
- log_status_bottom item[:status], "#{name} #{version}",
35
- item[:color], true
36
- end
37
- end
38
- end
39
-
40
- private
41
-
42
- def name_and_version_from_line(line)
43
- line.split(',')
44
- end
45
-
46
- def pad_by(sorted_diff)
47
- longest_role = sorted_diff.max_by { |s| s[:name].length }
48
- longest_role[:name].length
49
- end
50
-
51
- def sort_difference(diff_list)
52
- # custom sort order on the color key
53
- diff_list.sort_by { |item| {red: 1,
54
- yellow: 2,
55
- green: 3}[item[:color]] }
56
- end
57
-
58
- def difference(remote, yours, exact_match, missing_and_outdated = false)
59
- @diff_list = []
60
- yours_as_string = yours.join
61
-
62
- if missing_and_outdated
63
- diff = remote - yours
64
-
65
- diff.each do |line|
66
- line_parts = name_and_version_from_line(line)
67
- status = 'outdated'
68
- color = :yellow
69
- search_contents = exact_match ? yours : yours_as_string
70
-
71
- unless search_contents.include?(line_parts[0])
72
- status = 'missing'
73
- color = :red
74
- end
75
-
76
- @diff_list.push({
77
- color: color,
78
- status: status,
79
- name: line_parts[0],
80
- version: line_parts[1] || ''
81
- })
82
-
83
- end
84
- else
85
- remote.each do |line|
86
- unless yours.include?(line)
87
- line_parts = name_and_version_from_line(line)
88
- status = 'extra'
89
- color = :green
90
-
91
- @diff_list.push({
92
- color: color,
93
- status: status,
94
- name: line_parts[0],
95
- version: line_parts[1] || ''
96
- })
97
- end
98
- end
99
- end
100
-
101
- @diff_list
102
- end
103
- end
104
- end
105
- end
106
- end