gloo-cli 2.0 → 2.2
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/lib/menu.rb +35 -11
- data/lib/shell.rb +30 -2
- data/lib/shell_runner.rb +35 -2
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7d03397ae8d5ddcc580deef1c3d0f7acf681493e03fdf77da8034674303f26f8
|
|
4
|
+
data.tar.gz: bf4c226957a48194dde1f52e619a1475b72dc6b67fffcc6d2fe8df0b7122c003
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a84a16f558144fc05292dadc9e45c73740c8bb88fc1ce5c23e6e9e041ac5f9e5d69dafb52c5d4048e8975e830a70cea7f6e49ddb158d1021e086cd539b0d2b01
|
|
7
|
+
data.tar.gz: 73304154299c9e2f7df0a90387271dfa132506cbdc35835ee32f2b18ffa237e1225a92a82ac3f4711b67c07d8ddc03415fd4c6fcca3ca10b06e9a17d48e767e0
|
data/lib/menu.rb
CHANGED
|
@@ -19,6 +19,7 @@ class Menu < Gloo::Core::Obj
|
|
|
19
19
|
TITLE = 'title'.freeze
|
|
20
20
|
TITLE_COLOR = 'green'.freeze
|
|
21
21
|
QUIT_ITEM_NAME = 'q'.freeze
|
|
22
|
+
QUIT_HINT = "Use 'q' to quit this menu.".freeze
|
|
22
23
|
|
|
23
24
|
@@menu_stack = []
|
|
24
25
|
|
|
@@ -227,21 +228,42 @@ class Menu < Gloo::Core::Obj
|
|
|
227
228
|
run_default
|
|
228
229
|
loop do
|
|
229
230
|
begin_menu
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
cmd = @engine.platform.prompt.ask( "#{theme.accent( d )} #{theme.emphasis( t )} >" )
|
|
236
|
-
else
|
|
237
|
-
cmd = @engine.platform.prompt.ask( prompt_value )
|
|
238
|
-
end
|
|
239
|
-
cmd ? run_command( cmd ) : run_default
|
|
231
|
+
cmd = ask_command
|
|
232
|
+
next if cmd == :interrupted
|
|
233
|
+
|
|
234
|
+
# Ctrl-C stops the command and comes back to this menu.
|
|
235
|
+
@engine.run_interruptible { cmd ? run_command( cmd ) : run_default }
|
|
240
236
|
break unless loop?
|
|
241
237
|
end
|
|
242
238
|
pop_menu self
|
|
243
239
|
end
|
|
244
240
|
|
|
241
|
+
#
|
|
242
|
+
# Show the prompt and read a command: nil at the end of input, or
|
|
243
|
+
# :interrupted if Ctrl-C dropped the line (with the hint, if nothing
|
|
244
|
+
# had been typed).
|
|
245
|
+
#
|
|
246
|
+
def ask_command
|
|
247
|
+
prompt = @engine.platform.prompt
|
|
248
|
+
return prompt.ask( prompt_text )
|
|
249
|
+
rescue Interrupt
|
|
250
|
+
@engine.interrupted_at_prompt( prompt.line_typed, QUIT_HINT )
|
|
251
|
+
return :interrupted
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
#
|
|
255
|
+
# The menu's prompt: its own, or the date and time.
|
|
256
|
+
#
|
|
257
|
+
def prompt_text
|
|
258
|
+
return prompt_value unless prompt_value.empty?
|
|
259
|
+
|
|
260
|
+
dt = DateTime.now
|
|
261
|
+
d = dt.strftime( '%Y.%m.%d' )
|
|
262
|
+
t = dt.strftime( '%I:%M:%S' )
|
|
263
|
+
theme = @engine.theme
|
|
264
|
+
return "#{theme.accent( d )} #{theme.emphasis( t )} >"
|
|
265
|
+
end
|
|
266
|
+
|
|
245
267
|
# ---------------------------------------------------------------------
|
|
246
268
|
# Menu actions
|
|
247
269
|
# ---------------------------------------------------------------------
|
|
@@ -403,7 +425,9 @@ class Menu < Gloo::Core::Obj
|
|
|
403
425
|
'menu (not shown); q! — quit gloo entirely (not shown); ' \
|
|
404
426
|
': {command} — run a gloo command not part of the running app; ' \
|
|
405
427
|
': (alone) — quit the running app and drop into gloo, keeping ' \
|
|
406
|
-
'loaded app objects in the stack.'
|
|
428
|
+
'loaded app objects in the stack. Ctrl-C during an item stops ' \
|
|
429
|
+
'it and comes back to the menu; at an empty prompt it says how ' \
|
|
430
|
+
'to leave. See doc application, Stopping with Ctrl-C.',
|
|
407
431
|
:examples => <<~EXAMPLES.strip
|
|
408
432
|
simple [menu] :
|
|
409
433
|
on_load [script] :
|
data/lib/shell.rb
CHANGED
|
@@ -16,6 +16,8 @@ class Shell < Gloo::Core::Obj
|
|
|
16
16
|
BEFORE_ACTION = 'before_action'.freeze
|
|
17
17
|
AFTER_ACTION = 'after_action'.freeze
|
|
18
18
|
WITH_COMMAND = 'with_command'.freeze
|
|
19
|
+
NOT_IN_SCRIPT_MODE_ERR = "Could not start the shell: an app runs in App mode. Run it with 'gloo --app %s'.".freeze
|
|
20
|
+
UNKNOWN_APP_FOLDER = '<folder>'.freeze
|
|
19
21
|
|
|
20
22
|
#
|
|
21
23
|
# The name of the object type.
|
|
@@ -122,6 +124,8 @@ class Shell < Gloo::Core::Obj
|
|
|
122
124
|
# that one command and return. Otherwise, enter the interactive REPL.
|
|
123
125
|
#
|
|
124
126
|
def msg_start
|
|
127
|
+
return script_mode_err if @engine.mode == Gloo::App::Mode::SCRIPT
|
|
128
|
+
|
|
125
129
|
runner = get_runner
|
|
126
130
|
|
|
127
131
|
# add_test_commands
|
|
@@ -130,6 +134,25 @@ class Shell < Gloo::Core::Obj
|
|
|
130
134
|
runner.start
|
|
131
135
|
end
|
|
132
136
|
|
|
137
|
+
#
|
|
138
|
+
# A shell is an app, and an app runs in App mode. Started from a
|
|
139
|
+
# script run (gloo folder/start.gloo) it's a mistake: report it,
|
|
140
|
+
# with the command that runs the app, instead of starting.
|
|
141
|
+
#
|
|
142
|
+
def script_mode_err
|
|
143
|
+
@engine.err format( NOT_IN_SCRIPT_MODE_ERR, app_folder )
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
#
|
|
147
|
+
# The folder of the file gloo was run with (in Script mode, the
|
|
148
|
+
# first file loaded): the folder to give --app. A placeholder if
|
|
149
|
+
# nothing came from a file.
|
|
150
|
+
#
|
|
151
|
+
def app_folder
|
|
152
|
+
pn = @engine.persist_man.maps.first&.pn
|
|
153
|
+
return pn ? File.dirname( pn ) : UNKNOWN_APP_FOLDER
|
|
154
|
+
end
|
|
155
|
+
|
|
133
156
|
#
|
|
134
157
|
# Stop the shell.
|
|
135
158
|
#
|
|
@@ -247,7 +270,9 @@ class Shell < Gloo::Core::Obj
|
|
|
247
270
|
'one-shot run from an interactive session.'
|
|
248
271
|
],
|
|
249
272
|
:messages => [
|
|
250
|
-
'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.'
|
|
273
|
+
'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. ' \
|
|
274
|
+
'A shell is an app and runs in App mode (gloo --app {folder}): started from a script run (gloo {folder}/start.gloo) it does not start, and reports ' \
|
|
275
|
+
"Could not start the shell: an app runs in App mode. Run it with 'gloo --app {folder}'.",
|
|
251
276
|
'stop — Stop a running shell.'
|
|
252
277
|
],
|
|
253
278
|
:notes => 'No vault documentation exists for this object type — ' \
|
|
@@ -256,7 +281,10 @@ class Shell < Gloo::Core::Obj
|
|
|
256
281
|
'sending it the register message with this shell\'s path, or ' \
|
|
257
282
|
'by calling add_command directly. The underlying tree/REPL ' \
|
|
258
283
|
'engine here was later ported into dev/gloo itself (as ' \
|
|
259
|
-
'Gloo::Shell::Runner) to power the interactive help shell.'
|
|
284
|
+
'Gloo::Shell::Runner) to power the interactive help shell. ' \
|
|
285
|
+
'Ctrl-C during a command stops it and comes back to the ' \
|
|
286
|
+
'shell\'s prompt; at an empty prompt it says how to leave ' \
|
|
287
|
+
'(with include_quit). See doc application, Stopping with Ctrl-C.'
|
|
260
288
|
}
|
|
261
289
|
end
|
|
262
290
|
|
data/lib/shell_runner.rb
CHANGED
|
@@ -10,6 +10,7 @@ class ShellRunner
|
|
|
10
10
|
|
|
11
11
|
DEFAULT_PROMPT = " -> "
|
|
12
12
|
UNKNOWN_COMMAND = "Unknown command".freeze
|
|
13
|
+
QUIT_HINT = "Use 'quit' to leave the shell.".freeze
|
|
13
14
|
|
|
14
15
|
#
|
|
15
16
|
# Initialize the shell runner
|
|
@@ -294,15 +295,47 @@ class ShellRunner
|
|
|
294
295
|
def repl
|
|
295
296
|
setup_completion
|
|
296
297
|
|
|
297
|
-
|
|
298
|
+
until @context.done
|
|
299
|
+
line = read_line
|
|
300
|
+
next if line == :interrupted
|
|
301
|
+
break unless line
|
|
302
|
+
|
|
298
303
|
tokens = line.strip.split(" ")
|
|
299
304
|
if tokens.empty?
|
|
300
305
|
handle_empty_command
|
|
301
306
|
next
|
|
302
307
|
end
|
|
303
308
|
|
|
304
|
-
|
|
309
|
+
# Ctrl-C stops the command and comes back to this prompt.
|
|
310
|
+
@engine.run_interruptible { run_tokens( tokens ) }
|
|
305
311
|
end
|
|
306
312
|
end
|
|
307
313
|
|
|
314
|
+
#
|
|
315
|
+
# Read a line at the shell's prompt: nil at the end of input, or
|
|
316
|
+
# :interrupted if Ctrl-C dropped the line (with the hint, if nothing
|
|
317
|
+
# had been typed).
|
|
318
|
+
#
|
|
319
|
+
def read_line
|
|
320
|
+
return Readline.readline( prompt, true )
|
|
321
|
+
rescue Interrupt
|
|
322
|
+
@engine.interrupted_at_prompt( line_typed, quit_hint )
|
|
323
|
+
return :interrupted
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
#
|
|
327
|
+
# What had been typed when Ctrl-C was pressed.
|
|
328
|
+
#
|
|
329
|
+
def line_typed
|
|
330
|
+
return Readline.respond_to?( :line_buffer ) ? Readline.line_buffer.to_s : ''
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
#
|
|
334
|
+
# How to leave the shell, for the Ctrl-C hint: its quit command, if it
|
|
335
|
+
# has one.
|
|
336
|
+
#
|
|
337
|
+
def quit_hint
|
|
338
|
+
return @obj.include_quit? ? QUIT_HINT : nil
|
|
339
|
+
end
|
|
340
|
+
|
|
308
341
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gloo-cli
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '2.
|
|
4
|
+
version: '2.2'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Eric Crane
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '7.
|
|
18
|
+
version: '7.3'
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '7.
|
|
25
|
+
version: '7.3'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: bundler
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|