gloo-cli 1.5 → 1.6
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 +4 -4
- data/README.md +26 -0
- data/lib/cli_colorize.rb +36 -0
- data/lib/cli_confirm.rb +30 -0
- data/lib/command.rb +35 -2
- data/lib/menu.rb +64 -0
- data/lib/menu_item.rb +20 -0
- data/lib/prompt.rb +31 -0
- data/lib/select.rb +35 -0
- data/lib/shell.rb +42 -2
- metadata +6 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7954b2c20f1f5a6cfeba8603a9578e92c439f2890420966a61f502a0af4be0fa
|
|
4
|
+
data.tar.gz: e97bb3a1cc62b6934a1e24c65004ee015723cde0db1b9693f5958a85b7b5b6b9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9f4ff97d30afe5771e50e485f5a00eb75a07675e746a28bd4c6cc6ae76ffe51aa1f1c4cbefd858d9705c7ac68870c651ca23278f5dffcf451743d8832cdb7856
|
|
7
|
+
data.tar.gz: fc892775cffe97cc74b7f0f4a8f8187c12afbd9dff580d141f6d5dba396737fd8c6c50c41c5594ff6fdd3d8d1e328e8c4563d0ddd97d990c8f80120dd84c33d3
|
data/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# gloo-cli
|
|
2
|
+
|
|
3
|
+
A core gloo library for command-line interface applications.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Load this library in a gloo script:
|
|
8
|
+
|
|
9
|
+
```gloo
|
|
10
|
+
> load lib cli
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Objects
|
|
14
|
+
|
|
15
|
+
- `prompt` — CLI prompt for user input
|
|
16
|
+
- `select` — prompt for user to select from a list of options
|
|
17
|
+
- `confirm` — CLI confirmation prompt
|
|
18
|
+
- `menu` — a CLI menu, for a main loop or sub-menu of choices
|
|
19
|
+
- `menu_item` — a single element in a CLI menu
|
|
20
|
+
- `colorize` — write colored/styled output to the terminal
|
|
21
|
+
- `shell` — an interactive command-driven shell (REPL)
|
|
22
|
+
- `command` — a single command in a shell's command tree
|
|
23
|
+
|
|
24
|
+
## Full Reference
|
|
25
|
+
|
|
26
|
+
Every object's children and messages are documented in-app once the library is loaded — e.g. `help> object prompt`.
|
data/lib/cli_colorize.rb
CHANGED
|
@@ -66,4 +66,40 @@ class CliColorize < Gloo::Core::Obj
|
|
|
66
66
|
@engine.heap.it.set_to msg.to_s
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
+
# ---------------------------------------------------------------------
|
|
70
|
+
# Object Documentation
|
|
71
|
+
# ---------------------------------------------------------------------
|
|
72
|
+
|
|
73
|
+
#
|
|
74
|
+
# Get the object's documentation data.
|
|
75
|
+
#
|
|
76
|
+
def self.doc_data
|
|
77
|
+
{
|
|
78
|
+
:name => KEYWORD,
|
|
79
|
+
:shortcut => KEYWORD_SHORT,
|
|
80
|
+
:description => 'The Colorize object can be used to write output ' \
|
|
81
|
+
'in color. The Colorize container can contain multiple ' \
|
|
82
|
+
'strings, each one can have a different color as specified by ' \
|
|
83
|
+
'the names of the children.',
|
|
84
|
+
:children => [
|
|
85
|
+
'[color] (string) — The name of the child or children is the color. The string\'s value is what will be written out.'
|
|
86
|
+
],
|
|
87
|
+
:messages => [
|
|
88
|
+
'run — Output the string in the color specified.'
|
|
89
|
+
],
|
|
90
|
+
:examples => <<~EXAMPLES.strip
|
|
91
|
+
color [can] :
|
|
92
|
+
w [colorize] :
|
|
93
|
+
white [string] : This is white!
|
|
94
|
+
m [colorize] :
|
|
95
|
+
red [string] : red -
|
|
96
|
+
green [string] : green -
|
|
97
|
+
blue [string] : blue
|
|
98
|
+
on_load [script] :
|
|
99
|
+
run color.w
|
|
100
|
+
run color.m
|
|
101
|
+
EXAMPLES
|
|
102
|
+
}
|
|
103
|
+
end
|
|
104
|
+
|
|
69
105
|
end
|
data/lib/cli_confirm.rb
CHANGED
|
@@ -89,4 +89,34 @@ class CliConfirm < Gloo::Core::Obj
|
|
|
89
89
|
set_result result
|
|
90
90
|
end
|
|
91
91
|
|
|
92
|
+
# ---------------------------------------------------------------------
|
|
93
|
+
# Object Documentation
|
|
94
|
+
# ---------------------------------------------------------------------
|
|
95
|
+
|
|
96
|
+
#
|
|
97
|
+
# Get the object's documentation data.
|
|
98
|
+
#
|
|
99
|
+
def self.doc_data
|
|
100
|
+
{
|
|
101
|
+
:name => KEYWORD,
|
|
102
|
+
:shortcut => KEYWORD_SHORT,
|
|
103
|
+
:description => 'CLI confirmation prompt.',
|
|
104
|
+
:children => [
|
|
105
|
+
"prompt (string) — Default: '> '. The confirmation prompt.",
|
|
106
|
+
'result (boolean) — The result of the prompt.'
|
|
107
|
+
],
|
|
108
|
+
:messages => [
|
|
109
|
+
'run — Prompt the user and then set the result.'
|
|
110
|
+
],
|
|
111
|
+
:examples => <<~EXAMPLES.strip
|
|
112
|
+
confirm [confirm] :
|
|
113
|
+
prompt [string] : Are you sure?
|
|
114
|
+
result [boolean] :
|
|
115
|
+
on_load [script] :
|
|
116
|
+
run confirm
|
|
117
|
+
show 'Confirmed: ' + confirm.result
|
|
118
|
+
EXAMPLES
|
|
119
|
+
}
|
|
120
|
+
end
|
|
121
|
+
|
|
92
122
|
end
|
data/lib/command.rb
CHANGED
|
@@ -202,9 +202,9 @@ class Command < Gloo::Core::Obj
|
|
|
202
202
|
return data
|
|
203
203
|
end
|
|
204
204
|
|
|
205
|
-
#
|
|
205
|
+
#
|
|
206
206
|
# Get the command data for this command.
|
|
207
|
-
#
|
|
207
|
+
#
|
|
208
208
|
def get_command_data
|
|
209
209
|
if dynamic?
|
|
210
210
|
return {
|
|
@@ -231,4 +231,37 @@ class Command < Gloo::Core::Obj
|
|
|
231
231
|
end
|
|
232
232
|
end
|
|
233
233
|
|
|
234
|
+
# ---------------------------------------------------------------------
|
|
235
|
+
# Object Documentation
|
|
236
|
+
# ---------------------------------------------------------------------
|
|
237
|
+
|
|
238
|
+
#
|
|
239
|
+
# Get the object's documentation data.
|
|
240
|
+
#
|
|
241
|
+
def self.doc_data
|
|
242
|
+
{
|
|
243
|
+
:name => KEYWORD,
|
|
244
|
+
:shortcut => KEYWORD_SHORT,
|
|
245
|
+
:description => 'A single command in a shell\'s command tree. ' \
|
|
246
|
+
'Register it with a shell (via the register message) to make ' \
|
|
247
|
+
'it selectable at that shell\'s prompt; when selected, its ' \
|
|
248
|
+
'action script runs.',
|
|
249
|
+
:children => [
|
|
250
|
+
'name (string) — The command\'s name, as typed at the shell prompt.',
|
|
251
|
+
'description (string) — Shown alongside the command name when the shell lists its options.',
|
|
252
|
+
'action (script) — Run when the command is selected.',
|
|
253
|
+
'dynamic (string) — Optional. Marks this as a dynamic command whose children are generated at runtime from a named shell context list (set via a sibling command\'s options_key, or directly via Shell#set_context), rather than being declared up front.',
|
|
254
|
+
'nodes (container) — Optional. A container of child command objects, for a nested command tree under this one.',
|
|
255
|
+
'context (string) — Populated automatically with the selected child\'s name when a dynamic command\'s action runs.',
|
|
256
|
+
'options (container) — Optional. A fixed list of values for a dynamic command\'s source list, registered under options_key.',
|
|
257
|
+
'options_key (string) — Optional. The shell context key that options gets registered under.'
|
|
258
|
+
],
|
|
259
|
+
:messages => [
|
|
260
|
+
'register ({shell.path}) — Register this command with the given shell object, adding it to that shell\'s command tree. A parameter is required: the path to the shell.'
|
|
261
|
+
],
|
|
262
|
+
:notes => 'No vault documentation exists for this object type — ' \
|
|
263
|
+
'this was authored directly from the code.'
|
|
264
|
+
}
|
|
265
|
+
end
|
|
266
|
+
|
|
234
267
|
end
|
data/lib/menu.rb
CHANGED
|
@@ -363,4 +363,68 @@ class Menu < Gloo::Core::Obj
|
|
|
363
363
|
|
|
364
364
|
end
|
|
365
365
|
|
|
366
|
+
# ---------------------------------------------------------------------
|
|
367
|
+
# Object Documentation
|
|
368
|
+
# ---------------------------------------------------------------------
|
|
369
|
+
|
|
370
|
+
#
|
|
371
|
+
# Get the object's documentation data.
|
|
372
|
+
#
|
|
373
|
+
def self.doc_data
|
|
374
|
+
{
|
|
375
|
+
:name => KEYWORD,
|
|
376
|
+
:shortcut => KEYWORD_SHORT,
|
|
377
|
+
:description => 'A CLI menu. This can be used for the main loop ' \
|
|
378
|
+
'of a CLI application. Many of the children are optional; some ' \
|
|
379
|
+
'will be created dynamically if they are not specified in the ' \
|
|
380
|
+
'source file. Note that a Quit menu item will be added ' \
|
|
381
|
+
'dynamically if one is not specified in the source file.',
|
|
382
|
+
:children => [
|
|
383
|
+
"prompt (string) — Default: '> '. Optional; if not provided a default timestamp option is used. The prompt shown for menu item selection.",
|
|
384
|
+
'items (container) — The list of menu items.',
|
|
385
|
+
'loop (boolean) — Run the menu in a loop? If true, once a menu item has run, the menu prompts again; setting it to false ends the menu. Created dynamically if not specified.',
|
|
386
|
+
'title (string) — Optional title to use rather than manually implementing a menu header. With a title, the default and before_menu items are not needed.',
|
|
387
|
+
'hide_items (boolean) — Optional, false by default. If false, the menu items are shown each time through the loop; if true, they\'re hidden (can always be shown by typing ? at the prompt).',
|
|
388
|
+
'default (script) — Optional. Run if no other option is selected (RETURN pressed). Can be used to clear the screen, for example.',
|
|
389
|
+
'before_menu (script) — Optional. Run at the top of each loop through the menu.'
|
|
390
|
+
],
|
|
391
|
+
:messages => [
|
|
392
|
+
'run — Show the options and the prompt, then run the script for the user\'s selection. Optionally repeat as long as the loop child is true.'
|
|
393
|
+
],
|
|
394
|
+
:notes => 'Built-in menu items, always available: q — quit this ' \
|
|
395
|
+
'menu (quits the app if this is the root menu, or goes up to ' \
|
|
396
|
+
'the prior menu if a sub-menu); qq — quit to the top level ' \
|
|
397
|
+
'menu (not shown); q! — quit gloo entirely (not shown); ' \
|
|
398
|
+
': {command} — run a gloo command not part of the running app; ' \
|
|
399
|
+
': (alone) — quit the running app and drop into gloo, keeping ' \
|
|
400
|
+
'loaded app objects in the stack.',
|
|
401
|
+
:examples => <<~EXAMPLES.strip
|
|
402
|
+
simple [menu] :
|
|
403
|
+
on_load [script] :
|
|
404
|
+
run simple
|
|
405
|
+
title [string] : Simple Menu
|
|
406
|
+
items [can] :
|
|
407
|
+
h [mitem] : Run Hello World
|
|
408
|
+
do [script] : show 'Hello World!'
|
|
409
|
+
|
|
410
|
+
menu [menu] :
|
|
411
|
+
on_load [script] :
|
|
412
|
+
run menu
|
|
413
|
+
prompt [string] : >
|
|
414
|
+
loop [bool] : true
|
|
415
|
+
items [can] :
|
|
416
|
+
hw [mitem] :
|
|
417
|
+
shortcut [str] : hw
|
|
418
|
+
description [str] : Run Hello World
|
|
419
|
+
do [script] :
|
|
420
|
+
show 'Hello World!'
|
|
421
|
+
q [mitem] :
|
|
422
|
+
shortcut [str] : q
|
|
423
|
+
description [str] : Quit this menu
|
|
424
|
+
do [script] :
|
|
425
|
+
put false into menu.loop
|
|
426
|
+
EXAMPLES
|
|
427
|
+
}
|
|
428
|
+
end
|
|
429
|
+
|
|
366
430
|
end
|
data/lib/menu_item.rb
CHANGED
|
@@ -88,4 +88,24 @@ class MenuItem < Gloo::Core::Obj
|
|
|
88
88
|
return super
|
|
89
89
|
end
|
|
90
90
|
|
|
91
|
+
# ---------------------------------------------------------------------
|
|
92
|
+
# Object Documentation
|
|
93
|
+
# ---------------------------------------------------------------------
|
|
94
|
+
|
|
95
|
+
#
|
|
96
|
+
# Get the object's documentation data.
|
|
97
|
+
#
|
|
98
|
+
def self.doc_data
|
|
99
|
+
{
|
|
100
|
+
:name => KEYWORD,
|
|
101
|
+
:shortcut => KEYWORD_SHORT,
|
|
102
|
+
:description => 'A CLI menu item. One element in a CLI menu.',
|
|
103
|
+
:children => [
|
|
104
|
+
'shortcut (string) — Optional. May be used to select the menu item. If not provided, the name of the menu item is used instead.',
|
|
105
|
+
'description (string) — Optional. A textual description of the menu item action. If not provided, the value of the menu item is used instead.',
|
|
106
|
+
'do (script) — The script that will be run if the menu item is selected.'
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
end
|
|
110
|
+
|
|
91
111
|
end
|
data/lib/prompt.rb
CHANGED
|
@@ -119,4 +119,35 @@ class Prompt < Gloo::Core::Obj
|
|
|
119
119
|
set_result result
|
|
120
120
|
end
|
|
121
121
|
|
|
122
|
+
# ---------------------------------------------------------------------
|
|
123
|
+
# Object Documentation
|
|
124
|
+
# ---------------------------------------------------------------------
|
|
125
|
+
|
|
126
|
+
#
|
|
127
|
+
# Get the object's documentation data.
|
|
128
|
+
#
|
|
129
|
+
def self.doc_data
|
|
130
|
+
{
|
|
131
|
+
:name => KEYWORD,
|
|
132
|
+
:shortcut => KEYWORD_SHORT,
|
|
133
|
+
:description => 'CLI prompt for user input.',
|
|
134
|
+
:children => [
|
|
135
|
+
"prompt (string) — Default: '>'. The prompt displayed to the user.",
|
|
136
|
+
"result (string) — The result with the user's input."
|
|
137
|
+
],
|
|
138
|
+
:messages => [
|
|
139
|
+
'run — Prompt the user and then set the result.',
|
|
140
|
+
'multiline — Show a multiline prompt.'
|
|
141
|
+
],
|
|
142
|
+
:examples => <<~EXAMPLES.strip
|
|
143
|
+
ask [ask] :
|
|
144
|
+
prompt [string] : What is your name?
|
|
145
|
+
result [string] :
|
|
146
|
+
on_load [script] :
|
|
147
|
+
run ask
|
|
148
|
+
show 'Hello, ' + ask.result + '! Thanks for playing'
|
|
149
|
+
EXAMPLES
|
|
150
|
+
}
|
|
151
|
+
end
|
|
152
|
+
|
|
122
153
|
end
|
data/lib/select.rb
CHANGED
|
@@ -120,4 +120,39 @@ class Select < Gloo::Core::Obj
|
|
|
120
120
|
set_result self.key_for_option( result )
|
|
121
121
|
end
|
|
122
122
|
|
|
123
|
+
# ---------------------------------------------------------------------
|
|
124
|
+
# Object Documentation
|
|
125
|
+
# ---------------------------------------------------------------------
|
|
126
|
+
|
|
127
|
+
#
|
|
128
|
+
# Get the object's documentation data.
|
|
129
|
+
#
|
|
130
|
+
def self.doc_data
|
|
131
|
+
{
|
|
132
|
+
:name => KEYWORD,
|
|
133
|
+
:shortcut => KEYWORD_SHORT,
|
|
134
|
+
:description => 'Prompt for user to select from a list of options.',
|
|
135
|
+
:children => [
|
|
136
|
+
"prompt (string) — Default: '> '. The prompt displayed to the user.",
|
|
137
|
+
'options (container) — The list of options for the selection list. The name of each option is presented to the user, but the value is put in the result.',
|
|
138
|
+
"result (string) — The result with the user's selection."
|
|
139
|
+
],
|
|
140
|
+
:messages => [
|
|
141
|
+
'run — Prompt the user for a selection and then set the result.'
|
|
142
|
+
],
|
|
143
|
+
:examples => <<~EXAMPLES.strip
|
|
144
|
+
select [select] :
|
|
145
|
+
prompt [string] : What is your favorite color?
|
|
146
|
+
options [can] :
|
|
147
|
+
red : r
|
|
148
|
+
green : g
|
|
149
|
+
blue : b
|
|
150
|
+
result [string] :
|
|
151
|
+
on_load [script] :
|
|
152
|
+
run select
|
|
153
|
+
show select.result
|
|
154
|
+
EXAMPLES
|
|
155
|
+
}
|
|
156
|
+
end
|
|
157
|
+
|
|
123
158
|
end
|
data/lib/shell.rb
CHANGED
|
@@ -205,12 +205,52 @@ class Shell < Gloo::Core::Obj
|
|
|
205
205
|
#
|
|
206
206
|
def add_quit_command
|
|
207
207
|
return unless include_quit?
|
|
208
|
-
|
|
208
|
+
|
|
209
209
|
@runner.add_command_node({
|
|
210
210
|
name: "quit",
|
|
211
|
-
description: "Quit the application",
|
|
211
|
+
description: "Quit the application",
|
|
212
212
|
method: "cmd_quit"
|
|
213
213
|
})
|
|
214
214
|
end
|
|
215
215
|
|
|
216
|
+
# ---------------------------------------------------------------------
|
|
217
|
+
# Object Documentation
|
|
218
|
+
# ---------------------------------------------------------------------
|
|
219
|
+
|
|
220
|
+
#
|
|
221
|
+
# Get the object's documentation data.
|
|
222
|
+
#
|
|
223
|
+
def self.doc_data
|
|
224
|
+
{
|
|
225
|
+
:name => KEYWORD,
|
|
226
|
+
:shortcut => KEYWORD_SHORT,
|
|
227
|
+
:description => 'A CLI shell — an interactive command-driven ' \
|
|
228
|
+
'REPL, or a one-shot command executor when the app is invoked ' \
|
|
229
|
+
'with extra command-line arguments. Build up the command tree ' \
|
|
230
|
+
'by adding command objects (see the command object type) that ' \
|
|
231
|
+
'register themselves with this shell.',
|
|
232
|
+
:children => [
|
|
233
|
+
"prompt (string) — Default: '> '. The prompt shown at each turn of the REPL.",
|
|
234
|
+
'default_action (script) — Run when the user presses RETURN with no input.',
|
|
235
|
+
'include_quit (boolean) — Optional. If true, a built-in quit command is added automatically.',
|
|
236
|
+
'on_error (script) — Optional. Run when a command raises an error.',
|
|
237
|
+
"on_unknown_command (script) — Optional. Run when the input doesn't match any known command; if absent, a default \"Unknown command\" message is shown instead.",
|
|
238
|
+
'on_empty_command (script) — Optional. Run when the user submits an empty line.',
|
|
239
|
+
'before_action (script) — Optional. Run before every command executes.',
|
|
240
|
+
'after_action (script) — Optional. Run after every command executes.'
|
|
241
|
+
],
|
|
242
|
+
:messages => [
|
|
243
|
+
'start — Start the shell. If the app was invoked with extra command-line arguments, execute that one command and return; otherwise enter the interactive REPL.',
|
|
244
|
+
'stop — Stop a running shell.'
|
|
245
|
+
],
|
|
246
|
+
:notes => 'No vault documentation exists for this object type — ' \
|
|
247
|
+
'this was authored directly from the code. Commands attach to ' \
|
|
248
|
+
'a shell either by declaring a command object as a child and ' \
|
|
249
|
+
'sending it the register message with this shell\'s path, or ' \
|
|
250
|
+
'by calling add_command directly. The underlying tree/REPL ' \
|
|
251
|
+
'engine here was later ported into dev/gloo itself (as ' \
|
|
252
|
+
'Gloo::Shell::Runner) to power the interactive help shell.'
|
|
253
|
+
}
|
|
254
|
+
end
|
|
255
|
+
|
|
216
256
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gloo-cli
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '1.
|
|
4
|
+
version: '1.6'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Eric Crane
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
12
|
description: Adds CLI support to Gloo.
|
|
14
13
|
email:
|
|
@@ -17,6 +16,7 @@ executables: []
|
|
|
17
16
|
extensions: []
|
|
18
17
|
extra_rdoc_files: []
|
|
19
18
|
files:
|
|
19
|
+
- README.md
|
|
20
20
|
- lib/cli_colorize.rb
|
|
21
21
|
- lib/cli_confirm.rb
|
|
22
22
|
- lib/command.rb
|
|
@@ -29,12 +29,12 @@ files:
|
|
|
29
29
|
- lib/shell.rb
|
|
30
30
|
- lib/shell_context.rb
|
|
31
31
|
- lib/shell_runner.rb
|
|
32
|
-
homepage: https://
|
|
32
|
+
homepage: https://github.com/ecrane/gloo
|
|
33
33
|
licenses:
|
|
34
34
|
- MIT
|
|
35
35
|
metadata:
|
|
36
36
|
gloo.type: core-library
|
|
37
|
-
|
|
37
|
+
documentation_uri: https://github.com/ecrane/gloo
|
|
38
38
|
rdoc_options: []
|
|
39
39
|
require_paths:
|
|
40
40
|
- lib
|
|
@@ -49,8 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
49
49
|
- !ruby/object:Gem::Version
|
|
50
50
|
version: '0'
|
|
51
51
|
requirements: []
|
|
52
|
-
rubygems_version:
|
|
53
|
-
signing_key:
|
|
52
|
+
rubygems_version: 4.0.17
|
|
54
53
|
specification_version: 4
|
|
55
54
|
summary: Gloo core library. CLI support.
|
|
56
55
|
test_files: []
|