gloo-cli 1.3 → 1.4
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/command.rb +18 -1
- data/lib/shell.rb +61 -44
- data/lib/shell_runner.rb +34 -7
- 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: 9c190c4ba0bf57cc2f1abe2584610e8aaa3b6899b84ce61b1d04dbcd8bef61d0
|
|
4
|
+
data.tar.gz: e20087e9ca4690e4f25f0ab6db2619bc4ad37f6ebc1bd7bec9666b9b8c82c3ec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 310e0ac6d960606d8ae5bd5d9eb1624b400e5b7e0e67fc2614d0f4705ef8bfb8f6a491aacfbbe147d90020c5c0dfa0c5165a529ddf4325aaf88e81c8ca74219a
|
|
7
|
+
data.tar.gz: f643f55dc272167facafa4d4d317bd91e4e450d2c54a5dc228581f167561c3583507b7e7a9de47cf22554bc06282d9e0b57ec0338b3aad140473ce6ead82d293
|
data/lib/command.rb
CHANGED
|
@@ -8,6 +8,7 @@ class Command < Gloo::Core::Obj
|
|
|
8
8
|
|
|
9
9
|
KEYWORD = 'command'.freeze
|
|
10
10
|
KEYWORD_SHORT = 'command'.freeze
|
|
11
|
+
NAME = 'name'.freeze
|
|
11
12
|
DESCRIPTION = 'description'.freeze
|
|
12
13
|
ACTION = 'action'.freeze
|
|
13
14
|
DYNAMIC = 'dynamic'.freeze
|
|
@@ -16,6 +17,7 @@ class Command < Gloo::Core::Obj
|
|
|
16
17
|
CONTEXT = 'context'.freeze
|
|
17
18
|
OPTIONS = 'options'.freeze
|
|
18
19
|
OPTIONS_KEY = 'options_key'.freeze
|
|
20
|
+
ON_ERROR = 'on_error'.freeze
|
|
19
21
|
|
|
20
22
|
#
|
|
21
23
|
# The name of the object type.
|
|
@@ -105,14 +107,29 @@ class Command < Gloo::Core::Obj
|
|
|
105
107
|
Gloo::Exec::Dispatch.message( @engine, 'run', o )
|
|
106
108
|
end
|
|
107
109
|
|
|
110
|
+
#
|
|
111
|
+
# Run the action script with context.
|
|
112
|
+
#
|
|
108
113
|
def run_action_with_context( context )
|
|
109
114
|
o = find_child ACTION
|
|
110
115
|
return unless o
|
|
111
116
|
|
|
112
117
|
ctx = find_child CONTEXT
|
|
113
118
|
ctx.set_value( context ) if ctx
|
|
114
|
-
|
|
119
|
+
|
|
120
|
+
Gloo::Exec::Dispatch.message( @engine, 'run', o )
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
#
|
|
124
|
+
# Run the on_error script if one exists.
|
|
125
|
+
# Returns true if the script was found and run, false otherwise.
|
|
126
|
+
#
|
|
127
|
+
def run_on_error
|
|
128
|
+
o = find_child ON_ERROR
|
|
129
|
+
return false unless o
|
|
130
|
+
|
|
115
131
|
Gloo::Exec::Dispatch.message( @engine, 'run', o )
|
|
132
|
+
return true
|
|
116
133
|
end
|
|
117
134
|
|
|
118
135
|
|
data/lib/shell.rb
CHANGED
|
@@ -11,6 +11,11 @@ class Shell < Gloo::Core::Obj
|
|
|
11
11
|
PROMPT = 'prompt'.freeze
|
|
12
12
|
DEFAULT_ACTION = 'default_action'.freeze
|
|
13
13
|
INCLUDE_QUIT = 'include_quit'.freeze
|
|
14
|
+
ON_ERROR = 'on_error'.freeze
|
|
15
|
+
ON_UNKNOWN_CMD = 'on_unknown_command'.freeze
|
|
16
|
+
ON_EMPTY_CMD = 'on_empty_command'.freeze
|
|
17
|
+
BEFORE_ACTION = 'before_action'.freeze
|
|
18
|
+
AFTER_ACTION = 'after_action'.freeze
|
|
14
19
|
|
|
15
20
|
#
|
|
16
21
|
# The name of the object type.
|
|
@@ -127,6 +132,62 @@ class Shell < Gloo::Core::Obj
|
|
|
127
132
|
@runner.set_context( key, value )
|
|
128
133
|
end
|
|
129
134
|
|
|
135
|
+
#
|
|
136
|
+
# Run the on_error script if one exists.
|
|
137
|
+
# Returns true if the script was found and run, false otherwise.
|
|
138
|
+
#
|
|
139
|
+
def run_on_error
|
|
140
|
+
o = find_child ON_ERROR
|
|
141
|
+
return false unless o
|
|
142
|
+
|
|
143
|
+
Gloo::Exec::Dispatch.message( @engine, 'run', o )
|
|
144
|
+
return true
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
#
|
|
148
|
+
# Run the on_unknown_cmd script if one exists.
|
|
149
|
+
# Returns true if the script was found and run, false otherwise.
|
|
150
|
+
#
|
|
151
|
+
def run_on_unknown_cmd
|
|
152
|
+
o = find_child ON_UNKNOWN_CMD
|
|
153
|
+
return false unless o
|
|
154
|
+
|
|
155
|
+
Gloo::Exec::Dispatch.message( @engine, 'run', o )
|
|
156
|
+
return true
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
#
|
|
160
|
+
# Run the on_empty_command script if one exists.
|
|
161
|
+
# Returns true if the script was found and run, false otherwise.
|
|
162
|
+
#
|
|
163
|
+
def run_on_empty_cmd
|
|
164
|
+
o = find_child ON_EMPTY_CMD
|
|
165
|
+
return false unless o
|
|
166
|
+
|
|
167
|
+
Gloo::Exec::Dispatch.message( @engine, 'run', o )
|
|
168
|
+
return true
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
#
|
|
172
|
+
# Run the before_action script if one exists.
|
|
173
|
+
#
|
|
174
|
+
def run_before_action
|
|
175
|
+
o = find_child BEFORE_ACTION
|
|
176
|
+
return unless o
|
|
177
|
+
|
|
178
|
+
Gloo::Exec::Dispatch.message( @engine, 'run', o )
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
#
|
|
182
|
+
# Run the after_action script if one exists.
|
|
183
|
+
#
|
|
184
|
+
def run_after_action
|
|
185
|
+
o = find_child AFTER_ACTION
|
|
186
|
+
return unless o
|
|
187
|
+
|
|
188
|
+
Gloo::Exec::Dispatch.message( @engine, 'run', o )
|
|
189
|
+
end
|
|
190
|
+
|
|
130
191
|
|
|
131
192
|
# ---------------------------------------------------------------------
|
|
132
193
|
# Commands
|
|
@@ -145,48 +206,4 @@ class Shell < Gloo::Core::Obj
|
|
|
145
206
|
})
|
|
146
207
|
end
|
|
147
208
|
|
|
148
|
-
# def add_test_commands
|
|
149
|
-
# @runner.add_command_node({
|
|
150
|
-
# name: "add",
|
|
151
|
-
# description: "add a project",
|
|
152
|
-
# method: "cmd_add"
|
|
153
|
-
# })
|
|
154
|
-
|
|
155
|
-
# @runner.add_command_node({
|
|
156
|
-
# name: "show",
|
|
157
|
-
# description: "show a resource",
|
|
158
|
-
# children: [
|
|
159
|
-
# {
|
|
160
|
-
# name: "project",
|
|
161
|
-
# description: "show a project",
|
|
162
|
-
# dynamic: true,
|
|
163
|
-
# source: "projects"
|
|
164
|
-
# },
|
|
165
|
-
# {
|
|
166
|
-
# name: "task",
|
|
167
|
-
# description: "show a task",
|
|
168
|
-
# dynamic: true,
|
|
169
|
-
# source: "tasks"
|
|
170
|
-
# }
|
|
171
|
-
# ]
|
|
172
|
-
# })
|
|
173
|
-
|
|
174
|
-
# @runner.add_command_node({
|
|
175
|
-
# name: "list",
|
|
176
|
-
# description: "list resources",
|
|
177
|
-
# children: [
|
|
178
|
-
# {
|
|
179
|
-
# name: "projects",
|
|
180
|
-
# description: "list projects",
|
|
181
|
-
# method: "cmd_projects"
|
|
182
|
-
# },
|
|
183
|
-
# {
|
|
184
|
-
# name: "tasks",
|
|
185
|
-
# description: "list tasks",
|
|
186
|
-
# method: "cmd_tasks"
|
|
187
|
-
# }
|
|
188
|
-
# ]
|
|
189
|
-
# })
|
|
190
|
-
# end
|
|
191
|
-
|
|
192
209
|
end
|
data/lib/shell_runner.rb
CHANGED
|
@@ -9,6 +9,8 @@ require "readline"
|
|
|
9
9
|
class ShellRunner
|
|
10
10
|
|
|
11
11
|
DEFAULT_PROMPT = " -> "
|
|
12
|
+
UNKNOWN_COMMAND = "Unknown command".freeze
|
|
13
|
+
|
|
12
14
|
#
|
|
13
15
|
# Initialize the shell runner
|
|
14
16
|
#
|
|
@@ -48,9 +50,23 @@ class ShellRunner
|
|
|
48
50
|
return p ? p + ' ' : DEFAULT_PROMPT
|
|
49
51
|
end
|
|
50
52
|
|
|
51
|
-
#
|
|
53
|
+
#
|
|
54
|
+
# Handle an empty command — run on_empty_command if defined, otherwise do nothing.
|
|
55
|
+
#
|
|
56
|
+
def handle_empty_command
|
|
57
|
+
@obj.run_on_empty_cmd
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
#
|
|
61
|
+
# Handle an unknown command — run on_unknown_cmd if defined, otherwise show default message.
|
|
62
|
+
#
|
|
63
|
+
def handle_unknown_command
|
|
64
|
+
@obj.run_on_unknown_cmd || puts( UNKNOWN_COMMAND )
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
#
|
|
52
68
|
# Quit the shell.
|
|
53
|
-
#
|
|
69
|
+
#
|
|
54
70
|
def cmd_quit( obj, context )
|
|
55
71
|
puts "Quitting…"
|
|
56
72
|
context.done = true
|
|
@@ -67,15 +83,21 @@ class ShellRunner
|
|
|
67
83
|
end
|
|
68
84
|
end
|
|
69
85
|
|
|
70
|
-
|
|
86
|
+
#
|
|
87
|
+
# Run an action on an object with context.
|
|
88
|
+
#
|
|
89
|
+
def cmd_obj_action_with_context( cmd_node, parent_node = nil )
|
|
71
90
|
if parent_node
|
|
72
91
|
pn = Gloo::Core::Pn.new( @engine, parent_node.obj )
|
|
73
92
|
command = pn.resolve
|
|
74
93
|
if command
|
|
75
|
-
|
|
94
|
+
begin
|
|
95
|
+
command.run_action_with_context( cmd_node.name )
|
|
96
|
+
rescue => e
|
|
97
|
+
command.run_on_error || @obj.run_on_error
|
|
98
|
+
end
|
|
76
99
|
end
|
|
77
100
|
end
|
|
78
|
-
|
|
79
101
|
end
|
|
80
102
|
|
|
81
103
|
|
|
@@ -228,14 +250,19 @@ class ShellRunner
|
|
|
228
250
|
|
|
229
251
|
while ( ! @context.done && (line = Readline.readline(prompt, true)) )
|
|
230
252
|
tokens = line.strip.split(" ")
|
|
231
|
-
|
|
253
|
+
if tokens.empty?
|
|
254
|
+
handle_empty_command
|
|
255
|
+
next
|
|
256
|
+
end
|
|
232
257
|
|
|
233
258
|
result = traverse( @root, tokens )
|
|
234
259
|
|
|
235
260
|
if result[:node]
|
|
261
|
+
@obj.run_before_action
|
|
236
262
|
execute_command( result[:node], tokens, result[:parent] )
|
|
263
|
+
@obj.run_after_action
|
|
237
264
|
else
|
|
238
|
-
|
|
265
|
+
handle_unknown_command
|
|
239
266
|
end
|
|
240
267
|
end
|
|
241
268
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gloo-cli
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '1.
|
|
4
|
+
version: '1.4'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Eric Crane
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-06-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Adds CLI support to Gloo.
|
|
14
14
|
email:
|