ops_team 0.8.10 → 0.9.4
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 +4 -4
- data/lib/builtin.rb +12 -0
- data/lib/builtins/background.rb +41 -0
- data/lib/builtins/background_log.rb +37 -0
- data/lib/builtins/help.rb +23 -5
- data/lib/dependencies/sshkey.rb +1 -2
- data/lib/ops.rb +10 -9
- data/lib/output.rb +2 -0
- data/ops_team.gemspec +2 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eba253171a96866401be036ddbe987211414bd7f0ab1547efacc14880440effc
|
4
|
+
data.tar.gz: c223d51872392ffa6850af158c6c7611e737c9f346ea7f04f10236ea4548febe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 438fe1576dc499d1474a47f38fb47a27206c6337b0f98dfc446c8605789e61b0987dc028f78626213a6ac6df3693a7ec41a6d7cef9e04a3db0ededb11cc25982
|
7
|
+
data.tar.gz: b67faeea77ceea232adcadb7361d2070b2156e6a361d328c9981b5bbaf2aff61b78236d82ed6e719e98eff359fec20a83c7bbb796b2f4f5fe06494e147d76b82
|
data/lib/builtin.rb
CHANGED
@@ -1,10 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Builtin
|
4
|
+
attr_reader :args, :config
|
5
|
+
|
4
6
|
class << self
|
5
7
|
def description
|
6
8
|
"no description"
|
7
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
|
8
20
|
end
|
9
21
|
|
10
22
|
def initialize(args, config)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'builtin'
|
4
|
+
|
5
|
+
module Builtins
|
6
|
+
class Background < Builtin
|
7
|
+
DEFAULT_LOG_FILE_PREFIX = "/tmp/ops_bglog_"
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def description
|
11
|
+
"runs the given command in a background session"
|
12
|
+
end
|
13
|
+
|
14
|
+
def log_filename
|
15
|
+
Options.get("background.log_filename") || "#{DEFAULT_LOG_FILE_PREFIX}#{Ops.project_name}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
subprocess = fork do
|
21
|
+
run_ops(args)
|
22
|
+
end
|
23
|
+
|
24
|
+
Process.detach(subprocess)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def run_ops(args)
|
30
|
+
Output.notice("Running '#{args.join(' ')}' with stderr and stdout redirected to '#{Background.log_filename}'")
|
31
|
+
$stdout.sync = $stderr.sync = true
|
32
|
+
$stdout.reopen(Background.log_filename, "w")
|
33
|
+
$stderr.reopen($stdout)
|
34
|
+
|
35
|
+
Ops.new(args).run
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# set an alias
|
40
|
+
Bg = Background
|
41
|
+
end
|
@@ -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
|
data/lib/builtins/help.rb
CHANGED
@@ -23,14 +23,32 @@ module Builtins
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def builtins
|
26
|
-
|
27
|
-
|
28
|
-
|
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|
|
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/dependencies/sshkey.rb
CHANGED
data/lib/ops.rb
CHANGED
@@ -19,6 +19,12 @@ class Ops
|
|
19
19
|
INVALID_SYNTAX_EXIT_CODE = 64
|
20
20
|
UNKNOWN_ACTION_EXIT_CODE = 65
|
21
21
|
|
22
|
+
class << self
|
23
|
+
def project_name
|
24
|
+
File.basename(::Dir.pwd)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
22
28
|
def initialize(argv)
|
23
29
|
@action_name = argv[0]
|
24
30
|
@args = argv[1..-1]
|
@@ -27,7 +33,7 @@ class Ops
|
|
27
33
|
end
|
28
34
|
|
29
35
|
def run
|
30
|
-
exit(INVALID_SYNTAX_EXIT_CODE) unless syntax_valid?
|
36
|
+
return exit(INVALID_SYNTAX_EXIT_CODE) unless syntax_valid?
|
31
37
|
|
32
38
|
run_action
|
33
39
|
rescue UnknownActionError => e
|
@@ -39,8 +45,7 @@ class Ops
|
|
39
45
|
|
40
46
|
def syntax_valid?
|
41
47
|
if @action_name.nil?
|
42
|
-
|
43
|
-
puts "Usage: ops <action>"
|
48
|
+
Output.error("Usage: ops <action>")
|
44
49
|
false
|
45
50
|
else
|
46
51
|
true
|
@@ -53,21 +58,17 @@ class Ops
|
|
53
58
|
|
54
59
|
return builtin.run if builtin
|
55
60
|
|
56
|
-
Output.
|
61
|
+
Output.notice("Running '#{action}' from #{CONFIG_FILE} in environment '#{ENV['environment']}'...")
|
57
62
|
action.run
|
58
63
|
end
|
59
64
|
|
60
65
|
def builtin
|
61
|
-
@builtin ||=
|
66
|
+
@builtin ||= Builtin.class_for(name: @action_name).new(@args, config)
|
62
67
|
rescue NameError
|
63
68
|
# this means there isn't a builtin with that name in that module
|
64
69
|
nil
|
65
70
|
end
|
66
71
|
|
67
|
-
def builtin_class_name
|
68
|
-
@action_name.capitalize.to_sym
|
69
|
-
end
|
70
|
-
|
71
72
|
def action
|
72
73
|
return actions[@action_name] if actions[@action_name]
|
73
74
|
return aliases[@action_name] if aliases[@action_name]
|
data/lib/output.rb
CHANGED
data/ops_team.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'ops_team'
|
5
|
-
s.version = '0.
|
5
|
+
s.version = '0.9.4'
|
6
6
|
s.authors = [
|
7
7
|
'nickthecook@gmail.com'
|
8
8
|
]
|
9
|
-
s.date = '2020-08-
|
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.
|
4
|
+
version: 0.9.4
|
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
|
+
date: 2020-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bcrypt_pbkdf
|
@@ -148,6 +148,8 @@ files:
|
|
148
148
|
- lib/action.rb
|
149
149
|
- lib/app_config.rb
|
150
150
|
- lib/builtin.rb
|
151
|
+
- lib/builtins/background.rb
|
152
|
+
- lib/builtins/background_log.rb
|
151
153
|
- lib/builtins/down.rb
|
152
154
|
- lib/builtins/env.rb
|
153
155
|
- lib/builtins/exec.rb
|