ops_team 0.9.2 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a168c8803f5f12ecc5ba54fc77e4a304baa300aa100e2d81d92b2f5146551d7
4
- data.tar.gz: dec291b877b6cc0fc056feb794e676abd56f5376b8373f914b6c24dfd3d7462d
3
+ metadata.gz: cf41e11aef46cc62ac4ce648aac3c84ed2de854a23ffe8cc2a89d9a678fde503
4
+ data.tar.gz: 84bb677017c9e7ff084f6c3635a6228c26080736c1f27ccfdb6b9a761f3b1f33
5
5
  SHA512:
6
- metadata.gz: d96bea7054642ba35750f8efa59d6a6e2201dce98aaa5471dda573704ceb66f5daedf38f9cd7a68d2b31f9bd53ad17fff85790f61fe04fca8221ac9299140ddb
7
- data.tar.gz: 86b51b059eca72ba60f30c2be14c83bc40e4e1c872c3edaa91bab6a94080eb34a59eda351ef796d42d903216ca71f1fd8059d031773fb0b1efd2e7f2b498e4f5
6
+ metadata.gz: 6319116434905f139d5b9853f96cfe7efa9934d34f66df17a0abc1aed531b4389ab163039c867560a53b27738c472f5642aa9de1af7d528b9e2f2d9b6073dc49
7
+ data.tar.gz: ff9c8c68c014e39616e572e6fe74fc988d15807da12fd4c99fc7d91144d667bb7e386c62f68af659ca349116566adbc5a473b77a8be33c75dffcd69b6fbfd661
@@ -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,6 +27,10 @@ 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
35
  Output.notice("Running '#{args.join(' ')}' with stderr and stdout redirected to '#{Background.log_filename}'")
38
36
  $stdout.sync = $stderr.sync = true
@@ -41,10 +39,6 @@ module Builtins
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
 
@@ -15,7 +15,12 @@ module Builtins
15
15
 
16
16
  def run
17
17
  Secrets.load if Options.get("exec.load_secrets")
18
- Kernel.exec(@args.join(" "))
18
+
19
+ if args.any?
20
+ Kernel.exec(args.join(" "))
21
+ else
22
+ Output.error("Usage: ops exec '<command>'")
23
+ end
19
24
  end
20
25
  end
21
26
  end
@@ -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
@@ -77,8 +77,16 @@ class Ops
77
77
  end
78
78
 
79
79
  def actions
80
- config["actions"].transform_values do |config|
81
- Action.new(config, @args)
80
+ @actions ||= begin
81
+ if config["actions"]
82
+ config["actions"]&.transform_values do |config|
83
+ Action.new(config, @args)
84
+ end
85
+ else
86
+ # only print this error if ops.yml had something in it
87
+ Output.warn("'ops.yml' has no 'actions' defined.") if config.any?
88
+ {}
89
+ end
82
90
  end
83
91
  end
84
92
 
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ops_team'
5
- s.version = '0.9.2'
5
+ s.version = '0.9.7'
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.2
4
+ version: 0.9.7
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