ops_team 1.15.0.pre.rc2 → 1.16.0.pre.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/bin/benchmark +185 -0
- data/bin/ops +15 -3
- data/lib/action.rb +3 -3
- data/lib/action_list.rb +0 -2
- data/lib/app_config.rb +2 -0
- data/lib/builtin.rb +12 -3
- data/lib/builtins/background.rb +1 -3
- data/lib/builtins/background_log.rb +0 -3
- data/lib/builtins/common/up_down.rb +0 -7
- data/lib/builtins/countdown.rb +0 -3
- data/lib/builtins/down.rb +0 -5
- data/lib/builtins/env.rb +0 -3
- data/lib/builtins/envdiff.rb +1 -5
- data/lib/builtins/exec.rb +2 -5
- data/lib/builtins/help.rb +0 -4
- data/lib/builtins/helpers/dependency_handler.rb +0 -6
- data/lib/builtins/helpers/enumerator.rb +1 -1
- data/lib/builtins/init.rb +0 -3
- data/lib/builtins/up.rb +0 -6
- data/lib/builtins/version.rb +0 -3
- data/lib/dependencies/apk.rb +0 -2
- data/lib/dependencies/apt.rb +0 -3
- data/lib/dependencies/brew.rb +0 -2
- data/lib/dependencies/cask.rb +0 -2
- data/lib/dependencies/custom.rb +0 -2
- data/lib/dependencies/dir.rb +0 -2
- data/lib/dependencies/docker.rb +0 -2
- data/lib/dependencies/gem.rb +0 -3
- data/lib/dependencies/pip.rb +0 -3
- data/lib/dependencies/sshkey.rb +1 -2
- data/lib/dependency.rb +0 -3
- data/lib/environment.rb +0 -4
- data/lib/forward.rb +0 -2
- data/lib/forwards.rb +0 -2
- data/lib/hook_handler.rb +0 -3
- data/lib/ops.rb +9 -16
- data/lib/profiler.rb +47 -0
- data/lib/runner.rb +6 -9
- data/lib/secrets.rb +0 -4
- data/loader.rb +7 -1
- data/ops_team.gemspec +2 -1
- metadata +23 -2
- data/lib/builtins/completion.rb +0 -120
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d99e338fada03d6ca5e886fe11c3136eae0c9bebc37bc06f159dd3f7c8842f7
|
4
|
+
data.tar.gz: c078ec01b308b651bf6b95690157d16974497e81e94fde108acdcbd9f3c5d875
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f3e12012343ad350105b52c0435540e52955c9aa1de5c1842c7db8d8853d2b0693a23a40b128fe9b1250ee4fa3b202dc7fbb0e3a8d16b3fe78d0cee8978f882
|
7
|
+
data.tar.gz: e6103422745fc04f3c6ce160b03671a307cfa7afff8ce860f51bc90dddb404dc9417d0cf50b0218bb09ca6dab032b5ba3461dd93197c31232e8a2ef682efb9db
|
data/Gemfile
CHANGED
data/bin/benchmark
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'json'
|
5
|
+
require 'colorize'
|
6
|
+
|
7
|
+
COMMANDS = [
|
8
|
+
"version",
|
9
|
+
"env",
|
10
|
+
"help",
|
11
|
+
"exec echo hi",
|
12
|
+
"env OPS_AUTO_COMPLETE=true"
|
13
|
+
].freeze
|
14
|
+
|
15
|
+
class Runner
|
16
|
+
RUNS = 10
|
17
|
+
WARMUPS = 3
|
18
|
+
|
19
|
+
attr_reader :command, :version
|
20
|
+
|
21
|
+
def initialize(command, version)
|
22
|
+
@command = command
|
23
|
+
@version = version
|
24
|
+
end
|
25
|
+
|
26
|
+
def run
|
27
|
+
unless File.exist?(json_file)
|
28
|
+
system(
|
29
|
+
"hyperfine -m #{RUNS} \
|
30
|
+
--export-json #{json_file} \
|
31
|
+
--export-markdown #{markdown_file} \
|
32
|
+
--warmup #{WARMUPS} \
|
33
|
+
'#{@command}'"
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
results
|
38
|
+
end
|
39
|
+
|
40
|
+
def results
|
41
|
+
# for now, only ever one result, since we're not having hyperfine vary params
|
42
|
+
@results ||= JSON.parse(results_data)["results"].first
|
43
|
+
end
|
44
|
+
|
45
|
+
def method_missing(method, *_, &_)
|
46
|
+
results[method.to_s]
|
47
|
+
end
|
48
|
+
|
49
|
+
def respond_to_missing?(method, _ = false)
|
50
|
+
results&.keys&.include?(method.to_s)
|
51
|
+
end
|
52
|
+
|
53
|
+
def json_file
|
54
|
+
@json_file ||= "#{output_file}.json"
|
55
|
+
end
|
56
|
+
|
57
|
+
def markdown_file
|
58
|
+
@markdown_file ||= "#{output_file}.md"
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def output_file
|
64
|
+
"benchmark/#{@version}-#{@command.gsub(" ", "_").gsub("/", "-")}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def results_data
|
68
|
+
File.read(json_file)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class Benchmark
|
73
|
+
attr_reader :executable
|
74
|
+
|
75
|
+
def initialize(executable)
|
76
|
+
@executable = executable
|
77
|
+
end
|
78
|
+
|
79
|
+
def run
|
80
|
+
runners.map(&:run)
|
81
|
+
|
82
|
+
runners.map(&:mean)
|
83
|
+
end
|
84
|
+
|
85
|
+
def version
|
86
|
+
@version ||= `#{@executable} version`.chomp
|
87
|
+
end
|
88
|
+
|
89
|
+
def runners
|
90
|
+
@runners ||= COMMANDS.map do |cmd|
|
91
|
+
Runner.new("#{@executable} #{cmd}", version)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class Benchmarker
|
97
|
+
CLR_THRESHOLD = 0.1
|
98
|
+
CLR_WIDTH = 14
|
99
|
+
COL_WIDTH = 24
|
100
|
+
CMD_WIDTH = 30
|
101
|
+
|
102
|
+
def initialize(*executables)
|
103
|
+
@executables = executables
|
104
|
+
end
|
105
|
+
|
106
|
+
def summary
|
107
|
+
result_pairs = results.first.zip(results.last)
|
108
|
+
|
109
|
+
output = header
|
110
|
+
COMMANDS.length.times do |index|
|
111
|
+
output << format(
|
112
|
+
"%#{CMD_WIDTH + CLR_WIDTH}s %#{COL_WIDTH}s %#{COL_WIDTH + CLR_WIDTH}s",
|
113
|
+
COMMANDS[index].white,
|
114
|
+
*result_strings(result_pairs[index])
|
115
|
+
)
|
116
|
+
end
|
117
|
+
output << summary_numbers
|
118
|
+
|
119
|
+
output.join("\n")
|
120
|
+
end
|
121
|
+
|
122
|
+
def benchmarks
|
123
|
+
@benchmarks ||= @executables.map do |executable|
|
124
|
+
Benchmark.new(executable)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def results
|
129
|
+
@results ||= benchmarks.map(&:run)
|
130
|
+
end
|
131
|
+
|
132
|
+
private
|
133
|
+
|
134
|
+
def result_pairs
|
135
|
+
@result_pairs ||= results.first.zip(results.last)
|
136
|
+
end
|
137
|
+
|
138
|
+
def header
|
139
|
+
[
|
140
|
+
format(
|
141
|
+
"%#{CMD_WIDTH}s %#{COL_WIDTH + CLR_WIDTH}s %#{COL_WIDTH + CLR_WIDTH}s",
|
142
|
+
"", *benchmarks.map { |b| b.executable.white }
|
143
|
+
),
|
144
|
+
format(
|
145
|
+
"%#{CMD_WIDTH}s %#{COL_WIDTH + CLR_WIDTH}s %#{COL_WIDTH + CLR_WIDTH}s",
|
146
|
+
"", *benchmarks.map { |b| b.version.white }
|
147
|
+
)
|
148
|
+
]
|
149
|
+
end
|
150
|
+
|
151
|
+
def result_strings(pair)
|
152
|
+
colour = :blue
|
153
|
+
if pair.last < (pair.first * (1 - CLR_THRESHOLD))
|
154
|
+
colour = :green
|
155
|
+
elsif pair.last < (pair.first * CLR_THRESHOLD)
|
156
|
+
colour = :red
|
157
|
+
end
|
158
|
+
|
159
|
+
outputs = pair.map { |number| format("%02.3f", number) }
|
160
|
+
|
161
|
+
outputs[1] = outputs.last.send(colour)
|
162
|
+
|
163
|
+
outputs
|
164
|
+
end
|
165
|
+
|
166
|
+
def summary_numbers
|
167
|
+
format(
|
168
|
+
"%#{CMD_WIDTH + CLR_WIDTH}s %#{COL_WIDTH}s %#{COL_WIDTH + CLR_WIDTH}s",
|
169
|
+
"Avg difference".white, "-", avg_diff_string.white
|
170
|
+
)
|
171
|
+
end
|
172
|
+
|
173
|
+
def avg_diff_string
|
174
|
+
format("%02.3f", avg_diff)
|
175
|
+
end
|
176
|
+
|
177
|
+
def avg_diff
|
178
|
+
result_pairs.each_with_object([]) do |pair, diff|
|
179
|
+
diff << pair.first - pair.last
|
180
|
+
end.sum / result_pairs.length
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
`rm -f benchmark/*.json benchmark/*.md` unless %w[--skip -s].include?(ARGV[0])
|
185
|
+
puts Benchmarker.new("ops", "bin/ops").summary
|
data/bin/ops
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
5
|
+
|
6
|
+
require_relative '../lib/profiler'
|
4
7
|
require 'optparse'
|
5
8
|
|
6
9
|
def usage
|
@@ -12,6 +15,8 @@ def usage
|
|
12
15
|
end
|
13
16
|
|
14
17
|
options = {}
|
18
|
+
status = -1
|
19
|
+
|
15
20
|
while ARGV[0]&.match(/^-/)
|
16
21
|
opt = ARGV.shift
|
17
22
|
case opt
|
@@ -24,7 +29,14 @@ while ARGV[0]&.match(/^-/)
|
|
24
29
|
end
|
25
30
|
end
|
26
31
|
|
27
|
-
|
28
|
-
|
32
|
+
Profiler.measure("bin:require") do
|
33
|
+
require_relative "../loader"
|
34
|
+
end
|
35
|
+
|
36
|
+
Profiler.measure("bin:run") do
|
37
|
+
status = Ops.new(ARGV, config_file: options[:file]).run
|
38
|
+
end
|
29
39
|
|
30
|
-
|
40
|
+
Profiler.add_measurement("bin:all", Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time)
|
41
|
+
Output.error(Profiler.summary) if Profiler.summary
|
42
|
+
exit status
|
data/lib/action.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'secrets'
|
4
|
-
|
5
3
|
# represents one action to be performed in the shell
|
6
4
|
# can assemble a command line from a command and args
|
7
5
|
class Action
|
@@ -9,11 +7,13 @@ class Action
|
|
9
7
|
|
10
8
|
def initialize(name, config, args)
|
11
9
|
@name = name
|
12
|
-
@config = config
|
10
|
+
@config = config || {}
|
13
11
|
@args = args
|
14
12
|
end
|
15
13
|
|
16
14
|
def run
|
15
|
+
Output.error(Profiler.summary) if Profiler.summary
|
16
|
+
|
17
17
|
if perform_shell_expansion?
|
18
18
|
Kernel.exec(to_s)
|
19
19
|
else
|
data/lib/action_list.rb
CHANGED
data/lib/app_config.rb
CHANGED
data/lib/builtin.rb
CHANGED
@@ -14,14 +14,23 @@ class Builtin
|
|
14
14
|
|
15
15
|
def class_for(name:)
|
16
16
|
file = file_for(name: name)
|
17
|
-
|
17
|
+
unless File.exist?(file)
|
18
|
+
require 'require_all'
|
19
|
+
require_rel "builtins"
|
20
|
+
end
|
18
21
|
|
19
|
-
|
20
|
-
Builtins.const_get(builtin_class_name_for(name: name), false)
|
22
|
+
get_const(name: builtin_class_name_for(name: name))
|
21
23
|
end
|
22
24
|
|
23
25
|
private
|
24
26
|
|
27
|
+
def get_const(name:)
|
28
|
+
Builtins.const_get(name, false)
|
29
|
+
rescue NameError
|
30
|
+
# no such constant
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
25
34
|
def file_for(name:)
|
26
35
|
File.join(File.dirname(__FILE__), BUILTIN_DIR, "#{name}.rb")
|
27
36
|
end
|
data/lib/builtins/background.rb
CHANGED
data/lib/builtins/countdown.rb
CHANGED
data/lib/builtins/down.rb
CHANGED
data/lib/builtins/env.rb
CHANGED
data/lib/builtins/envdiff.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'builtin'
|
4
|
-
|
5
3
|
module Builtins
|
6
|
-
class
|
4
|
+
class Envdiff < Builtin
|
7
5
|
class << self
|
8
6
|
def description
|
9
7
|
"compares keys present in config and secrets between different environments"
|
@@ -126,6 +124,4 @@ module Builtins
|
|
126
124
|
Options.get("envdiff.ignored_keys") || []
|
127
125
|
end
|
128
126
|
end
|
129
|
-
|
130
|
-
Envdiff = EnvDiff
|
131
127
|
end
|
data/lib/builtins/exec.rb
CHANGED
@@ -1,10 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'builtin'
|
4
|
-
require 'output'
|
5
|
-
require 'secrets'
|
6
|
-
require 'options'
|
7
|
-
|
8
3
|
module Builtins
|
9
4
|
class Exec < Builtin
|
10
5
|
class << self
|
@@ -17,9 +12,11 @@ module Builtins
|
|
17
12
|
Secrets.load if Options.get("exec.load_secrets")
|
18
13
|
|
19
14
|
if args.any?
|
15
|
+
Output.error(Profiler.summary) if Profiler.summary
|
20
16
|
Kernel.exec(args.join(" "))
|
21
17
|
else
|
22
18
|
Output.error("Usage: ops exec '<command>'")
|
19
|
+
|
23
20
|
false
|
24
21
|
end
|
25
22
|
end
|
data/lib/builtins/help.rb
CHANGED
data/lib/builtins/init.rb
CHANGED
data/lib/builtins/up.rb
CHANGED
data/lib/builtins/version.rb
CHANGED
data/lib/dependencies/apk.rb
CHANGED
data/lib/dependencies/apt.rb
CHANGED
data/lib/dependencies/brew.rb
CHANGED
data/lib/dependencies/cask.rb
CHANGED
data/lib/dependencies/custom.rb
CHANGED
data/lib/dependencies/dir.rb
CHANGED
data/lib/dependencies/docker.rb
CHANGED
data/lib/dependencies/gem.rb
CHANGED
data/lib/dependencies/pip.rb
CHANGED
data/lib/dependencies/sshkey.rb
CHANGED
data/lib/dependency.rb
CHANGED
data/lib/environment.rb
CHANGED
data/lib/forward.rb
CHANGED
data/lib/forwards.rb
CHANGED
data/lib/hook_handler.rb
CHANGED
data/lib/ops.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
require '
|
6
|
-
require "rubygems"
|
4
|
+
Profiler.measure("ops:requires_external") do
|
5
|
+
require 'yaml'
|
6
|
+
require "rubygems"
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
require 'version'
|
11
|
-
require 'runner'
|
9
|
+
Profiler.measure("ops:requires_internal") do
|
10
|
+
end
|
12
11
|
|
13
12
|
# executes commands based on local `ops.yml`
|
14
13
|
class Ops
|
@@ -39,13 +38,13 @@ class Ops
|
|
39
38
|
# rubocop:disable Metrics/MethodLength
|
40
39
|
# better to have all the rescues in one place
|
41
40
|
def run
|
42
|
-
return completion_list if ENV["OPS_AUTO_COMPLETE"]
|
43
|
-
|
44
41
|
# "return" is here to allow specs to stub "exit" without executing everything after it
|
45
42
|
return exit(INVALID_SYNTAX_EXIT_CODE) unless syntax_valid?
|
46
43
|
return exit(MIN_VERSION_NOT_MET_EXIT_CODE) unless min_version_met?
|
47
44
|
|
48
|
-
runner
|
45
|
+
Profiler.measure("runner:run") do
|
46
|
+
runner.run
|
47
|
+
end
|
49
48
|
rescue Runner::UnknownActionError => e
|
50
49
|
Output.error(e.to_s)
|
51
50
|
Output.out(RECOMMEND_HELP_TEXT) unless print_did_you_mean
|
@@ -67,12 +66,6 @@ class Ops
|
|
67
66
|
|
68
67
|
private
|
69
68
|
|
70
|
-
def completion_list
|
71
|
-
require 'builtins/completion'
|
72
|
-
|
73
|
-
Builtins::Completion.new(@args, @config).completion
|
74
|
-
end
|
75
|
-
|
76
69
|
def syntax_valid?
|
77
70
|
return true unless @action_name.nil?
|
78
71
|
|
data/lib/profiler.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Profiler
|
4
|
+
INDENT = " "
|
5
|
+
|
6
|
+
@measurements = {}
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_reader :measurements
|
10
|
+
|
11
|
+
def measure(tag)
|
12
|
+
start = time_now
|
13
|
+
result = yield
|
14
|
+
add_measurement(tag, time_now - start)
|
15
|
+
|
16
|
+
result
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_measurement(tag, seconds)
|
20
|
+
return unless profiling?
|
21
|
+
|
22
|
+
@measurements[tag] ||= []
|
23
|
+
|
24
|
+
@measurements[tag] << seconds
|
25
|
+
end
|
26
|
+
|
27
|
+
def summary
|
28
|
+
return unless profiling?
|
29
|
+
|
30
|
+
@summary ||= measurements.reverse_each.each_with_object([]) do |(tag, values), output|
|
31
|
+
output << "#{tag}:\n"
|
32
|
+
values.sort.reverse.each do |value|
|
33
|
+
value_str = format("%.3f", value * 1000)
|
34
|
+
output << format("%<indent>s%9<value>sms\n", indent: INDENT, value: value_str)
|
35
|
+
end
|
36
|
+
end.join
|
37
|
+
end
|
38
|
+
|
39
|
+
def profiling?
|
40
|
+
!ENV["OPS_PROFILE"].nil?
|
41
|
+
end
|
42
|
+
|
43
|
+
def time_now
|
44
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/runner.rb
CHANGED
@@ -1,13 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'hook_handler'
|
4
|
-
require 'action'
|
5
|
-
require 'action_list'
|
6
|
-
require 'action_suggester'
|
7
|
-
require 'forwards'
|
8
|
-
require 'environment'
|
9
|
-
require 'builtin'
|
10
|
-
|
11
3
|
module Builtins
|
12
4
|
end
|
13
5
|
|
@@ -65,7 +57,12 @@ class Runner
|
|
65
57
|
end
|
66
58
|
|
67
59
|
def builtin
|
68
|
-
|
60
|
+
Profiler.measure("runner:require_builtin") do
|
61
|
+
@builtin ||= Builtin.class_for(name: @action_name)&.new(@args, @config)
|
62
|
+
end
|
63
|
+
rescue NameError
|
64
|
+
# this means there isn't a builtin with that name in that module
|
65
|
+
nil
|
69
66
|
end
|
70
67
|
|
71
68
|
def builtin_names
|
data/lib/secrets.rb
CHANGED
data/loader.rb
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# for convenience, add "lib" to the load path
|
4
|
-
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/lib"))
|
4
|
+
# $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/lib"))
|
5
|
+
|
6
|
+
require 'zeitwerk'
|
7
|
+
|
8
|
+
loader = Zeitwerk::Loader.new
|
9
|
+
loader.push_dir(File.expand_path("#{__dir__}/lib"))
|
10
|
+
loader.setup
|
data/ops_team.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'ops_team'
|
5
|
-
s.version = '1.
|
5
|
+
s.version = '1.16.0-rc3'
|
6
6
|
s.authors = [
|
7
7
|
'nickthecook@gmail.com'
|
8
8
|
]
|
@@ -31,5 +31,6 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.add_runtime_dependency 'ejson', '~> 1.2', '>= 1.2.1'
|
32
32
|
s.add_runtime_dependency 'net-ssh', '~> 6.1', '>= 6.1.0'
|
33
33
|
s.add_runtime_dependency 'require_all', '~> 1.1', '>= 1.1.6'
|
34
|
+
s.add_runtime_dependency 'zeitwerk', '~> 2.5', '>= 2.5.3'
|
34
35
|
s.license = 'GPL-3.0-only'
|
35
36
|
end
|
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: 1.
|
4
|
+
version: 1.16.0.pre.rc3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nickthecook@gmail.com
|
@@ -150,6 +150,26 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: 1.1.6
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: zeitwerk
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '2.5'
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: 2.5.3
|
163
|
+
type: :runtime
|
164
|
+
prerelease: false
|
165
|
+
version_requirements: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - "~>"
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '2.5'
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: 2.5.3
|
153
173
|
description:
|
154
174
|
email:
|
155
175
|
executables:
|
@@ -158,6 +178,7 @@ extensions: []
|
|
158
178
|
extra_rdoc_files: []
|
159
179
|
files:
|
160
180
|
- Gemfile
|
181
|
+
- bin/benchmark
|
161
182
|
- bin/ops
|
162
183
|
- bin/print_config
|
163
184
|
- bin/print_secrets
|
@@ -173,7 +194,6 @@ files:
|
|
173
194
|
- lib/builtins/background.rb
|
174
195
|
- lib/builtins/background_log.rb
|
175
196
|
- lib/builtins/common/up_down.rb
|
176
|
-
- lib/builtins/completion.rb
|
177
197
|
- lib/builtins/countdown.rb
|
178
198
|
- lib/builtins/down.rb
|
179
199
|
- lib/builtins/env.rb
|
@@ -206,6 +226,7 @@ files:
|
|
206
226
|
- lib/ops.rb
|
207
227
|
- lib/options.rb
|
208
228
|
- lib/output.rb
|
229
|
+
- lib/profiler.rb
|
209
230
|
- lib/runner.rb
|
210
231
|
- lib/secrets.rb
|
211
232
|
- lib/version.rb
|
data/lib/builtins/completion.rb
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'builtin'
|
4
|
-
require 'forwards'
|
5
|
-
require 'builtins/helpers/enumerator'
|
6
|
-
require 'options'
|
7
|
-
|
8
|
-
require 'require_all'
|
9
|
-
require_rel '.'
|
10
|
-
|
11
|
-
module Builtins
|
12
|
-
class Completion < Builtin
|
13
|
-
BASH = "bash"
|
14
|
-
ZSH = "zsh"
|
15
|
-
USAGE = "Usage: ops completion 'bash / zsh'"
|
16
|
-
|
17
|
-
class << self
|
18
|
-
def description
|
19
|
-
"displays completion configuration for the flavor of shell provided"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def run
|
24
|
-
if args.none? || ![BASH, ZSH].include?(args[0])
|
25
|
-
Output.error(USAGE)
|
26
|
-
false
|
27
|
-
elsif args[0] == BASH
|
28
|
-
Output.print(bash_completion)
|
29
|
-
true
|
30
|
-
elsif args[0] == ZSH
|
31
|
-
Output.print(zsh_completion)
|
32
|
-
true
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def completion
|
37
|
-
return false if ENV["OPS_AUTO_COMPLETE"].nil? || ENV["COMP_WORDS"].nil? || ENV["COMP_CWORD"].nil?
|
38
|
-
|
39
|
-
word_list = ENV["COMP_WORDS"].split(" ")
|
40
|
-
current_index = ENV["COMP_CWORD"].to_i
|
41
|
-
current_word = word_list[current_index]
|
42
|
-
|
43
|
-
Output.out(completion_list(current_word))
|
44
|
-
true
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def bash_completion
|
50
|
-
"\n\n_ops_completion()\n"\
|
51
|
-
"{\n"\
|
52
|
-
" COMPREPLY=( $( COMP_WORDS=\"${COMP_WORDS[*]}\" \\\n"\
|
53
|
-
" COMP_CWORD=$COMP_CWORD \\\n"\
|
54
|
-
" OPS_AUTO_COMPLETE=1 $1 2>/dev/null ) )\n"\
|
55
|
-
"}\n"\
|
56
|
-
"complete -o default -F _ops_completion ops\n"
|
57
|
-
end
|
58
|
-
|
59
|
-
def zsh_completion
|
60
|
-
"\n\nfunction _ops_completion {\n"\
|
61
|
-
" local words cword\n"\
|
62
|
-
" read -Ac words\n"\
|
63
|
-
" read -cn cword\n"\
|
64
|
-
" reply=( $( COMP_WORDS=\"$words[*]\" \\\n"\
|
65
|
-
" COMP_CWORD=$(( cword-1 )) \\\n"\
|
66
|
-
" OPS_AUTO_COMPLETE=1 $words[1] 2>/dev/null ))\n"\
|
67
|
-
"}\n"\
|
68
|
-
"compctl -K _ops_completion ops\n"
|
69
|
-
end
|
70
|
-
|
71
|
-
def completion_list(filter)
|
72
|
-
(actions | builtins | forwards).select { |item| item =~ /^#{filter}/ }.sort.join(" ")
|
73
|
-
end
|
74
|
-
|
75
|
-
def forwards
|
76
|
-
@forwards ||= Forwards.new(@config).forwards.map do |name, _dir|
|
77
|
-
name
|
78
|
-
end.uniq
|
79
|
-
end
|
80
|
-
|
81
|
-
def builtins
|
82
|
-
@builtins ||= builtin_enumerator.names_by_constant.map do |_klass, names|
|
83
|
-
names.map(&:downcase).map(&:to_s)
|
84
|
-
end.flatten.uniq
|
85
|
-
end
|
86
|
-
|
87
|
-
def actions
|
88
|
-
return [] unless @config["actions"]
|
89
|
-
|
90
|
-
@actions ||= @config["actions"].map do |name, action_config|
|
91
|
-
next unless verify_by_restrictions(action_config)
|
92
|
-
|
93
|
-
include_aliases? ? [name, alias_string_for(action_config)] : name
|
94
|
-
end.flatten.uniq
|
95
|
-
end
|
96
|
-
|
97
|
-
def alias_string_for(action_config)
|
98
|
-
return action_config["alias"].to_s if action_config["alias"]
|
99
|
-
|
100
|
-
""
|
101
|
-
end
|
102
|
-
|
103
|
-
def include_aliases?
|
104
|
-
@include_aliases ||= Options.get("completion.include_aliases")
|
105
|
-
end
|
106
|
-
|
107
|
-
def verify_by_restrictions(action_config)
|
108
|
-
env = ENV["environment"] || "dev"
|
109
|
-
return false if action_config["skip_in_envs"]&.include?(env)
|
110
|
-
return false if action_config["not_in_envs"]&.include?(env)
|
111
|
-
return false if action_config["in_envs"] && !action_config["in_envs"].include?(env)
|
112
|
-
|
113
|
-
true
|
114
|
-
end
|
115
|
-
|
116
|
-
def builtin_enumerator
|
117
|
-
@builtin_enumerator ||= ::Builtins::Helpers::Enumerator
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|