ops_team 0.9.0 → 0.9.5

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: a811c1178ce7f125d006e4a3839191446cf758bf24dd5b68d10e6778b4aa2927
4
- data.tar.gz: 4b46a9a22a19f533d244c4442ab8c4bbb30479e04c09d4f40f65993faa7f4ea1
3
+ metadata.gz: 68bef8a0a6e0fb892d9d5ef94f6487ee4eaa6ed8f07d3b5f5b874bd9f1170ad7
4
+ data.tar.gz: 0b11cf35f0b0b3f656d5972f4a88e76ba3f84768006490174c93b9e11107f13d
5
5
  SHA512:
6
- metadata.gz: 14117ab9417d99efc20ea08a0497504acdc7486704be02b96f65fe7da0719447dace894e8ee733261e9fd73b5cafe81199527aa37e4977cd818434e6517465be
7
- data.tar.gz: 179c07999a87d8f43710ab22f1ffda3dd7a5776e56640324c1a4e175df36607fe904e0b2c15901e8c5e89eaba3a1a216157a6fb518e5aca6f64120061bb6dbc5
6
+ metadata.gz: 1305aa44e4043d677d34d7c74e5c429ae6a12afc5c5fd705e2db87d7ee14c25449bbb8b4eba52219dbcf2f8fa7dc77a6e51ce63559cfef0b8915652f3a1c0099
7
+ data.tar.gz: afd4a2e9207b9359d2c3a5b7f41f44d9af3ea05cdce808683e7e6f455a6498fd642f08d7bc71d74c0a92bb15a29006b7ba1efcea80dae17709aacc86020cca10
@@ -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
 
@@ -7,6 +7,16 @@ class Builtin
7
7
  def description
8
8
  "no description"
9
9
  end
10
+
11
+ def class_for(name:)
12
+ Builtins.const_get(builtin_class_name_for(name: name), false)
13
+ end
14
+
15
+ private
16
+
17
+ def builtin_class_name_for(name:)
18
+ name.capitalize.to_sym
19
+ end
10
20
  end
11
21
 
12
22
  def initialize(args, config)
@@ -1,18 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'open3'
4
-
5
3
  require 'builtin'
6
4
 
7
5
  module Builtins
8
6
  class Background < Builtin
9
- DEFAULT_SHELL = "bash"
10
7
  DEFAULT_LOG_FILE_PREFIX = "/tmp/ops_bglog_"
11
8
 
12
9
  class << self
13
10
  def description
14
11
  "runs the given command in a background session"
15
12
  end
13
+
14
+ def log_filename
15
+ Options.get("background.log_filename") || "#{DEFAULT_LOG_FILE_PREFIX}#{Ops.project_name}"
16
+ end
16
17
  end
17
18
 
18
19
  def run
@@ -26,25 +27,13 @@ module Builtins
26
27
  private
27
28
 
28
29
  def run_ops(args)
29
- Output.warn("Running '#{args.join(' ')}' with stderr and stdout redirected to '#{log_file}'")
30
+ Output.notice("Running '#{args.join(' ')}' with stderr and stdout redirected to '#{Background.log_filename}'")
30
31
  $stdout.sync = $stderr.sync = true
31
- $stdout.reopen(log_file, "w")
32
+ $stdout.reopen(Background.log_filename, "w")
32
33
  $stderr.reopen($stdout)
33
34
 
34
35
  Ops.new(args).run
35
36
  end
36
-
37
- def log_file
38
- @log_file ||= "#{log_file_prefix}#{Ops.project_name}"
39
- end
40
-
41
- def log_file_prefix
42
- Options.get("background.log_file_prefix") || DEFAULT_LOG_FILE_PREFIX
43
- end
44
-
45
- def shell
46
- Options.get("background.shell") || DEFAULT_SHELL
47
- end
48
37
  end
49
38
 
50
39
  # set an alias
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'builtin'
4
+ require 'builtins/background'
5
+
6
+ module Builtins
7
+ class BackgroundLog < Builtin
8
+ class << self
9
+ def description
10
+ "displays the log from the current or most recent background task from this project"
11
+ end
12
+ end
13
+
14
+ def run
15
+ unless File.exist?(Background.log_filename)
16
+ Output.warn("No background log found at '#{Background.log_filename}'.")
17
+ return 0
18
+ end
19
+
20
+ Output.notice("Displaying background log '#{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
32
+ end
33
+ end
34
+
35
+ # set an alias
36
+ Bglog = BackgroundLog
37
+ 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
@@ -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,21 +58,17 @@ 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
 
66
65
  def builtin
67
- @builtin ||= Builtins.const_get(builtin_class_name, false).new(@args, config)
66
+ @builtin ||= Builtin.class_for(name: @action_name).new(@args, config)
68
67
  rescue NameError
69
68
  # this means there isn't a builtin with that name in that module
70
69
  nil
71
70
  end
72
71
 
73
- def builtin_class_name
74
- @action_name.capitalize.to_sym
75
- end
76
-
77
72
  def action
78
73
  return actions[@action_name] if actions[@action_name]
79
74
  return aliases[@action_name] if aliases[@action_name]
@@ -40,6 +40,8 @@ class Output
40
40
  @err.puts(msg.yellow)
41
41
  end
42
42
 
43
+ alias_method :notice, :warn
44
+
43
45
  def error(msg)
44
46
  @err.puts(msg.red)
45
47
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ops_team'
5
- s.version = '0.9.0'
5
+ s.version = '0.9.5'
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.0
4
+ version: 0.9.5
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
@@ -149,6 +149,7 @@ files:
149
149
  - lib/app_config.rb
150
150
  - lib/builtin.rb
151
151
  - lib/builtins/background.rb
152
+ - lib/builtins/background_log.rb
152
153
  - lib/builtins/down.rb
153
154
  - lib/builtins/env.rb
154
155
  - lib/builtins/exec.rb