ops_team 1.14.1 → 1.15.0.pre.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/builtins/completion.rb +120 -0
- data/lib/ops.rb +8 -0
- data/ops_team.gemspec +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dd30e0216346f00e34b6f12ae0ca98b63d9191b5e894dc27b1bd9e7497c5611
|
4
|
+
data.tar.gz: aede677cfad8bcfc29d0665eb289f913d26cd2a9ec1555f14f4f8a3155136b96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c42419ff6fcc7b8e697c0c9ef88d2ffc9975e077a04d3dfe40cd09276d41a9787c64df5c6ebdcd7b93fa68c008494cfdd9ec94a20ea0917989edbf057f47d98
|
7
|
+
data.tar.gz: b73b36965c85fcec71bce2675f18993a372598f9842c37b88878231f035ac8e7296f3f27095a099572ea75f3be99d63f6f0d7bf5d77cad2a76d2e44195315a36
|
@@ -0,0 +1,120 @@
|
|
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
|
data/lib/ops.rb
CHANGED
@@ -39,6 +39,8 @@ class Ops
|
|
39
39
|
# rubocop:disable Metrics/MethodLength
|
40
40
|
# better to have all the rescues in one place
|
41
41
|
def run
|
42
|
+
return completion_list if ENV["OPS_AUTO_COMPLETE"]
|
43
|
+
|
42
44
|
# "return" is here to allow specs to stub "exit" without executing everything after it
|
43
45
|
return exit(INVALID_SYNTAX_EXIT_CODE) unless syntax_valid?
|
44
46
|
return exit(MIN_VERSION_NOT_MET_EXIT_CODE) unless min_version_met?
|
@@ -65,6 +67,12 @@ class Ops
|
|
65
67
|
|
66
68
|
private
|
67
69
|
|
70
|
+
def completion_list
|
71
|
+
require 'builtins/completion'
|
72
|
+
|
73
|
+
Builtins::Completion.new(@args, @config).completion
|
74
|
+
end
|
75
|
+
|
68
76
|
def syntax_valid?
|
69
77
|
return true unless @action_name.nil?
|
70
78
|
|
data/ops_team.gemspec
CHANGED
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.15.0.pre.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nickthecook@gmail.com
|
@@ -173,6 +173,7 @@ files:
|
|
173
173
|
- lib/builtins/background.rb
|
174
174
|
- lib/builtins/background_log.rb
|
175
175
|
- lib/builtins/common/up_down.rb
|
176
|
+
- lib/builtins/completion.rb
|
176
177
|
- lib/builtins/countdown.rb
|
177
178
|
- lib/builtins/down.rb
|
178
179
|
- lib/builtins/env.rb
|
@@ -225,9 +226,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
225
226
|
version: '2.5'
|
226
227
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
227
228
|
requirements:
|
228
|
-
- - "
|
229
|
+
- - ">"
|
229
230
|
- !ruby/object:Gem::Version
|
230
|
-
version:
|
231
|
+
version: 1.3.1
|
231
232
|
requirements: []
|
232
233
|
rubygems_version: 3.2.15
|
233
234
|
signing_key:
|