ops_team 0.18.0 → 1.0.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
  SHA256:
3
- metadata.gz: 1fe720771051eb12c4f6786c7a9409d8e2ab01e592abb7959349ceba74f47eed
4
- data.tar.gz: d2fdd069587db893f74d599abf875d15dcad4a09c19b94169496527ba462c77f
3
+ metadata.gz: 0e74fe375694383d5cf99385e04c314e804a2ab1aae6b03558b811e78874c65e
4
+ data.tar.gz: 4c9f31d818c8bc456c4c9c37d40d42491dde28ef6e038eee77ff0e7c42e7a6da
5
5
  SHA512:
6
- metadata.gz: 48f067fd6e9379a1b40830defed7652301786020310137c1be4349e8abb5ab45eae478084b6614d807e10db6738531fb1f169c44146445fed77c1b517eabdba5
7
- data.tar.gz: 32d83b0e2cf94f4178f577b3fbc2b9d232bd10f1de3370f5d516fac9e98f86abe1401749428a486c1f436d0d4646ad332f88701e889ac75764e432978f634000
6
+ metadata.gz: 87320ca1362f2691ad4808bca8b7733b2d1be4bc70b4ca06b650267bf5c50c7d69e64a554fc91d246c821e17454794ae0aadb9cca27ea747f7092f5f636a6492
7
+ data.tar.gz: 6b6bee1687f1858a1097931e336ddcf28fe4f50a9b8802cded747a034f4fefddbcab0fd4331bd961a269811384eb574bfca4e4cc69c5cca576a709bcb2cb59e0
@@ -17,8 +17,6 @@ class Action
17
17
  raise NotAllowedInEnvError, "Action not allowed in #{Environment.environment} environment."
18
18
  end
19
19
 
20
- Secrets.load if load_secrets?
21
-
22
20
  Kernel.exec(to_s)
23
21
  end
24
22
 
@@ -56,12 +54,12 @@ class Action
56
54
  end
57
55
  end
58
56
 
59
- private
60
-
61
57
  def load_secrets?
62
- @config["load_secrets"]
58
+ @config["load_secrets"].nil? ? false : @config["load_secrets"]
63
59
  end
64
60
 
61
+ private
62
+
65
63
  def not_in_envs
66
64
  @config["not_in_envs"] || []
67
65
  end
@@ -3,12 +3,15 @@
3
3
  require 'colorize'
4
4
 
5
5
  require 'builtin'
6
+ require 'forwards'
6
7
 
7
8
  module Builtins
8
9
  class Help < Builtin
10
+ NAME_WIDTH = 35
11
+
9
12
  class << self
10
13
  def description
11
- "displays available builtins and actions"
14
+ "displays available builtins, actions, and forwards"
12
15
  end
13
16
  end
14
17
 
@@ -16,15 +19,24 @@ module Builtins
16
19
  Output.out("Builtins:")
17
20
  Output.out(" #{builtins.join("\n ")}")
18
21
  Output.out("")
22
+ Output.out("Forwards:")
23
+ Output.out(" #{forwards.join("\n ")}")
24
+ Output.out("")
19
25
  Output.out("Actions:")
20
26
  Output.out(" #{actions.join("\n ")}")
21
27
  end
22
28
 
23
29
  private
24
30
 
31
+ def forwards
32
+ Forwards.new(@config).forwards.map do |name, dir|
33
+ format("%<name>-#{NAME_WIDTH}s %<desc>s" , name: name.yellow, desc: "#{dir}")
34
+ end
35
+ end
36
+
25
37
  def builtins
26
38
  builtin_class_map.map do |klass, name|
27
- format("%<name>-35s %<desc>s", name: name.downcase.to_s.yellow, desc: klass.description)
39
+ format("%<name>-#{NAME_WIDTH}s %<desc>s", name: name.downcase.to_s.yellow, desc: klass.description)
28
40
  end
29
41
  end
30
42
 
@@ -55,7 +67,7 @@ module Builtins
55
67
  return [] unless @config["actions"]
56
68
 
57
69
  @config["actions"].map do |name, action_config|
58
- format("%<name>-40s %<desc>s",
70
+ format("%<name>-#{NAME_WIDTH}s %<desc>s",
59
71
  name: "#{name.yellow} #{alias_string_for(action_config)}",
60
72
  desc: action_config["description"] || action_config["command"]
61
73
  )
@@ -3,15 +3,6 @@
3
3
  class Executor
4
4
  attr_reader :output, :exit_code
5
5
 
6
- class << self
7
- def execute(command)
8
- @output, status = Open3.capture2e(command)
9
- @exit_code = status.exitstatus
10
-
11
- [@output, @exit_code]
12
- end
13
- end
14
-
15
6
  def initialize(command)
16
7
  @command = command
17
8
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'output'
4
+
5
+ class Forward
6
+ def initialize(dir, args)
7
+ @dir = dir
8
+ @args = args
9
+ end
10
+
11
+ def run
12
+ Output.notice("Forwarding 'ops #{@args.join(" ")}' to '#{@dir}/'...")
13
+
14
+ Dir.chdir(@dir)
15
+ Ops.new(@args).run
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forward'
4
+
5
+ class Forwards
6
+ def initialize(config, args = [])
7
+ @config = config
8
+ @args = args
9
+ end
10
+
11
+ def get(name)
12
+ Forward.new(forwards[name], @args) if forwards[name]
13
+ end
14
+
15
+ def forwards
16
+ @forwards ||= @config["forwards"] || {}
17
+ end
18
+ end
@@ -25,11 +25,18 @@ class HookHandler
25
25
  def execute_hooks(name)
26
26
  hooks(name).each do |hook|
27
27
  Output.notice("Running #{name} hook: #{hook}")
28
- output, exit_code = Executor.execute(hook)
28
+ output, exit_code = execute_hook(hook)
29
29
 
30
30
  next if exit_code.zero?
31
31
 
32
32
  raise HookExecError, "#{name} hook '#{hook}' failed with exit code #{exit_code}:\n#{output}"
33
33
  end
34
34
  end
35
+
36
+ def execute_hook(name)
37
+ executor = Executor.new(name)
38
+ executor.execute
39
+
40
+ [executor.output, executor.exit_code]
41
+ end
35
42
  end
data/lib/ops.rb CHANGED
@@ -13,6 +13,7 @@ require 'environment'
13
13
  require 'version'
14
14
  require 'action_list'
15
15
  require 'action_suggester'
16
+ require 'forwards'
16
17
 
17
18
  require_rel "builtins"
18
19
 
@@ -101,10 +102,13 @@ class Ops
101
102
  end
102
103
 
103
104
  def run_action
105
+ return forward.run if forward
106
+
104
107
  do_before_all
105
108
 
106
109
  return builtin.run if builtin
107
110
 
111
+ raise UnknownActionError, "Unknown action: #{@action_name}" unless action
108
112
  raise ActionConfigError, action.config_errors.join("; ") unless action.config_valid?
109
113
 
110
114
  do_before_action
@@ -122,15 +126,17 @@ class Ops
122
126
  end
123
127
 
124
128
  def do_before_all
125
- environment.set_variables
126
129
  AppConfig.load
130
+ Secrets.load if action && action.load_secrets?
131
+ environment.set_variables
127
132
  end
128
133
 
129
134
  def do_before_action
130
- hook_handler.do_hooks("before") unless ENV["OPS_RUNNING"] || action.skip_hooks?("before")
135
+ return if ENV["OPS_RUNNING"] || action.skip_hooks?("before")
131
136
 
132
137
  # this prevents before hooks from running in ops executed by ops
133
138
  ENV["OPS_RUNNING"] = "1"
139
+ hook_handler.do_hooks("before")
134
140
  end
135
141
 
136
142
  def hook_handler
@@ -148,11 +154,13 @@ class Ops
148
154
  Builtins.constants.select { |c| Builtins.const_get(c).is_a? Class }.map(&:downcase)
149
155
  end
150
156
 
157
+ def forward
158
+ @forward ||= Forwards.new(@config, @args).get(@action_name)
159
+ end
160
+
151
161
  def action
152
162
  return action_list.get(@action_name) if action_list.get(@action_name)
153
163
  return action_list.get_by_alias(@action_name) if action_list.get_by_alias(@action_name)
154
-
155
- raise UnknownActionError, "Unknown action: #{@action_name}"
156
164
  end
157
165
 
158
166
  def action_list
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ops_team'
5
- s.version = '0.18.0'
5
+ s.version = '1.0.0'
6
6
  s.authors = [
7
7
  'nickthecook@gmail.com'
8
8
  ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ops_team
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nickthecook@gmail.com
@@ -175,6 +175,8 @@ files:
175
175
  - lib/dependency.rb
176
176
  - lib/environment.rb
177
177
  - lib/executor.rb
178
+ - lib/forward.rb
179
+ - lib/forwards.rb
178
180
  - lib/hook_handler.rb
179
181
  - lib/ops.rb
180
182
  - lib/options.rb