moonshot 2.0.0.beta6 → 2.0.0.beta7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +5 -5
  2. data/bin/moonshot +4 -1
  3. data/lib/default/bin/build.sh +0 -0
  4. data/lib/moonshot/account_context.rb +2 -0
  5. data/lib/moonshot/always_use_default_source.rb +5 -4
  6. data/lib/moonshot/artifact_repository/s3_bucket.rb +11 -5
  7. data/lib/moonshot/artifact_repository/s3_bucket_via_github_releases.rb +7 -7
  8. data/lib/moonshot/ask_user_source.rb +2 -0
  9. data/lib/moonshot/build_mechanism/github_release.rb +9 -2
  10. data/lib/moonshot/build_mechanism/script.rb +8 -7
  11. data/lib/moonshot/build_mechanism/travis_deploy.rb +5 -5
  12. data/lib/moonshot/build_mechanism/version_proxy.rb +13 -0
  13. data/lib/moonshot/change_set.rb +17 -35
  14. data/lib/moonshot/command.rb +3 -1
  15. data/lib/moonshot/command_line.rb +12 -9
  16. data/lib/moonshot/command_line_dispatcher.rb +5 -7
  17. data/lib/moonshot/commands/build.rb +6 -0
  18. data/lib/moonshot/commands/console.rb +2 -0
  19. data/lib/moonshot/commands/create.rb +14 -2
  20. data/lib/moonshot/commands/delete.rb +9 -0
  21. data/lib/moonshot/commands/deploy.rb +4 -8
  22. data/lib/moonshot/commands/doctor.rb +2 -0
  23. data/lib/moonshot/commands/generate_template.rb +46 -0
  24. data/lib/moonshot/commands/interactive_command.rb +15 -0
  25. data/lib/moonshot/commands/list.rb +2 -0
  26. data/lib/moonshot/commands/new.rb +5 -2
  27. data/lib/moonshot/commands/parameter_arguments.rb +5 -4
  28. data/lib/moonshot/commands/parent_stack_option.rb +2 -0
  29. data/lib/moonshot/commands/push.rb +2 -0
  30. data/lib/moonshot/commands/show_all_events_option.rb +2 -0
  31. data/lib/moonshot/commands/ssh.rb +4 -0
  32. data/lib/moonshot/commands/status.rb +2 -0
  33. data/lib/moonshot/commands/update.rb +7 -1
  34. data/lib/moonshot/commands/version.rb +2 -0
  35. data/lib/moonshot/controller.rb +28 -13
  36. data/lib/moonshot/controller_config.rb +12 -27
  37. data/lib/moonshot/creds_helper.rb +2 -0
  38. data/lib/moonshot/deployment_mechanism/code_deploy.rb +44 -37
  39. data/lib/moonshot/doctor_helper.rb +14 -15
  40. data/lib/moonshot/dynamic_template.rb +76 -0
  41. data/lib/moonshot/interactive_logger_proxy.rb +4 -4
  42. data/lib/moonshot/json_stack_template.rb +3 -0
  43. data/lib/moonshot/parameter_collection.rb +3 -0
  44. data/lib/moonshot/parent_stack_parameter_loader.rb +7 -3
  45. data/lib/moonshot/resources.rb +2 -0
  46. data/lib/moonshot/resources_helper.rb +5 -1
  47. data/lib/moonshot/shell.rb +8 -8
  48. data/lib/moonshot/ssh_command.rb +2 -0
  49. data/lib/moonshot/ssh_command_builder.rb +3 -1
  50. data/lib/moonshot/ssh_config.rb +3 -2
  51. data/lib/moonshot/ssh_fork_executor.rb +2 -0
  52. data/lib/moonshot/ssh_target_selector.rb +3 -1
  53. data/lib/moonshot/stack.rb +50 -46
  54. data/lib/moonshot/stack_asg_printer.rb +14 -12
  55. data/lib/moonshot/stack_config.rb +3 -2
  56. data/lib/moonshot/stack_events_poller.rb +3 -1
  57. data/lib/moonshot/stack_list_printer.rb +2 -0
  58. data/lib/moonshot/stack_lister.rb +6 -2
  59. data/lib/moonshot/stack_output_printer.rb +2 -0
  60. data/lib/moonshot/stack_parameter.rb +5 -9
  61. data/lib/moonshot/stack_parameter_printer.rb +3 -1
  62. data/lib/moonshot/stack_template.rb +2 -0
  63. data/lib/moonshot/task.rb +3 -0
  64. data/lib/moonshot/tools/asg_rollout/asg.rb +19 -21
  65. data/lib/moonshot/tools/asg_rollout/asg_instance.rb +2 -0
  66. data/lib/moonshot/tools/asg_rollout/hook_exec_environment.rb +2 -0
  67. data/lib/moonshot/tools/asg_rollout/instance_health.rb +2 -0
  68. data/lib/moonshot/tools/asg_rollout.rb +16 -14
  69. data/lib/moonshot/tools/asg_rollout_config.rb +2 -0
  70. data/lib/moonshot/unicode_table.rb +1 -1
  71. data/lib/moonshot/yaml_stack_template.rb +2 -0
  72. data/lib/moonshot.rb +13 -1
  73. data/lib/plugins/backup.rb +24 -30
  74. data/lib/plugins/code_deploy_setup.rb +4 -2
  75. data/lib/plugins/dynamic_template.rb +36 -0
  76. data/lib/plugins/encrypted_parameters/kms_key.rb +2 -0
  77. data/lib/plugins/encrypted_parameters/parameter_encrypter.rb +2 -0
  78. data/lib/plugins/encrypted_parameters.rb +3 -1
  79. metadata +124 -57
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 29bfc137789e7c406cf1a235f693e12b142baa97
4
- data.tar.gz: a3a9eb8d496c61bb93f9cb7f1d97e41f6dd06fd9
2
+ SHA256:
3
+ metadata.gz: bacc77a06be77c55f7f4e73d73d9e62cdccf5b9fbb8187026f0e0ae1cc3c4732
4
+ data.tar.gz: 27d5031220c00c7a1abc4653c2280223d1f74a4d38c285cd77da8cb743cb2257
5
5
  SHA512:
6
- metadata.gz: '00381ff4a8552595b8aaa0f1cec95b6c892045cad3b6a6c921bd5fb5e379405db1f7491a4282b68c18aaa55a441ce43df078b5a4100457cf2e28a9024918b737'
7
- data.tar.gz: 0e84cbf7b3f6378991a8faf7070a143f14fdca00eccea19d6ae457f0284c725975e16723151da2bc5b3185d33c472ddd0ee028f894fab70059187b25393d0fdf
6
+ metadata.gz: b734d33a71f63b80962adb425438c0ece07baba1a0cb66c8a6b8b1be337991438bf427ce1d80582502d3b4ff6ab6e12bfe45df927731a17ddd3ff4961c9178d8
7
+ data.tar.gz: de00cd0374f40133d472808c67dc32049c276ea79e4200ea6a471a67b2d831747596b2659f8669009532211ac0851cde1bc36cd91510d41917e8db4446308994
data/bin/moonshot CHANGED
@@ -1,11 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require 'moonshot'
3
5
 
4
6
  # This is the main entry point for the `moonshot` command-line tool.
5
7
  begin
6
8
  Moonshot::CommandLine.new.run!
7
- rescue => e
9
+ rescue StandardError => e
8
10
  warn "#{e} (at #{e.backtrace.first})"
9
11
  raise e if ENV['MOONSHOT_BACKTRACE']
12
+
10
13
  exit 1
11
14
  end
File without changes
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Moonshot
2
4
  module AccountContext
3
5
  def self.get
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Moonshot
2
4
  # The AlwaysUseDefaultSource will always use the previous value in
3
5
  # the stack, or use the default value during stack creation. This is
@@ -6,12 +8,11 @@ module Moonshot
6
8
  # answer files or command-line arguments will always apply.
7
9
  class AlwaysUseDefaultSource
8
10
  def get(sp)
9
- unless sp.default?
10
- raise "Parameter #{sp.name} does not have a default, cannot use AlwaysUseDefaultSource!"
11
- end
12
-
13
11
  # Don't do anything, the default will apply on create, and the
14
12
  # previous value will be used on update.
13
+ return if sp.default?
14
+
15
+ raise "Parameter #{sp.name} does not have a default, cannot use AlwaysUseDefaultSource!"
15
16
  end
16
17
  end
17
18
  end
@@ -1,3 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../resources_helper'
4
+ require_relative '../creds_helper'
5
+ require_relative '../doctor_helper'
6
+
1
7
  # The S3Bucket stores builds in an S3 Bucket.
2
8
  #
3
9
  # For example:
@@ -19,7 +25,7 @@ class Moonshot::ArtifactRepository::S3Bucket
19
25
 
20
26
  def store_hook(build_mechanism, version_name)
21
27
  unless build_mechanism.respond_to?(:output_file)
22
- raise "S3Bucket does not know how to store artifacts from #{build_mechanism.class}, no method '#output_file'." # rubocop:disable LineLength
28
+ raise "S3Bucket does not know how to store artifacts from #{build_mechanism.class}, no method '#output_file'."
23
29
  end
24
30
 
25
31
  file = build_mechanism.output_file
@@ -41,7 +47,7 @@ class Moonshot::ArtifactRepository::S3Bucket
41
47
  def upload_to_s3(file, key)
42
48
  s3_client.put_object(
43
49
  acl: 'bucket-owner-full-control',
44
- key: key,
50
+ key:,
45
51
  body: File.open(file),
46
52
  bucket: @bucket_name,
47
53
  storage_class: 'STANDARD_IA'
@@ -51,7 +57,7 @@ class Moonshot::ArtifactRepository::S3Bucket
51
57
  def doctor_check_bucket_exists
52
58
  s3_client.get_bucket_location(bucket: @bucket_name)
53
59
  success "Bucket '#{@bucket_name}' exists."
54
- rescue => e
60
+ rescue StandardError => e
55
61
  # This is warning because the role you use for deployment may not actually
56
62
  # be able to read builds, however the instance role assigned to the nodes
57
63
  # might.
@@ -68,9 +74,9 @@ class Moonshot::ArtifactRepository::S3Bucket
68
74
  )
69
75
  s3_client.delete_object(key: 'test-object', bucket: @bucket_name)
70
76
  success 'Bucket is writable, new builds can be uploaded.'
71
- rescue => e
77
+ rescue StandardError => e
72
78
  # This is a warning because you may deploy to an environment where you have
73
79
  # read access to builds, but could not publish a new build.
74
- warning('Could not write to bucket, you may still be able to deploy existing builds.', e.message) # rubocop:disable LineLength
80
+ warning('Could not write to bucket, you may still be able to deploy existing builds.', e.message)
75
81
  end
76
82
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'moonshot/artifact_repository/s3_bucket'
2
4
  require 'moonshot/shell'
3
5
  require 'digest'
@@ -9,7 +11,7 @@ require 'retriable'
9
11
  module Moonshot::ArtifactRepository
10
12
  # S3 Bucket repository backed by GitHub releases.
11
13
  # If a SemVer package isn't found in S3, it is copied from GitHub releases.
12
- class S3BucketViaGithubReleases < S3Bucket # rubocop:disable ClassLength
14
+ class S3BucketViaGithubReleases < S3Bucket # rubocop:disable Metrics/ClassLength
13
15
  include Moonshot::BuildMechanism
14
16
  include Moonshot::Shell
15
17
 
@@ -36,9 +38,7 @@ module Moonshot::ArtifactRepository
36
38
  # artifact repositories a hook before deploy.
37
39
  def filename_for_version(version)
38
40
  s3_name = super
39
- if !@output_file && release?(version) && !in_s3?(s3_name)
40
- github_to_s3(version, s3_name)
41
- end
41
+ github_to_s3(version, s3_name) if !@output_file && release?(version) && !in_s3?(s3_name)
42
42
  s3_name
43
43
  end
44
44
 
@@ -51,7 +51,7 @@ module Moonshot::ArtifactRepository
51
51
  end
52
52
 
53
53
  def in_s3?(key)
54
- s3_client.head_object(key: key, bucket: bucket_name)
54
+ s3_client.head_object(key:, bucket: bucket_name)
55
55
  rescue ::Aws::S3::Errors::NotFound
56
56
  false
57
57
  end
@@ -62,7 +62,7 @@ module Moonshot::ArtifactRepository
62
62
 
63
63
  # If there is a checksum file, attach it as well. We only support MD5
64
64
  # since that's what S3 uses.
65
- checksum_file = File.basename(file, '.tar.gz') + '.md5'
65
+ checksum_file = "#{File.basename(file, '.tar.gz')}.md5"
66
66
  cmd += " --attach=#{checksum_file}" if File.exist?(checksum_file)
67
67
 
68
68
  sh_step(cmd)
@@ -218,7 +218,7 @@ module Moonshot::ArtifactRepository
218
218
 
219
219
  def doctor_check_hub_release_download
220
220
  sh_out('hub release download --help')
221
- rescue
221
+ rescue StandardError
222
222
  critical '`hub release download` command missing, upgrade hub.' \
223
223
  ' See https://github.com/github/hub/pull/1103'
224
224
  else
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'colorize'
2
4
 
3
5
  module Moonshot
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'forwardable'
2
4
  require 'moonshot/shell'
3
5
  require 'open3'
@@ -31,6 +33,8 @@ module Moonshot::BuildMechanism
31
33
  parser.on('-s', '--[no-]skip-ci-status', 'Skips checks on CI jobs', TrueClass) do |value|
32
34
  @skip_ci_status = value
33
35
  end
36
+
37
+ parser
34
38
  end
35
39
 
36
40
  def doctor_hook
@@ -83,6 +87,8 @@ module Moonshot::BuildMechanism
83
87
  say("Changelog for #{version}", :yellow)
84
88
  say("#{@changes}\n\n")
85
89
 
90
+ return unless Moonshot.config.interactive
91
+
86
92
  q = "Do you want to tag and release this commit as #{version}? [y/n]"
87
93
  raise 'Release declined.' unless yes?(q)
88
94
  end
@@ -131,6 +137,7 @@ module Moonshot::BuildMechanism
131
137
 
132
138
  def hub_create_release(semver, commitish, changelog_entry)
133
139
  return if hub_release_exists(semver)
140
+
134
141
  message = "#{semver}\n\n#{changelog_entry}"
135
142
  cmd = "hub release create #{semver} --commitish=#{commitish}"
136
143
  cmd << ' --prerelease' if semver.pre || semver.build
@@ -216,7 +223,7 @@ module Moonshot::BuildMechanism
216
223
 
217
224
  def doctor_check_upstream
218
225
  sh_out('git remote | grep ^upstream$')
219
- rescue => e
226
+ rescue StandardError => e
220
227
  critical "git remote `upstream` not found.\n#{e.message}"
221
228
  else
222
229
  success 'git remote `upstream` exists.'
@@ -224,7 +231,7 @@ module Moonshot::BuildMechanism
224
231
 
225
232
  def doctor_check_hub_auth
226
233
  sh_out('hub ci-status 0.0.0')
227
- rescue => e
234
+ rescue StandardError => e
228
235
  critical "`hub` failed, install hub and authorize it.\n#{e.message}"
229
236
  else
230
237
  success '`hub` installed and authorized.'
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'open3'
2
- include Open3
3
4
 
4
5
  # Compile a release artifact using a shell script.
5
6
  #
@@ -18,6 +19,8 @@ class Moonshot::BuildMechanism::Script
18
19
  include Moonshot::ResourcesHelper
19
20
  include Moonshot::DoctorHelper
20
21
 
22
+ include Open3
23
+
21
24
  attr_reader :output_file
22
25
 
23
26
  def initialize(script, output_file: 'output.tar.gz')
@@ -35,12 +38,12 @@ class Moonshot::BuildMechanism::Script
35
38
  'OUTPUT_FILE' => @output_file
36
39
  }
37
40
  ilog.start_threaded "Running Script: #{@script}" do |s|
38
- run_script(s, env: env)
41
+ run_script(s, env:)
39
42
  end
40
43
  end
41
44
 
42
45
  def post_build_hook(_version)
43
- unless File.exist?(@output_file) # rubocop:disable GuardClause
46
+ unless File.exist?(@output_file) # rubocop:disable Style/GuardClause
44
47
  raise 'Build command did not produce output file!'
45
48
  end
46
49
  end
@@ -61,10 +64,8 @@ class Moonshot::BuildMechanism::Script
61
64
  end
62
65
 
63
66
  result = wait.value
64
- if result.exitstatus == 0
65
- step.success "Build script #{@script} exited successfully!"
66
- end
67
- unless result.exitstatus == 0
67
+ step.success "Build script #{@script} exited successfully!" if result.exitstatus.zero?
68
+ unless result.exitstatus.zero?
68
69
  ilog.error "Build script failed with exit status #{result.exitstatus}!"
69
70
  ilog.error output.join("\n")
70
71
  step.failure "Build script #{@script} failed with exit status #{result.exitstatus}!"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'moonshot/shell'
2
4
  require 'travis'
3
5
  require 'travis/pro'
@@ -25,8 +27,7 @@ module Moonshot::BuildMechanism
25
27
  @cli_args = "-r #{@slug} #{@endpoint}"
26
28
  end
27
29
 
28
- def pre_build_hook(_)
29
- end
30
+ def pre_build_hook(_); end
30
31
 
31
32
  def build_hook(version)
32
33
  job_number = find_build_and_job(version)
@@ -34,8 +35,7 @@ module Moonshot::BuildMechanism
34
35
  check_build(version)
35
36
  end
36
37
 
37
- def post_build_hook(_)
38
- end
38
+ def post_build_hook(_); end
39
39
 
40
40
  private
41
41
 
@@ -120,7 +120,7 @@ module Moonshot::BuildMechanism
120
120
 
121
121
  def doctor_check_travis_auth
122
122
  sh_out("bundle exec travis raw #{@endpoint} repos/#{@slug}")
123
- rescue => e
123
+ rescue StandardError => e
124
124
  critical "`travis` not available or not authorized.\n#{e.message}"
125
125
  else
126
126
  success '`travis` installed and authorized.'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'forwardable'
2
4
  require 'semantic'
3
5
 
@@ -37,6 +39,17 @@ class Moonshot::BuildMechanism::VersionProxy
37
39
  active(version).post_build_hook(version)
38
40
  end
39
41
 
42
+ def build_cli_hook(parser)
43
+ # Expose any command line arguments provided by the build mechanisms. We
44
+ # don't know the version at this point, so we can't call the hook on only
45
+ # the one we're going to use, which may result in options being exposed that
46
+ # are only applicable for one of the build mechanisms.
47
+ parser = @release.build_cli_hook(parser) if @release.respond_to?(:build_cli_hook)
48
+ parser = @dev.build_cli_hook(parser) if @dev.respond_to?(:build_cli_hook)
49
+
50
+ parser
51
+ end
52
+
40
53
  private
41
54
 
42
55
  def active(version)
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Moonshot
2
4
  class ChangeSet
3
- attr_reader :name
4
- attr_reader :stack_name
5
+ attr_reader :name, :stack_name
5
6
 
6
7
  def initialize(name, stack_name)
7
8
  @name = name
@@ -11,9 +12,7 @@ module Moonshot
11
12
  end
12
13
 
13
14
  def confirm?
14
- unless Moonshot.config.interactive
15
- raise 'Cannot confirm ChangeSet when interactive mode is disabled!'
16
- end
15
+ raise 'Cannot confirm ChangeSet when interactive mode is disabled!' unless Moonshot.config.interactive
17
16
 
18
17
  loop do
19
18
  print 'Apply changes? '
@@ -21,6 +20,7 @@ module Moonshot
21
20
 
22
21
  return true if resp == 'yes'
23
22
  return false if resp == 'no'
23
+
24
24
  puts "Please enter 'yes' or 'no'!"
25
25
  end
26
26
  end
@@ -39,9 +39,10 @@ module Moonshot
39
39
  @change_set.changes.map(&:resource_change).each do |c|
40
40
  puts "* #{c.action} #{c.logical_resource_id} (#{c.resource_type})"
41
41
 
42
- if c.replacement == 'True'
42
+ case c.replacement
43
+ when 'True'
43
44
  puts ' - Will be replaced'
44
- elsif c.replacement == 'Conditional'
45
+ when 'Conditional'
45
46
  puts ' - May be replaced (Conditional)'
46
47
  end
47
48
 
@@ -60,47 +61,28 @@ module Moonshot
60
61
  wait_for_change_set unless @change_set
61
62
  @cf_client.execute_change_set(
62
63
  change_set_name: @name,
63
- stack_name: @stack_name)
64
+ stack_name: @stack_name
65
+ )
64
66
  end
65
67
 
66
68
  def delete
67
69
  wait_for_change_set unless @change_set
68
70
  @cf_client.delete_change_set(
69
71
  change_set_name: @name,
70
- stack_name: @stack_name)
72
+ stack_name: @stack_name
73
+ )
71
74
  rescue Aws::CloudFormation::Errors::InvalidChangeSetStatus
72
75
  sleep 1
73
76
  retry
74
77
  end
75
78
 
76
- # NOTE: At the time of this patch, AWS-SDK native Waiters do not
77
- # have support for ChangeSets. Once they add this, we can make
78
- # this code much better.
79
- # Still no support for this waiter, but it's planned.
80
- # https://github.com/aws/aws-sdk-ruby/issues/1388
81
79
  def wait_for_change_set
82
- wait_seconds = Moonshot.config.changeset_wait_time || 90
83
- start = Time.now.to_i
84
-
85
- loop do
86
- resp = @cf_client.describe_change_set(
87
- change_set_name: @name,
88
- stack_name: @stack_name)
80
+ @cf_client.wait_until(:change_set_create_complete,
81
+ stack_name: @stack_name,
82
+ change_set_name: @name)
89
83
 
90
- if %w(CREATE_COMPLETE FAILED).include?(resp.status)
91
- @change_set = resp
92
- return
93
- end
94
-
95
- if Time.now.to_i > start + wait_seconds
96
- raise "ChangeSet did not complete creation within #{wait_seconds} seconds!"
97
- end
98
-
99
- sleep 5 # http://bit.ly/1qY1ZXJ
100
- # Wait 5 seconds because other waiters seem to wait at least 5 seconds
101
- # before repeating requests.
102
- # See: https://github.com/aws/aws-sdk-ruby/blob/master/aws-sdk-core/apis/cloudformation/2010-05-15/waiters-2.json#L5
103
- end
84
+ @change_set = @cf_client.describe_change_set(stack_name: @stack_name,
85
+ change_set_name: @name)
104
86
  end
105
87
  end
106
88
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'optparse'
2
4
 
3
5
  module Moonshot
@@ -44,7 +46,7 @@ module Moonshot
44
46
  # Degrade to a more compatible logger if the terminal seems outdated,
45
47
  # or at the users request.
46
48
  if !$stdout.isatty || !@use_interactive_logger
47
- log = Logger.new(STDOUT)
49
+ log = Logger.new($stdout)
48
50
  controller.config.interactive_logger = InteractiveLoggerProxy.new(log)
49
51
  end
50
52
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Moonshot
2
4
  # This class implements the command-line `moonshot` tool.
3
5
  class CommandLine
@@ -10,7 +12,7 @@ module Moonshot
10
12
  @classes || []
11
13
  end
12
14
 
13
- def run! # rubocop:disable CyclomaticComplexity, MethodLength, PerceivedComplexity
15
+ def run! # rubocop:disable Metrics/MethodLength
14
16
  # Commands defined as Moonshot::Commands require a properly
15
17
  # configured Moonshot.rb and supporting files. Without them, we only
16
18
  # support `--help` and `new`.
@@ -24,7 +26,7 @@ module Moonshot
24
26
 
25
27
  if Dir.pwd == '/'
26
28
  warn 'No Moonfile.rb found, are you in a project? Maybe you need to '\
27
- 'create one with `moonshot new <app_name>`?'
29
+ 'create one with `moonshot new <app_name>`?'
28
30
  raise 'No Moonfile found'
29
31
  end
30
32
 
@@ -51,7 +53,7 @@ module Moonshot
51
53
 
52
54
  # Determine what command is being run, which should be the first argument.
53
55
  command = ARGV.shift
54
- if %w(--help -h help).include?(command) || command.nil?
56
+ if %w[--help -h help].include?(command) || command.nil?
55
57
  usage
56
58
  return
57
59
  end
@@ -94,7 +96,7 @@ module Moonshot
94
96
  max_len = fields.map(&:first).map(&:size).max
95
97
 
96
98
  fields.each do |f|
97
- line = format(" %-#{max_len}s # %s", *f)
99
+ line = format(" %-#{max_len}s # %s", *f) # rubocop:disable Lint/FormatParameterMismatch
98
100
  warn line
99
101
  end
100
102
  end
@@ -117,9 +119,9 @@ module Moonshot
117
119
 
118
120
  def commandify(klass)
119
121
  word = klass.to_s.split('::').last
120
- word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'.freeze)
121
- word.gsub!(/([a-z\d])([A-Z])/, '\1_\2'.freeze)
122
- word.tr!('_'.freeze, '-'.freeze)
122
+ word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
123
+ word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
124
+ word.tr!('_', '-')
123
125
  word.downcase!
124
126
  word
125
127
  end
@@ -127,10 +129,11 @@ module Moonshot
127
129
  def handle_early_commands
128
130
  # If this is a legacy (Thor) help command, re-write it as
129
131
  # OptionParser format.
130
- if ARGV[0] == 'help'
132
+ case ARGV[0]
133
+ when 'help'
131
134
  ARGV.delete_at(0)
132
135
  ARGV.push('-h')
133
- elsif ARGV[0] == 'new'
136
+ when 'new'
134
137
  app_name = ARGV[1]
135
138
  ::Moonshot::Commands::New.run!(app_name)
136
139
  return true
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Moonshot
2
4
  class CommandLineDispatcher
3
5
  def initialize(command, klass, args)
@@ -46,18 +48,14 @@ module Moonshot
46
48
 
47
49
  # Each mechanism / plugin may manipulate the OptionParser object
48
50
  # associated with this command.
49
- [:build_mechanism, :deployment_mechanism, :artifact_repository].each do |prov|
51
+ %i[build_mechanism deployment_mechanism artifact_repository].each do |prov|
50
52
  provider = Moonshot.config.send(prov)
51
53
 
52
- if provider.respond_to?(hook_func_name(@command))
53
- parser = provider.send(hook_func_name(@command), parser)
54
- end
54
+ parser = provider.send(hook_func_name(@command), parser) if provider.respond_to?(hook_func_name(@command))
55
55
  end
56
56
 
57
57
  Moonshot.config.plugins.each do |plugin|
58
- if plugin.respond_to?(hook_func_name(@command))
59
- parser = plugin.send(hook_func_name(@command), parser)
60
- end
58
+ parser = plugin.send(hook_func_name(@command), parser) if plugin.respond_to?(hook_func_name(@command))
61
59
  end
62
60
 
63
61
  parser
@@ -1,6 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'interactive_command'
4
+
1
5
  module Moonshot
2
6
  module Commands
3
7
  class Build < Moonshot::Command
8
+ include InteractiveCommand
9
+
4
10
  self.usage = 'build VERSION'
5
11
  self.description = 'Build a release artifact, ready for deployment'
6
12
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pry'
2
4
 
3
5
  module Moonshot
@@ -1,3 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'parameter_arguments'
4
+ require_relative 'show_all_events_option'
5
+ require_relative 'parent_stack_option'
6
+
1
7
  module Moonshot
2
8
  module Commands
3
9
  class Create < Moonshot::Command
@@ -14,13 +20,19 @@ module Moonshot
14
20
  @deploy = true
15
21
 
16
22
  parser = super
17
- parser.on('-d', '--[no-]deploy', TrueClass, 'Choose if code should be deployed immediately after the stack is created') do |v| # rubocop:disable LineLength
23
+ desc = 'Choose if code should be deployed immediately after the stack is created'
24
+ parser.on('-d', '--[no-]deploy', TrueClass, desc) do |v|
18
25
  @deploy = v
19
26
  end
20
27
 
21
- parser.on('--version VERSION_NAME', 'Version for initial deployment. If unset, a new development build is created from the local directory') do |v| # rubocop:disable LineLength
28
+ desc = 'Version for initial deployment. If unset, a new development build is created from the local directory'
29
+ parser.on('--version VERSION_NAME', desc) do |v|
22
30
  @version = v
23
31
  end
32
+
33
+ parser.on('--template-file=FILE', 'Override the path to the CloudFormation template.') do |v|
34
+ Moonshot.config.template_file = v
35
+ end
24
36
  end
25
37
 
26
38
  def execute
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Moonshot
2
4
  module Commands
3
5
  class Delete < Moonshot::Command
@@ -6,6 +8,13 @@ module Moonshot
6
8
  self.usage = 'delete [options]'
7
9
  self.description = 'Delete an existing environment'
8
10
 
11
+ def parser
12
+ parser = super
13
+ parser.on('--template-file=FILE', 'Override the path to the CloudFormation template.') do |v|
14
+ Moonshot.config.template_file = v
15
+ end
16
+ end
17
+
9
18
  def execute
10
19
  controller.delete
11
20
  end
@@ -1,17 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Moonshot
2
4
  module Commands
3
5
  class Deploy < Moonshot::Command
6
+ include InteractiveCommand
7
+
4
8
  self.usage = 'deploy VERSION'
5
9
  self.description = 'Deploy a versioned release to the environment'
6
10
 
7
- def parser
8
- parser = super
9
-
10
- parser.on('--[no-]interactive', TrueClass, 'Use interactive prompts.') do |v|
11
- Moonshot.config.interactive = v
12
- end
13
- end
14
-
15
11
  def execute(version_name)
16
12
  controller.deploy_version(version_name)
17
13
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Moonshot
2
4
  module Commands
3
5
  class Doctor < Moonshot::Command