ops_team 1.15.0.pre.rc2 → 1.16.0.pre.rc1

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: 1dd30e0216346f00e34b6f12ae0ca98b63d9191b5e894dc27b1bd9e7497c5611
4
- data.tar.gz: aede677cfad8bcfc29d0665eb289f913d26cd2a9ec1555f14f4f8a3155136b96
3
+ metadata.gz: e5aa70e4e711e46c9e7661013c62fc3f40db454caeee504c0ff3c49258ea3951
4
+ data.tar.gz: c1a491887c6629b419b3397aed7b0ad0e1b74a19bcfda45fc79fb15d481f517c
5
5
  SHA512:
6
- metadata.gz: 2c42419ff6fcc7b8e697c0c9ef88d2ffc9975e077a04d3dfe40cd09276d41a9787c64df5c6ebdcd7b93fa68c008494cfdd9ec94a20ea0917989edbf057f47d98
7
- data.tar.gz: b73b36965c85fcec71bce2675f18993a372598f9842c37b88878231f035ac8e7296f3f27095a099572ea75f3be99d63f6f0d7bf5d77cad2a76d2e44195315a36
6
+ metadata.gz: b92b2d6583d86f2a0fccf7d17d6d713aaf062eed7837836fb0904c7bafee5ded631a9d26b22c96eb429e629f54d7a9e06f5f2ace0411743e57005ec410086808
7
+ data.tar.gz: f8199c0e807ed8fa7e1d3bfba3928c51fa32dca844bdaa103d3d18afb35b8ef017ddae71a8371a3d5fbb1a3ec3b9bd475105754e6e5f0b7b439b90279171c28c
data/Gemfile CHANGED
@@ -14,6 +14,7 @@ gem "io-console"
14
14
  gem "json", ">= 2.3.0"
15
15
  gem "net-ssh"
16
16
  gem "require_all"
17
+ gem "zeitwerk"
17
18
 
18
19
  group :test do
19
20
  gem "fuubar"
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
- require_relative "../loader"
28
- require 'ops'
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
- exit Ops.new(ARGV, config_file: options[:file]).run
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
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'action'
4
-
5
3
  class ActionList
6
4
  class UnknownActionError < StandardError; end
7
5
 
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
- return nil unless File.exist?(file)
17
+ unless File.exist?(file)
18
+ require 'require_all'
19
+ require_rel "builtins"
20
+ end
18
21
 
19
- require file
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)
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
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'builtin'
4
-
5
3
  module Builtins
6
- class Background < Builtin
4
+ class Background < ::Builtin
7
5
  DEFAULT_LOG_FILE_PREFIX = "/tmp/ops_bglog_"
8
6
 
9
7
  class << self
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'builtin'
4
- require 'builtins/background'
5
-
6
3
  module Builtins
7
4
  class BackgroundLog < Builtin
8
5
  class << self
@@ -1,12 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'require_all'
4
- require_rel "../../dependencies"
5
-
6
- require 'builtin'
7
- require 'builtins/helpers/dependency_handler'
8
- require 'output'
9
-
10
3
  module Builtins
11
4
  module Common
12
5
  class UpDown < Builtin
@@ -2,9 +2,6 @@
2
2
 
3
3
  require 'concurrent'
4
4
 
5
- require 'builtin'
6
- require 'output'
7
-
8
5
  module Builtins
9
6
  class Countdown < Builtin
10
7
  USAGE_STRING = "Usage: ops countdown <seconds>"
data/lib/builtins/down.rb CHANGED
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'require_all'
4
- require_rel "../dependencies"
5
-
6
- require 'builtins/common/up_down'
7
-
8
3
  module Builtins
9
4
  class Down < Common::UpDown
10
5
  def handle_dependency(dependency)
data/lib/builtins/env.rb CHANGED
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'builtin'
4
- require 'output'
5
-
6
3
  module Builtins
7
4
  class Env < Builtin
8
5
  class << self
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'builtin'
4
-
5
3
  module Builtins
6
- class EnvDiff < Builtin
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
@@ -2,10 +2,6 @@
2
2
 
3
3
  require 'colorize'
4
4
 
5
- require 'builtin'
6
- require 'forwards'
7
- require 'builtins/helpers/enumerator'
8
-
9
5
  module Builtins
10
6
  class Help < Builtin
11
7
  NAME_WIDTH = 40
@@ -1,11 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'builtin'
4
- require 'output'
5
-
6
- require 'require_all'
7
- require_rel "../../dependencies"
8
-
9
3
  module Builtins
10
4
  module Helpers
11
5
  class DependencyHandler
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'require_all'
4
- require_rel ".."
4
+ require_rel '..'
5
5
 
6
6
  module Builtins
7
7
  module Helpers
data/lib/builtins/init.rb CHANGED
@@ -2,9 +2,6 @@
2
2
 
3
3
  require 'fileutils'
4
4
 
5
- require 'builtin'
6
- require 'output'
7
-
8
5
  module Builtins
9
6
  class Init < Builtin
10
7
  OPS_YML = "ops.yml"
data/lib/builtins/up.rb CHANGED
@@ -1,11 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'require_all'
4
- require_rel "../dependencies"
5
-
6
- require 'builtins/common/up_down'
7
- require 'output'
8
-
9
3
  module Builtins
10
4
  class Up < Common::UpDown
11
5
  def handle_dependency(dependency)
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "output"
4
- require "version"
5
-
6
3
  module Builtins
7
4
  class Version < Builtin
8
5
  class << self
@@ -2,8 +2,6 @@
2
2
 
3
3
  require 'English'
4
4
 
5
- require 'dependency'
6
-
7
5
  module Dependencies
8
6
  class Apk < Dependency
9
7
  def met?
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dependencies/versioned_dependency'
4
- require 'dependencies/helpers/apt_cache_policy'
5
-
6
3
  module Dependencies
7
4
  class Apt < VersionedDependency
8
5
  def met?
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dependency'
4
-
5
3
  module Dependencies
6
4
  class Brew < Dependency
7
5
  def met?
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dependencies/brew'
4
-
5
3
  module Dependencies
6
4
  class Cask < Brew
7
5
  def met?
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dependency'
4
-
5
3
  module Dependencies
6
4
  class Custom < Dependency
7
5
  class CustomConfigError < StandardError; end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dependency'
4
-
5
3
  module Dependencies
6
4
  class Dir < Dependency
7
5
  def met?
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dependency'
4
-
5
3
  module Dependencies
6
4
  class Docker < Dependency
7
5
  def met?
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dependency'
4
- require 'options'
5
-
6
3
  module Dependencies
7
4
  class Gem < VersionedDependency
8
5
  def met?
@@ -2,9 +2,6 @@
2
2
 
3
3
  require 'English'
4
4
 
5
- require 'dependency'
6
- require 'options'
7
-
8
5
  module Dependencies
9
6
  class Pip < Dependency
10
7
  DEFAULT_PIP = "python3 -m pip"
@@ -2,8 +2,6 @@
2
2
 
3
3
  require 'net/ssh'
4
4
 
5
- require 'dependency'
6
-
7
5
  module Dependencies
8
6
  class Sshkey < Dependency
9
7
  DEFAULT_KEY_SIZE = 4096
data/lib/dependency.rb CHANGED
@@ -3,9 +3,6 @@
3
3
  require 'open3'
4
4
  require 'English'
5
5
 
6
- require 'output'
7
- require 'executor'
8
-
9
6
  class Dependency
10
7
  DESCRIPTION_TYPE_WIDTH = 8
11
8
 
data/lib/environment.rb CHANGED
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'version'
4
- require 'secrets'
5
- require 'app_config'
6
-
7
3
  class Environment
8
4
  class << self
9
5
  def environment
data/lib/forward.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'output'
4
-
5
3
  class Forward
6
4
  def initialize(dir, args)
7
5
  @dir = dir
data/lib/forwards.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'forward'
4
-
5
3
  class Forwards
6
4
  def initialize(config, args = [])
7
5
  @config = config
data/lib/hook_handler.rb CHANGED
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'output'
4
- require 'executor'
5
-
6
3
  class HookHandler
7
4
  class HookConfigError < StandardError; end
8
5
 
data/lib/ops.rb CHANGED
@@ -1,14 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'yaml'
5
- require 'require_all'
6
- require "rubygems"
4
+ Profiler.measure("ops:requires_external") do
5
+ require 'yaml'
6
+ require "rubygems"
7
+ end
7
8
 
8
- require 'output'
9
- require 'options'
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.run
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
- @builtin ||= Builtin.class_for(name: @action_name)&.new(@args, @config)
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
@@ -3,10 +3,6 @@
3
3
  require 'json'
4
4
  require 'open3'
5
5
 
6
- require 'output'
7
- require 'app_config'
8
- require 'options'
9
-
10
6
  class Secrets < AppConfig
11
7
  class << self
12
8
  def default_filename
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.15.0-rc2'
5
+ s.version = '1.16.0-rc1'
6
6
  s.authors = [
7
7
  'nickthecook@gmail.com'
8
8
  ]
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.15.0.pre.rc2
4
+ version: 1.16.0.pre.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nickthecook@gmail.com
@@ -158,6 +158,7 @@ extensions: []
158
158
  extra_rdoc_files: []
159
159
  files:
160
160
  - Gemfile
161
+ - bin/benchmark
161
162
  - bin/ops
162
163
  - bin/print_config
163
164
  - bin/print_secrets
@@ -173,7 +174,6 @@ files:
173
174
  - lib/builtins/background.rb
174
175
  - lib/builtins/background_log.rb
175
176
  - lib/builtins/common/up_down.rb
176
- - lib/builtins/completion.rb
177
177
  - lib/builtins/countdown.rb
178
178
  - lib/builtins/down.rb
179
179
  - lib/builtins/env.rb
@@ -206,6 +206,7 @@ files:
206
206
  - lib/ops.rb
207
207
  - lib/options.rb
208
208
  - lib/output.rb
209
+ - lib/profiler.rb
209
210
  - lib/runner.rb
210
211
  - lib/secrets.rb
211
212
  - lib/version.rb
@@ -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