gloo-cli 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5f80d16b893db44ef2e4d348a2979007b864ac38f342d70a717020bbf00276fd
4
+ data.tar.gz: 31954b09b879c03afc926e5aacfe6c05ee25fd52b033ea777077d62b001401c8
5
+ SHA512:
6
+ metadata.gz: a6145323794e1db29438533c549059f0e2168f160c8659ba30f864e3a169d9c48e29693e8bec7decf8dcbe6823a1385835306f75ba1517d6579bf33ad583c7e6
7
+ data.tar.gz: 7a2196a88c59023f5316da64534913a969150d6e653015f8cfdb76277465a207b813644b1fa32e7ec0872d1318376514ab0ab8346415abd004e0f5448faefa1e
@@ -0,0 +1,69 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Show colorized output.
5
+ #
6
+ require 'colorized_string'
7
+
8
+ class CliColorize < Gloo::Core::Obj
9
+
10
+ KEYWORD = 'colorize'.freeze
11
+ KEYWORD_SHORT = 'color'.freeze
12
+
13
+ #
14
+ # The name of the object type.
15
+ #
16
+ def self.typename
17
+ return KEYWORD
18
+ end
19
+
20
+ #
21
+ # The short name of the object type.
22
+ #
23
+ def self.short_typename
24
+ return KEYWORD_SHORT
25
+ end
26
+
27
+ # ---------------------------------------------------------------------
28
+ # Children
29
+ # ---------------------------------------------------------------------
30
+
31
+ # Does this object have children to add when an object
32
+ # is created in interactive mode?
33
+ # This does not apply during obj load, etc.
34
+ def add_children_on_create?
35
+ return true
36
+ end
37
+
38
+ # Add children to this object.
39
+ # This is used by containers to add children needed
40
+ # for default configurations.
41
+ def add_default_children
42
+ fac = @engine.factory
43
+ fac.create_string 'white', '', self
44
+ end
45
+
46
+ # ---------------------------------------------------------------------
47
+ # Messages
48
+ # ---------------------------------------------------------------------
49
+
50
+ #
51
+ # Get a list of message names that this object receives.
52
+ #
53
+ def self.messages
54
+ return super + [ 'run' ]
55
+ end
56
+
57
+ #
58
+ # Run the colorize command.
59
+ #
60
+ def msg_run
61
+ msg = ''
62
+ children.each do |o|
63
+ msg += ColorizedString[ o.value_display ].colorize( o.name.to_sym )
64
+ end
65
+ @engine.log.show msg
66
+ @engine.heap.it.set_to msg.to_s
67
+ end
68
+
69
+ end
@@ -0,0 +1,92 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Show a CLI confirmation prompt.
5
+ #
6
+
7
+ class CliConfirm < Gloo::Core::Obj
8
+
9
+ KEYWORD = 'confirm'.freeze
10
+ KEYWORD_SHORT = 'confirm'.freeze
11
+ PROMPT = 'prompt'.freeze
12
+ DEFAULT_PROMPT = '> '.freeze
13
+ RESULT = 'result'.freeze
14
+
15
+ #
16
+ # The name of the object type.
17
+ #
18
+ def self.typename
19
+ return KEYWORD
20
+ end
21
+
22
+ #
23
+ # The short name of the object type.
24
+ #
25
+ def self.short_typename
26
+ return KEYWORD_SHORT
27
+ end
28
+
29
+ #
30
+ # Get the URI from the child object.
31
+ # Returns nil if there is none.
32
+ #
33
+ def prompt_value
34
+ o = find_child PROMPT
35
+ return nil unless o
36
+
37
+ return o.value
38
+ end
39
+
40
+ #
41
+ # Set the result of the system call.
42
+ #
43
+ def set_result( data )
44
+ r = find_child RESULT
45
+ return nil unless r
46
+
47
+ r.set_value data
48
+ end
49
+
50
+ # ---------------------------------------------------------------------
51
+ # Children
52
+ # ---------------------------------------------------------------------
53
+
54
+ # Does this object have children to add when an object
55
+ # is created in interactive mode?
56
+ # This does not apply during obj load, etc.
57
+ def add_children_on_create?
58
+ return true
59
+ end
60
+
61
+ # Add children to this object.
62
+ # This is used by containers to add children needed
63
+ # for default configurations.
64
+ def add_default_children
65
+ fac = @engine.factory
66
+ fac.create_string PROMPT, DEFAULT_PROMPT, self
67
+ fac.create_bool RESULT, nil, self
68
+ end
69
+
70
+ # ---------------------------------------------------------------------
71
+ # Messages
72
+ # ---------------------------------------------------------------------
73
+
74
+ #
75
+ # Get a list of message names that this object receives.
76
+ #
77
+ def self.messages
78
+ return super + [ 'run' ]
79
+ end
80
+
81
+ #
82
+ # Run the confirmation command.
83
+ #
84
+ def msg_run
85
+ prompt = prompt_value
86
+ return unless prompt
87
+
88
+ result = @engine.platform.prompt.yes?( prompt )
89
+ set_result result
90
+ end
91
+
92
+ end
data/lib/gloo-cli.rb ADDED
@@ -0,0 +1,44 @@
1
+ #
2
+ # Shim to allow `require 'gloo-cli'`
3
+ #
4
+ # This file is loaded when someone does `require 'gloo-cli'`
5
+ #
6
+ require 'cli_colorize'
7
+ require 'cli_confirm'
8
+ require 'menu'
9
+ require 'menu_item'
10
+ require 'prompt'
11
+ require 'select'
12
+
13
+ #
14
+ # Registers the extension.
15
+ #
16
+ class CliInit < Gloo::Plugin::Base
17
+
18
+ #
19
+ # Register verbs and objects.
20
+ #
21
+ def register( callback )
22
+ callback.register_obj( CliColorize )
23
+ callback.register_obj( CliConfirm )
24
+ callback.register_obj( Menu )
25
+ callback.register_obj( MenuItem )
26
+ callback.register_obj( Prompt )
27
+ callback.register_obj( Select )
28
+ end
29
+
30
+ end
31
+
32
+ #
33
+ # Registers the extension.
34
+ #
35
+ class MdInit < Gloo::Plugin::Base
36
+
37
+ #
38
+ # Register verbs and objects.
39
+ #
40
+ def register( callback )
41
+ callback.register_obj( Md )
42
+ end
43
+
44
+ end
data/lib/menu.rb ADDED
@@ -0,0 +1,366 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # A CLI menu.
5
+ # The menu contains a collection of menu items, a prompt
6
+ # and an option to loop until done.
7
+ #
8
+
9
+ class Menu < Gloo::Core::Obj
10
+
11
+ KEYWORD = 'menu'.freeze
12
+ KEYWORD_SHORT = 'menu'.freeze
13
+ PROMPT = 'prompt'.freeze
14
+ ITEMS = 'items'.freeze
15
+ LOOP = 'loop'.freeze
16
+ HIDE_ITEMS = 'hide_items'.freeze
17
+ BEFORE_MENU = 'before_menu'.freeze
18
+ DEFAULT = 'default'.freeze
19
+ TITLE = 'title'.freeze
20
+ TITLE_COLOR = 'green'.freeze
21
+ QUIT_ITEM_NAME = 'q'.freeze
22
+
23
+ @@menu_stack = []
24
+
25
+ #
26
+ # The name of the object type.
27
+ #
28
+ def self.typename
29
+ return KEYWORD
30
+ end
31
+
32
+ #
33
+ # The short name of the object type.
34
+ #
35
+ def self.short_typename
36
+ return KEYWORD_SHORT
37
+ end
38
+
39
+ #
40
+ # Get the value of the prompt child object.
41
+ # Returns nil if there is none.
42
+ #
43
+ def prompt_value
44
+ o = find_child PROMPT
45
+ return '' unless o
46
+
47
+ return o.value
48
+ end
49
+
50
+ #
51
+ # Get the value of the loop child object.
52
+ # Should we keep looping or should we stop?
53
+ #
54
+ def loop?
55
+ return false unless @engine.running
56
+
57
+ o = find_child LOOP
58
+ return false unless o
59
+
60
+ return o.value
61
+ end
62
+
63
+ #
64
+ # If there is no loop child, add it.
65
+ #
66
+ def add_loop_child
67
+ o = find_child LOOP
68
+ if o
69
+ o.set_value true
70
+ return
71
+ end
72
+
73
+ fac = @engine.factory
74
+ fac.create_bool LOOP, true, self
75
+ end
76
+
77
+ #
78
+ # Add a Quit menu item
79
+ #
80
+ def add_quit_item
81
+ items = find_child ITEMS
82
+ q = items.find_child QUIT_ITEM_NAME
83
+ return if q
84
+
85
+ fac = @engine.factory
86
+ fac.create_bool LOOP, true, self
87
+
88
+ params = { :name => QUIT_ITEM_NAME,
89
+ :type => 'mitem',
90
+ :value => 'Quit',
91
+ :parent => items }
92
+ mitem = fac.create params
93
+ script = "put false into #{self.pn}.loop"
94
+ fac.create_script 'do', script, mitem
95
+ end
96
+
97
+ #
98
+ # Add any required children not specified in the source.
99
+ #
100
+ def lazy_add_children
101
+ add_loop_child
102
+ add_quit_item
103
+ end
104
+
105
+ #
106
+ # Does the menu have a title?
107
+ #
108
+ def title?
109
+ o = find_child TITLE
110
+ return o ? true : false
111
+ end
112
+
113
+ #
114
+ # Get the Menu's Title.
115
+ #
116
+ def title
117
+ obj = find_child TITLE
118
+ return obj.value
119
+ end
120
+
121
+ # ---------------------------------------------------------------------
122
+ # Children
123
+ # ---------------------------------------------------------------------
124
+
125
+ #
126
+ # Does this object have children to add when an object
127
+ # is created in interactive mode?
128
+ # This does not apply during obj load, etc.
129
+ #
130
+ def add_children_on_create?
131
+ return true
132
+ end
133
+
134
+ #
135
+ # Add children to this object.
136
+ # This is used by containers to add children needed
137
+ # for default configurations.
138
+ #
139
+ def add_default_children
140
+ fac = @engine.factory
141
+ fac.create_string PROMPT, '> ', self
142
+ fac.create_can ITEMS, self
143
+ fac.create_bool LOOP, true, self
144
+ fac.create_script DEFAULT, '', self
145
+ end
146
+
147
+ # ---------------------------------------------------------------------
148
+ # Menu Stack
149
+ # ---------------------------------------------------------------------
150
+
151
+ #
152
+ # Show the bread-crumbs for the menu stack.
153
+ #
154
+ def show_menu_stack
155
+ if @@menu_stack.count < 2
156
+ puts '...'
157
+ else
158
+ msg = ''
159
+ @@menu_stack[0..-2].each do |menu|
160
+ msg << ' | ' unless msg.blank?
161
+ msg << menu.title
162
+ end
163
+ msg << ' | ... '
164
+ puts msg
165
+ end
166
+ end
167
+
168
+ #
169
+ # Add a menu to the stack.
170
+ #
171
+ def push_menu obj
172
+ @@menu_stack << obj
173
+ end
174
+
175
+ #
176
+ # Pop a menu from the stack.
177
+ # If the last item isn't the given menu,
178
+ # it won't be popped.
179
+ #
180
+ def pop_menu menu
181
+ if @@menu_stack[-1] == menu
182
+ @@menu_stack.pop
183
+ end
184
+ end
185
+
186
+ #
187
+ # Quit all menus and drop into gloo.
188
+ #
189
+ def pop_to_top_level_menu
190
+ @engine.log.debug 'Quitting to top level menu'
191
+ while @@menu_stack.count > 1
192
+ menu = @@menu_stack.pop
193
+ o = menu.find_child LOOP
194
+ o.set_value( false ) if o
195
+ end
196
+ end
197
+
198
+ #
199
+ # Quit all menus and drop into gloo.
200
+ #
201
+ def quit_all_menus
202
+ @engine.log.debug 'Dropping into Gloo'
203
+ @@menu_stack.each do |menu|
204
+ o = menu.find_child LOOP
205
+ o.set_value( false ) if o
206
+ end
207
+ @engine.loop
208
+ end
209
+
210
+ # ---------------------------------------------------------------------
211
+ # Messages
212
+ # ---------------------------------------------------------------------
213
+
214
+ #
215
+ # Get a list of message names that this object receives.
216
+ #
217
+ def self.messages
218
+ return super + [ 'run' ]
219
+ end
220
+
221
+ #
222
+ # Show the menu options, and prompt for user input.
223
+ #
224
+ def msg_run
225
+ lazy_add_children
226
+ push_menu self
227
+ run_default
228
+ loop do
229
+ begin_menu
230
+ if prompt_value.empty?
231
+ dt = DateTime.now
232
+ d = dt.strftime( '%Y.%m.%d' )
233
+ t = dt.strftime( '%I:%M:%S' )
234
+ cmd = @engine.platform.prompt.ask( "#{d.yellow} #{t.white} >" )
235
+ else
236
+ cmd = @engine.platform.prompt.ask( prompt_value )
237
+ end
238
+ cmd ? run_command( cmd ) : run_default
239
+ break unless loop?
240
+ end
241
+ pop_menu self
242
+ end
243
+
244
+ # ---------------------------------------------------------------------
245
+ # Menu actions
246
+ # ---------------------------------------------------------------------
247
+
248
+ #
249
+ # Begin the menu execution.
250
+ # Run the before menu script if there is one,
251
+ # then show options unless we are hiding them by default.
252
+ #
253
+ def begin_menu
254
+ run_before_menu
255
+
256
+ # Check to see if we should show items at all.
257
+ o = find_child HIDE_ITEMS
258
+ return if o && o.value == true
259
+
260
+ show_options
261
+ end
262
+
263
+ #
264
+ # If there is a before menu script, run it now.
265
+ #
266
+ def run_before_menu
267
+ o = find_child BEFORE_MENU
268
+ return unless o
269
+
270
+ Gloo::Exec::Dispatch.message( @engine, 'run', o )
271
+ end
272
+
273
+ #
274
+ # Show the list of menu options.
275
+ #
276
+ def show_options
277
+ o = find_child ITEMS
278
+ return unless o
279
+
280
+ o.children.each do |mitem|
281
+ mitem = Gloo::Objs::Alias.resolve_alias( @engine, mitem )
282
+ puts " #{mitem.shortcut_value} - #{mitem.description_value}"
283
+ end
284
+ end
285
+
286
+ #
287
+ # Find the command matching user input.
288
+ #
289
+ def find_cmd( cmd )
290
+ o = find_child ITEMS
291
+ return nil unless o
292
+
293
+ o.children.each do |mitem|
294
+ mitem = Gloo::Objs::Alias.resolve_alias( @engine, mitem )
295
+ return mitem if mitem.shortcut_value.downcase == cmd.downcase
296
+ end
297
+
298
+ return nil
299
+ end
300
+
301
+ #
302
+ # Run the default option.
303
+ #
304
+ def run_default
305
+ obj = find_child DEFAULT
306
+ if obj
307
+ s = Gloo::Exec::Script.new( @engine, obj )
308
+ s.run
309
+ elsif title?
310
+ run_default_title
311
+ end
312
+ end
313
+
314
+ #
315
+ # There is a title, so show it.
316
+ #
317
+ def run_default_title
318
+ @engine.platform&.clear_screen
319
+ show_menu_stack
320
+
321
+ title_text = @engine.platform.table.box( title )
322
+ puts title_text.colorize( :color => :white, :background => :black )
323
+ end
324
+
325
+ #
326
+ # Run the selected command.
327
+ #
328
+ def run_command( cmd )
329
+ @engine.log.info "Menu Command: #{cmd}"
330
+ obj = find_cmd cmd
331
+
332
+ if obj
333
+ script = obj.do_script
334
+ return unless script
335
+
336
+ s = Gloo::Exec::Script.new( @engine, script )
337
+ s.run
338
+ else
339
+ if cmd == '?'
340
+ @engine.log.debug 'Showing options'
341
+ show_options
342
+ elsif cmd == 'q!'
343
+ @engine.log.debug 'Quitting Gloo'
344
+ @engine.stop_running
345
+ elsif cmd == 'qq'
346
+ @engine.log.debug 'Quitting to top level menu'
347
+ pop_to_top_level_menu
348
+ elsif cmd.starts_with? ':'
349
+ gloo_cmd = cmd[1..-1].strip
350
+ if gloo_cmd.blank?
351
+ @engine.log.debug 'Quitting all menus and dropping into Gloo'
352
+ quit_all_menus
353
+ else
354
+ @engine.log.debug "Running Gloo command: #{gloo_cmd}"
355
+ @engine.process_cmd gloo_cmd
356
+ end
357
+ else
358
+ msg = "#{cmd} is not a valid option"
359
+ @engine.log.warn msg
360
+ end
361
+ return
362
+ end
363
+
364
+ end
365
+
366
+ end
data/lib/menu_item.rb ADDED
@@ -0,0 +1,91 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # A CLI menu item. One element in a CLI menu.
5
+ #
6
+
7
+ class MenuItem < Gloo::Core::Obj
8
+
9
+ KEYWORD = 'menu_item'.freeze
10
+ KEYWORD_SHORT = 'mitem'.freeze
11
+ SHORTCUT = 'shortcut'.freeze
12
+ DESCRIPTION = 'description'.freeze
13
+ DO = 'do'.freeze
14
+
15
+ #
16
+ # The name of the object type.
17
+ #
18
+ def self.typename
19
+ return KEYWORD
20
+ end
21
+
22
+ #
23
+ # The short name of the object type.
24
+ #
25
+ def self.short_typename
26
+ return KEYWORD_SHORT
27
+ end
28
+
29
+ #
30
+ # Get the value of the menu item shortcut.
31
+ # Returns nil if there is none.
32
+ #
33
+ def shortcut_value
34
+ o = find_child SHORTCUT
35
+ return self.name unless o
36
+
37
+ return o.value
38
+ end
39
+
40
+ #
41
+ # Get the action's description.
42
+ # Returns nil if there is none.
43
+ #
44
+ def description_value
45
+ o = find_child DESCRIPTION
46
+ return self.value unless o
47
+
48
+ return o.value
49
+ end
50
+
51
+ #
52
+ # Get the action's script.
53
+ # Returns nil if there is none.
54
+ #
55
+ def do_script
56
+ return find_child DO
57
+ end
58
+
59
+ # ---------------------------------------------------------------------
60
+ # Children
61
+ # ---------------------------------------------------------------------
62
+
63
+ # Does this object have children to add when an object
64
+ # is created in interactive mode?
65
+ # This does not apply during obj load, etc.
66
+ def add_children_on_create?
67
+ return true
68
+ end
69
+
70
+ # Add children to this object.
71
+ # This is used by containers to add children needed
72
+ # for default configurations.
73
+ def add_default_children
74
+ fac = @engine.factory
75
+ fac.create_string SHORTCUT, '', self
76
+ fac.create_string DESCRIPTION, '', self
77
+ fac.create_script DO, '', self
78
+ end
79
+
80
+ # ---------------------------------------------------------------------
81
+ # Messages
82
+ # ---------------------------------------------------------------------
83
+
84
+ #
85
+ # Get a list of message names that this object receives.
86
+ #
87
+ def self.messages
88
+ return super
89
+ end
90
+
91
+ end
data/lib/prompt.rb ADDED
@@ -0,0 +1,106 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Show a CLI prompt and collect user input.
5
+ #
6
+
7
+ class Prompt < Gloo::Core::Obj
8
+
9
+ KEYWORD = 'prompt'.freeze
10
+ KEYWORD_SHORT = 'ask'.freeze
11
+ PROMPT = 'prompt'.freeze
12
+ RESULT = 'result'.freeze
13
+
14
+ #
15
+ # The name of the object type.
16
+ #
17
+ def self.typename
18
+ return KEYWORD
19
+ end
20
+
21
+ #
22
+ # The short name of the object type.
23
+ #
24
+ def self.short_typename
25
+ return KEYWORD_SHORT
26
+ end
27
+
28
+ #
29
+ # Get the prompt from the child object.
30
+ # Returns nil if there is none.
31
+ #
32
+ def prompt_value
33
+ o = find_child PROMPT
34
+ return nil unless o
35
+
36
+ return o.value
37
+ end
38
+
39
+ #
40
+ # Set the result of the system call.
41
+ #
42
+ def set_result( data )
43
+ r = find_child RESULT
44
+ return nil unless r
45
+
46
+ r.set_value data
47
+ end
48
+
49
+ # ---------------------------------------------------------------------
50
+ # Children
51
+ # ---------------------------------------------------------------------
52
+
53
+ #
54
+ # Does this object have children to add when an object
55
+ # is created in interactive mode?
56
+ # This does not apply during obj load, etc.
57
+ #
58
+ def add_children_on_create?
59
+ return true
60
+ end
61
+
62
+ #
63
+ # Add children to this object.
64
+ # This is used by containers to add children needed
65
+ # for default configurations.
66
+ #
67
+ def add_default_children
68
+ fac = @engine.factory
69
+ fac.create_string PROMPT, '>', self
70
+ fac.create_string RESULT, nil, self
71
+ end
72
+
73
+ # ---------------------------------------------------------------------
74
+ # Messages
75
+ # ---------------------------------------------------------------------
76
+
77
+ #
78
+ # Get a list of message names that this object receives.
79
+ #
80
+ def self.messages
81
+ return super + %w[run multiline]
82
+ end
83
+
84
+ #
85
+ # Show a multiline prompt and get the user's input.
86
+ #
87
+ def msg_multiline
88
+ prompt = prompt_value
89
+ return unless prompt
90
+
91
+ result = @engine.platform.prompt.multiline( prompt )
92
+ set_result result.join
93
+ end
94
+
95
+ #
96
+ # Show the prompt and get the user's input.
97
+ #
98
+ def msg_run
99
+ prompt = prompt_value
100
+ return unless prompt
101
+
102
+ result = @engine.platform.prompt.ask( prompt )
103
+ set_result result
104
+ end
105
+
106
+ end
data/lib/select.rb ADDED
@@ -0,0 +1,123 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Show a CLI prompt and user selection from a list.
5
+ #
6
+
7
+ class Select < Gloo::Core::Obj
8
+
9
+ KEYWORD = 'select'.freeze
10
+ KEYWORD_SHORT = 'sel'.freeze
11
+ PROMPT = 'prompt'.freeze
12
+ OPTIONS = 'options'.freeze
13
+ RESULT = 'result'.freeze
14
+
15
+ #
16
+ # The name of the object type.
17
+ #
18
+ def self.typename
19
+ return KEYWORD
20
+ end
21
+
22
+ #
23
+ # The short name of the object type.
24
+ #
25
+ def self.short_typename
26
+ return KEYWORD_SHORT
27
+ end
28
+
29
+ #
30
+ # Get the prompt from the child object.
31
+ # Returns nil if there is none.
32
+ #
33
+ def prompt_value
34
+ o = find_child PROMPT
35
+ return nil unless o
36
+
37
+ return o.value
38
+ end
39
+
40
+ #
41
+ # Get the list of options for selection.
42
+ #
43
+ def options
44
+ o = find_child OPTIONS
45
+ return [] unless o
46
+
47
+ return o.children.map( &:name )
48
+ end
49
+
50
+ #
51
+ # Get the value of the selected item.
52
+ #
53
+ def key_for_option( selected )
54
+ o = find_child OPTIONS
55
+ return nil unless o
56
+
57
+ o.children.each do |c|
58
+ return c.value if c.name == selected
59
+ end
60
+
61
+ return nil
62
+ end
63
+
64
+ #
65
+ # Set the result of the system call.
66
+ #
67
+ def set_result( data )
68
+ r = find_child RESULT
69
+ return nil unless r
70
+
71
+ r.set_value data
72
+ end
73
+
74
+ # ---------------------------------------------------------------------
75
+ # Children
76
+ # ---------------------------------------------------------------------
77
+
78
+ #
79
+ # Does this object have children to add when an object
80
+ # is created in interactive mode?
81
+ # This does not apply during obj load, etc.
82
+ #
83
+ def add_children_on_create?
84
+ return true
85
+ end
86
+
87
+ #
88
+ # Add children to this object.
89
+ # This is used by containers to add children needed
90
+ # for default configurations.
91
+ #
92
+ def add_default_children
93
+ fac = @engine.factory
94
+ fac.create_string PROMPT, '>', self
95
+ fac.create_can OPTIONS, self
96
+ fac.create_string RESULT, nil, self
97
+ end
98
+
99
+ # ---------------------------------------------------------------------
100
+ # Messages
101
+ # ---------------------------------------------------------------------
102
+
103
+ #
104
+ # Get a list of message names that this object receives.
105
+ #
106
+ def self.messages
107
+ return super + %w[run]
108
+ end
109
+
110
+ #
111
+ # Show the prompt and get the user's selection.
112
+ #
113
+ def msg_run
114
+ prompt = prompt_value
115
+ return unless prompt
116
+
117
+ # Page size was part of the tty-prompt but not used now.
118
+ # per = Gloo::App::Settings.page_size( @engine )
119
+ result = @engine.platform.prompt.select( prompt, options )
120
+ set_result self.key_for_option( result )
121
+ end
122
+
123
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gloo-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Eric Crane
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-02-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Adds CLI support to Gloo.
14
+ email:
15
+ - eric.crane@mac.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/cli_colorize.rb
21
+ - lib/cli_confirm.rb
22
+ - lib/gloo-cli.rb
23
+ - lib/menu.rb
24
+ - lib/menu_item.rb
25
+ - lib/prompt.rb
26
+ - lib/select.rb
27
+ homepage: https://gloo.ecrane.us/
28
+ licenses:
29
+ - MIT
30
+ metadata:
31
+ gloo.type: core-library
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubygems_version: 3.5.16
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: Gloo core library. CLI support.
51
+ test_files: []