cli-mastermind 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cli/mastermind.rb +5 -5
- data/lib/cli/mastermind/interface.rb +55 -22
- data/lib/cli/mastermind/loader/planfile_loader.rb +2 -2
- data/lib/cli/mastermind/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f9d964ad9871b8f4b0b44fce7340487954d1fa00396fafa1c546be54673ced8
|
4
|
+
data.tar.gz: b1ca65e254ac504bdfdc3badde8964dd7f21321b3ef882f6546b7e8c97e94e12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba400135252064d5ae3709c8759ffaac92b19f6c3f3cb55a4db8da99401a0c52becd4507ed075a9ca185bc28b96018eac7763397d8bfd9dd7cc96d4f5cd850d5
|
7
|
+
data.tar.gz: be4dbac7ae0e6d37fa76a55893e9a64c554081fff45bb6f4692e9f5fa22a581f0989ee4e5a0a3661c69f505d020aad0fe62d050187398be4d4fc08b263e03b0d
|
data/lib/cli/mastermind.rb
CHANGED
@@ -62,12 +62,14 @@ module CLI
|
|
62
62
|
@config.instance_variables.each do |attribute|
|
63
63
|
value = @config.instance_variable_get(attribute)
|
64
64
|
|
65
|
+
name = attribute.to_s.sub(/^@/, '')
|
66
|
+
|
65
67
|
if value.respond_to? :call
|
66
68
|
if @arguments.resolve_callable_attributes?
|
67
69
|
value = begin
|
68
|
-
|
70
|
+
@config.send(name)
|
69
71
|
rescue => e
|
70
|
-
"UNABLE TO LOAD: #{e.
|
72
|
+
"UNABLE TO LOAD: #{e.message}"
|
71
73
|
end
|
72
74
|
end
|
73
75
|
|
@@ -76,8 +78,6 @@ module CLI
|
|
76
78
|
was_callable = false
|
77
79
|
end
|
78
80
|
|
79
|
-
name = attribute.to_s.sub(/^@/, '')
|
80
|
-
|
81
81
|
suffix = was_callable ? '{{*}}' : ' '
|
82
82
|
|
83
83
|
puts stylize("{{yellow:#{name}}}")
|
@@ -153,7 +153,7 @@ module CLI
|
|
153
153
|
end
|
154
154
|
|
155
155
|
def do_interactive_plan_selection
|
156
|
-
options = @selected_plan&.children || @plans
|
156
|
+
options = (@selected_plan&.children || @plans).map { |k,v| [titleize(k.to_s), v] }.to_h
|
157
157
|
|
158
158
|
@selected_plan = select("Select a plan under #{@plan_stack.join('/')}", options: options)
|
159
159
|
@plan_stack << titleize(@selected_plan.name)
|
@@ -14,27 +14,30 @@ module CLI::Mastermind::Interface
|
|
14
14
|
# Display a spinner with a +title+ while data is being loaded
|
15
15
|
# @returns the value of the given block
|
16
16
|
# @see https://github.com/Shopify/cli-ui#spinner-groups
|
17
|
-
def spinner(title)
|
17
|
+
def spinner(title, &block)
|
18
18
|
return yield unless ui_enabled?
|
19
19
|
|
20
|
-
|
20
|
+
results = concurrently do |actions|
|
21
|
+
actions.await(title, &block)
|
22
|
+
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
msg = catch(:fail) do
|
26
|
-
yield_value = yield spinner
|
27
|
-
throw :success
|
28
|
-
end
|
24
|
+
results[title]
|
25
|
+
end
|
26
|
+
alias_method :await, :spinner
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
# Performs a set of actions concurrently
|
29
|
+
# Yields an +AsyncSpinners+ objects which inherits from +CLI::UI::SpinGroup+.
|
30
|
+
# The only difference between the two is that +AsyncSpinners+ provides a
|
31
|
+
# mechanism for exfiltrating results by using +await+ instead of the usual
|
32
|
+
# +add+.
|
33
|
+
def concurrently
|
34
|
+
group = AsyncSpinners.new
|
35
|
+
|
36
|
+
yield group
|
34
37
|
|
35
38
|
group.wait
|
36
39
|
|
37
|
-
|
40
|
+
group.results
|
38
41
|
end
|
39
42
|
|
40
43
|
# Uses +CLI::UI.fmt+ to format a string
|
@@ -75,23 +78,28 @@ module CLI::Mastermind::Interface
|
|
75
78
|
default_value = nil
|
76
79
|
options = case options
|
77
80
|
when Array
|
78
|
-
|
81
|
+
default_text = default
|
79
82
|
|
80
83
|
o = options - [default]
|
81
84
|
o.zip(o).to_h
|
82
85
|
when Hash
|
83
|
-
# Handle the "default" default. Otherwise, we expect the
|
84
|
-
#
|
85
|
-
|
86
|
-
|
87
|
-
|
86
|
+
# Handle the "default" default. Otherwise, we expect the default
|
87
|
+
# is the default value
|
88
|
+
if default.is_a? Array
|
89
|
+
default_text, default = default
|
90
|
+
else
|
91
|
+
default_text = options.invert[default]
|
92
|
+
end
|
93
|
+
|
94
|
+
# dup so that we don't change whatever was passed in
|
95
|
+
options.dup.tap { |o| o.delete(default_text) }
|
88
96
|
end
|
89
97
|
|
90
98
|
CLI::UI::Prompt.ask(question, **opts) do |handler|
|
91
|
-
handler.option(
|
99
|
+
handler.option(default_text.to_s) { default }
|
92
100
|
|
93
101
|
options.each do |(text, value)|
|
94
|
-
handler.option(
|
102
|
+
handler.option(text) { value }
|
95
103
|
end
|
96
104
|
end
|
97
105
|
end
|
@@ -108,4 +116,29 @@ module CLI::Mastermind::Interface
|
|
108
116
|
def titleize(string)
|
109
117
|
string.gsub(/[-_-]/, ' ').split(' ').map(&:capitalize).join(' ')
|
110
118
|
end
|
119
|
+
|
120
|
+
class AsyncSpinners < CLI::UI::SpinGroup
|
121
|
+
attr_reader :results
|
122
|
+
|
123
|
+
def initialize
|
124
|
+
@results = {}
|
125
|
+
super
|
126
|
+
end
|
127
|
+
|
128
|
+
def await(title)
|
129
|
+
@results[title] = nil
|
130
|
+
|
131
|
+
add(title) do |spinner|
|
132
|
+
catch(:success) do
|
133
|
+
msg = catch(:fail) do
|
134
|
+
@results[title] = yield spinner
|
135
|
+
throw :success
|
136
|
+
end
|
137
|
+
|
138
|
+
puts msg
|
139
|
+
CLI::UI::Spinner::TASK_FAILED
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
111
144
|
end
|
@@ -41,8 +41,8 @@ module CLI::Mastermind
|
|
41
41
|
end
|
42
42
|
alias_method :desc, :description
|
43
43
|
|
44
|
-
def plan(name, &block)
|
45
|
-
@plans <<
|
44
|
+
def plan(name, plan_class = Plan, &block)
|
45
|
+
@plans << plan_class.new(name, @description, @filename, &block)
|
46
46
|
@description = nil
|
47
47
|
end
|
48
48
|
alias_method :task, :plan
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cli-mastermind
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Hall
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cli-ui
|