ops_team 0.9.1 → 0.9.6

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: 70498a1ccc87cf4bf2ddd7ad29028785f02d8dc5a6c8ea44f181a1db5d8e8fea
4
- data.tar.gz: e43c220a41cf3956c14bc077ead9abf64f5502960ad46c6c49915a3a51a4b76d
3
+ metadata.gz: c1dc62ca13a4fa0fb9fc2b6ebe6b06016dac94ff1f05308890cfa010369bb12e
4
+ data.tar.gz: 89936730eb61c53c23c873af7ff1fd6c9d410204be7de027b6a9b45c062b47f7
5
5
  SHA512:
6
- metadata.gz: be7def6a15311c5bed82a39b898a22d9aaeacd7058abecd1cdea47cef341439b78af9c9271cccf8ecdf5f9445c6be1d8fb76d44650a18654e0b22dd69b64dbd7
7
- data.tar.gz: ad1cb8908108aae55c985b8b513421ad4669143a40a79db2fa064c1f4b07615b82fc736af36d766432204f459bd0cc467af8fa8743b8ff3c03b5af9aa4f259b5
6
+ metadata.gz: c51e41abec028542d7aa60a8aae7efbd1e3a6a9422f5e6ac3c8175ab9f094cece843616eb68dd7f5ddf993fe19ddf1fbca736c1a822397eec583f30a746315c0
7
+ data.tar.gz: e612fd4349b5468a876f1398663859048031964808a4ff0ef55a9dc6e429052780d1ead4abba28470fc4d7f687014ee8f7d63ae9be3b9c509c7d037be97070ea
@@ -23,7 +23,7 @@ class AppConfig
23
23
 
24
24
  def load
25
25
  config['environment']&.each do |key, value|
26
- ENV[key] = value.to_s
26
+ ENV[key] = value.is_a?(Hash) || value.is_a?(Array) ? value.to_json : value.to_s
27
27
  end
28
28
  end
29
29
 
@@ -4,7 +4,6 @@ require 'builtin'
4
4
 
5
5
  module Builtins
6
6
  class Background < Builtin
7
- DEFAULT_SHELL = "bash"
8
7
  DEFAULT_LOG_FILE_PREFIX = "/tmp/ops_bglog_"
9
8
 
10
9
  class << self
@@ -13,18 +12,13 @@ module Builtins
13
12
  end
14
13
 
15
14
  def log_filename
16
- "#{log_filename_prefix}#{Ops.project_name}"
17
- end
18
-
19
- private
20
-
21
- def log_filename_prefix
22
- Options.get("background.log_filename_prefix") || DEFAULT_LOG_FILE_PREFIX
15
+ Options.get("background.log_filename") || "#{DEFAULT_LOG_FILE_PREFIX}#{Ops.project_name}"
23
16
  end
24
17
  end
25
18
 
26
19
  def run
27
20
  subprocess = fork do
21
+ set_bglog_file_permissions
28
22
  run_ops(args)
29
23
  end
30
24
 
@@ -33,18 +27,18 @@ module Builtins
33
27
 
34
28
  private
35
29
 
30
+ def set_bglog_file_permissions
31
+ File.new(Background.log_filename, "w").chmod(0o600)
32
+ end
33
+
36
34
  def run_ops(args)
37
- Output.warn("Running '#{args.join(' ')}' with stderr and stdout redirected to '#{Background.log_filename}'")
35
+ Output.notice("Running '#{args.join(' ')}' with stderr and stdout redirected to '#{Background.log_filename}'")
38
36
  $stdout.sync = $stderr.sync = true
39
37
  $stdout.reopen(Background.log_filename, "w")
40
38
  $stderr.reopen($stdout)
41
39
 
42
40
  Ops.new(args).run
43
41
  end
44
-
45
- def shell
46
- Options.get("background.shell") || DEFAULT_SHELL
47
- end
48
42
  end
49
43
 
50
44
  # set an alias
@@ -18,7 +18,17 @@ module Builtins
18
18
  end
19
19
 
20
20
  Output.notice("Displaying background log '#{Background.log_filename}'...")
21
- exec("tail #{args.join(' ')} '#{Background.log_filename}'")
21
+ display_file
22
+ end
23
+
24
+ private
25
+
26
+ def display_file
27
+ if args.any?
28
+ exec("tail #{args.join(' ')} '#{Background.log_filename}'")
29
+ else
30
+ exec("cat '#{Background.log_filename}'")
31
+ end
22
32
  end
23
33
  end
24
34
 
@@ -23,14 +23,32 @@ module Builtins
23
23
  private
24
24
 
25
25
  def builtins
26
- builtin_class_names.map do |class_name|
27
- description = Builtins.const_get(class_name).description
28
- format("%<name>-35s %<desc>s", name: class_name.downcase.to_s.yellow, desc: description)
26
+ builtin_class_map.map do |klass, name|
27
+ format("%<name>-35s %<desc>s", name: name.downcase.to_s.yellow, desc: klass.description)
28
+ end
29
+ end
30
+
31
+ def builtin_class_map
32
+ builtin_class_names.each_with_object({}) do |name, hash|
33
+ # get the class reference for this name
34
+ constant = const_for(name)
35
+ # check hash for an existing entry for the same class
36
+ existing_name = hash[constant]
37
+
38
+ # if there is an existing key for the same class, and it's longer than the one we just found,
39
+ # skip adding this one one to avoid duplicates, leaving the shortest name for each class
40
+ next if existing_name && existing_name.length <= name.length
41
+
42
+ hash[constant] = name
29
43
  end
30
44
  end
31
45
 
32
46
  def builtin_class_names
33
- Builtins.constants.select { |c| Builtins.const_get(c).is_a? Class }
47
+ @builtin_class_names ||= Builtins.constants.select { |c| const_for(c).is_a?(Class) }.sort
48
+ end
49
+
50
+ def const_for(name)
51
+ Builtins.const_get(name, false)
34
52
  end
35
53
 
36
54
  def actions
@@ -39,7 +57,7 @@ module Builtins
39
57
  name: name.yellow,
40
58
  desc: value["description"] || value["command"]
41
59
  )
42
- end
60
+ end.sort
43
61
  end
44
62
  end
45
63
  end
data/lib/ops.rb CHANGED
@@ -33,7 +33,7 @@ class Ops
33
33
  end
34
34
 
35
35
  def run
36
- exit(INVALID_SYNTAX_EXIT_CODE) unless syntax_valid?
36
+ return exit(INVALID_SYNTAX_EXIT_CODE) unless syntax_valid?
37
37
 
38
38
  run_action
39
39
  rescue UnknownActionError => e
@@ -45,8 +45,7 @@ class Ops
45
45
 
46
46
  def syntax_valid?
47
47
  if @action_name.nil?
48
- # TODO: output to stderr
49
- puts "Usage: ops <action>"
48
+ Output.error("Usage: ops <action>")
50
49
  false
51
50
  else
52
51
  true
@@ -59,7 +58,7 @@ class Ops
59
58
 
60
59
  return builtin.run if builtin
61
60
 
62
- Output.warn("Running '#{action}' from #{CONFIG_FILE} in environment '#{ENV['environment']}'...")
61
+ Output.notice("Running '#{action}' from #{CONFIG_FILE} in environment '#{ENV['environment']}'...")
63
62
  action.run
64
63
  end
65
64
 
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ops_team'
5
- s.version = '0.9.1'
5
+ s.version = '0.9.6'
6
6
  s.authors = [
7
7
  'nickthecook@gmail.com'
8
8
  ]
9
- s.date = '2020-08-11'
9
+ s.date = '2020-08-12'
10
10
  s.summary = 'ops_team handles basic operations tasks for your project, driven by YAML config'
11
11
  s.homepage = 'https://github.com/nickthecook/ops'
12
12
  s.files = Dir[
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ops_team
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - nickthecook@gmail.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-11 00:00:00.000000000 Z
11
+ date: 2020-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bcrypt_pbkdf