cli-mastermind 0.0.4 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 665b35d4768aadf8c4f322eefc4724e8baa5ad62efb24e5abd9992d0c6c7e920
4
- data.tar.gz: 28526d6c94c5ff46cda54c04fa44009eaeabaa46b5787a5be327f5d0f60fbecd
3
+ metadata.gz: 4f9d964ad9871b8f4b0b44fce7340487954d1fa00396fafa1c546be54673ced8
4
+ data.tar.gz: b1ca65e254ac504bdfdc3badde8964dd7f21321b3ef882f6546b7e8c97e94e12
5
5
  SHA512:
6
- metadata.gz: 22dcafdc16a3c88699b70702319403b3df5b7d9113a993ca9a04bfe354a55094b549fbae02a1b1be22cbc86bc33bf85ef564409405b65231e2cd07cecb008fe1
7
- data.tar.gz: f0b19448539416003f3e16fde716bc888ee27c0a70b679c790580e5cae86e6b6a8fcf7280dacf3da35c7c6dec89e5836da96f97a8cd47d2f0e247f2ca746ccb6
6
+ metadata.gz: ba400135252064d5ae3709c8759ffaac92b19f6c3f3cb55a4db8da99401a0c52becd4507ed075a9ca185bc28b96018eac7763397d8bfd9dd7cc96d4f5cd850d5
7
+ data.tar.gz: be4dbac7ae0e6d37fa76a55893e9a64c554081fff45bb6f4692e9f5fa22a581f0989ee4e5a0a3661c69f505d020aad0fe62d050187398be4d4fc08b263e03b0d
@@ -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
- value.call
70
+ @config.send(name)
69
71
  rescue => e
70
- "UNABLE TO LOAD: #{e.messae}"
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
- yield_value = nil
20
+ results = concurrently do |actions|
21
+ actions.await(title, &block)
22
+ end
21
23
 
22
- group = CLI::UI::SpinGroup.new
23
- group.add(title) do |spinner|
24
- catch(:success) do
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
- puts msg
31
- CLI::UI::Spinner::TASK_FAILED
32
- end
33
- end
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
- yield_value
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
- default_value = default
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
- # default to be a key in the options hash
85
- default = default.first if default.is_a? Array
86
- default_value = options[default]
87
- options.dup.tap { |o| o.delete(default) }
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(titleize(default.to_s)) { default_value }
99
+ handler.option(default_text.to_s) { default }
92
100
 
93
101
  options.each do |(text, value)|
94
- handler.option(titleize(text.to_s)) { value }
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 << Plan.new(name, @description, @filename, &block)
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
@@ -7,8 +7,8 @@ module CLI
7
7
 
8
8
  module VERSION
9
9
  RELEASE = 0
10
- MAJOR = 0
11
- MINOR = 4
10
+ MAJOR = 1
11
+ MINOR = 0
12
12
  PATCH = nil
13
13
 
14
14
  STRING = [RELEASE, MAJOR, MINOR, PATCH].compact.join('.').freeze
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
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-20 00:00:00.000000000 Z
11
+ date: 2019-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cli-ui