gloo-lang 0.9.3 → 0.9.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/Gemfile.lock +1 -1
- data/gloo-lang.gemspec +1 -0
- data/lib/VERSION +1 -1
- data/lib/gloo_lang/app/args.rb +0 -1
- data/lib/gloo_lang/app/engine.rb +10 -37
- data/lib/gloo_lang/app/help.rb +2 -41
- data/lib/gloo_lang/app/info.rb +34 -0
- data/lib/gloo_lang/app/log.rb +8 -10
- data/lib/gloo_lang/app/platform.rb +75 -0
- data/lib/gloo_lang/app/settings.rb +36 -13
- data/lib/gloo_lang/objs/basic/container.rb +1 -12
- data/lib/gloo_lang/objs/basic/text.rb +2 -10
- data/lib/gloo_lang/objs/data/markdown.rb +2 -7
- data/lib/gloo_lang/objs/data/table.rb +1 -29
- data/lib/gloo_lang/verbs/show.rb +3 -2
- metadata +23 -21
- data/lib/gloo_lang/objs/cli/banner.rb +0 -108
- data/lib/gloo_lang/objs/cli/bar.rb +0 -133
- data/lib/gloo_lang/objs/cli/colorize.rb +0 -73
- data/lib/gloo_lang/objs/cli/confirm.rb +0 -96
- data/lib/gloo_lang/objs/cli/menu.rb +0 -206
- data/lib/gloo_lang/objs/cli/menu_item.rb +0 -95
- data/lib/gloo_lang/objs/cli/pastel.rb +0 -97
- data/lib/gloo_lang/objs/cli/prompt.rb +0 -110
- data/lib/gloo_lang/objs/cli/select.rb +0 -126
- data/lib/gloo_lang/objs/dev/git.rb +0 -140
- data/lib/gloo_lang/objs/dev/stats.rb +0 -120
- data/lib/gloo_lang/objs/snd/play.rb +0 -48
- data/lib/gloo_lang/objs/snd/say.rb +0 -98
- data/lib/gloo_lang/objs/system/file_handle.rb +0 -138
- data/lib/gloo_lang/objs/system/ssh_exec.rb +0 -126
- data/lib/gloo_lang/objs/system/system.rb +0 -136
- data/lib/gloo_lang/verbs/alert.rb +0 -79
- data/lib/gloo_lang/verbs/beep.rb +0 -40
- data/lib/gloo_lang/verbs/cls.rb +0 -37
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gloo-lang
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Crane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -138,6 +138,26 @@ dependencies:
|
|
138
138
|
- - ">="
|
139
139
|
- !ruby/object:Gem::Version
|
140
140
|
version: 6.1.0
|
141
|
+
- !ruby/object:Gem::Dependency
|
142
|
+
name: tty-platform
|
143
|
+
requirement: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - "~>"
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0.3'
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: 0.3.0
|
151
|
+
type: :runtime
|
152
|
+
prerelease: false
|
153
|
+
version_requirements: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - "~>"
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0.3'
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: 0.3.0
|
141
161
|
description: A scripting languge to keep it all together.
|
142
162
|
email:
|
143
163
|
- eric.crane@mac.com
|
@@ -164,6 +184,7 @@ files:
|
|
164
184
|
- lib/gloo_lang/app/info.rb
|
165
185
|
- lib/gloo_lang/app/log.rb
|
166
186
|
- lib/gloo_lang/app/mode.rb
|
187
|
+
- lib/gloo_lang/app/platform.rb
|
167
188
|
- lib/gloo_lang/app/settings.rb
|
168
189
|
- lib/gloo_lang/convert/converter.rb
|
169
190
|
- lib/gloo_lang/convert/string_to_datetime.rb
|
@@ -285,15 +306,6 @@ files:
|
|
285
306
|
- lib/gloo_lang/objs/basic/string.rb
|
286
307
|
- lib/gloo_lang/objs/basic/text.rb
|
287
308
|
- lib/gloo_lang/objs/basic/untyped.rb
|
288
|
-
- lib/gloo_lang/objs/cli/banner.rb
|
289
|
-
- lib/gloo_lang/objs/cli/bar.rb
|
290
|
-
- lib/gloo_lang/objs/cli/colorize.rb
|
291
|
-
- lib/gloo_lang/objs/cli/confirm.rb
|
292
|
-
- lib/gloo_lang/objs/cli/menu.rb
|
293
|
-
- lib/gloo_lang/objs/cli/menu_item.rb
|
294
|
-
- lib/gloo_lang/objs/cli/pastel.rb
|
295
|
-
- lib/gloo_lang/objs/cli/prompt.rb
|
296
|
-
- lib/gloo_lang/objs/cli/select.rb
|
297
309
|
- lib/gloo_lang/objs/ctrl/each.rb
|
298
310
|
- lib/gloo_lang/objs/ctrl/repeat.rb
|
299
311
|
- lib/gloo_lang/objs/data/markdown.rb
|
@@ -301,18 +313,11 @@ files:
|
|
301
313
|
- lib/gloo_lang/objs/data/query.rb
|
302
314
|
- lib/gloo_lang/objs/data/sqlite.rb
|
303
315
|
- lib/gloo_lang/objs/data/table.rb
|
304
|
-
- lib/gloo_lang/objs/dev/git.rb
|
305
|
-
- lib/gloo_lang/objs/dev/stats.rb
|
306
316
|
- lib/gloo_lang/objs/dt/date.rb
|
307
317
|
- lib/gloo_lang/objs/dt/datetime.rb
|
308
318
|
- lib/gloo_lang/objs/dt/time.rb
|
309
319
|
- lib/gloo_lang/objs/ror/erb.rb
|
310
320
|
- lib/gloo_lang/objs/ror/eval.rb
|
311
|
-
- lib/gloo_lang/objs/snd/play.rb
|
312
|
-
- lib/gloo_lang/objs/snd/say.rb
|
313
|
-
- lib/gloo_lang/objs/system/file_handle.rb
|
314
|
-
- lib/gloo_lang/objs/system/ssh_exec.rb
|
315
|
-
- lib/gloo_lang/objs/system/system.rb
|
316
321
|
- lib/gloo_lang/objs/web/http_get.rb
|
317
322
|
- lib/gloo_lang/objs/web/http_post.rb
|
318
323
|
- lib/gloo_lang/objs/web/json.rb
|
@@ -327,9 +332,6 @@ files:
|
|
327
332
|
- lib/gloo_lang/utils/format.rb
|
328
333
|
- lib/gloo_lang/utils/stats.rb
|
329
334
|
- lib/gloo_lang/utils/words.rb
|
330
|
-
- lib/gloo_lang/verbs/alert.rb
|
331
|
-
- lib/gloo_lang/verbs/beep.rb
|
332
|
-
- lib/gloo_lang/verbs/cls.rb
|
333
335
|
- lib/gloo_lang/verbs/context.rb
|
334
336
|
- lib/gloo_lang/verbs/create.rb
|
335
337
|
- lib/gloo_lang/verbs/execute.rb
|
@@ -1,108 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# Show a large-text banner.
|
5
|
-
#
|
6
|
-
require 'tty-font'
|
7
|
-
require 'pastel'
|
8
|
-
|
9
|
-
module GlooLang
|
10
|
-
module Objs
|
11
|
-
class Banner < GlooLang::Core::Obj
|
12
|
-
|
13
|
-
KEYWORD = 'banner'.freeze
|
14
|
-
KEYWORD_SHORT = 'ban'.freeze
|
15
|
-
TEXT = 'text'.freeze
|
16
|
-
STYLE = 'style'.freeze
|
17
|
-
COLOR = 'color'.freeze
|
18
|
-
|
19
|
-
#
|
20
|
-
# The name of the object type.
|
21
|
-
#
|
22
|
-
def self.typename
|
23
|
-
return KEYWORD
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
# The short name of the object type.
|
28
|
-
#
|
29
|
-
def self.short_typename
|
30
|
-
return KEYWORD_SHORT
|
31
|
-
end
|
32
|
-
|
33
|
-
#
|
34
|
-
# Get the banner text from the child object.
|
35
|
-
#
|
36
|
-
def text_value
|
37
|
-
o = find_child TEXT
|
38
|
-
return '' unless o
|
39
|
-
|
40
|
-
return o.value
|
41
|
-
end
|
42
|
-
|
43
|
-
#
|
44
|
-
# Get the banner style from the child object.
|
45
|
-
#
|
46
|
-
def style_value
|
47
|
-
o = find_child STYLE
|
48
|
-
return '' unless o
|
49
|
-
|
50
|
-
return o.value
|
51
|
-
end
|
52
|
-
|
53
|
-
#
|
54
|
-
# Get the banner color from the child object.
|
55
|
-
#
|
56
|
-
def color_value
|
57
|
-
o = find_child COLOR
|
58
|
-
return '' unless o
|
59
|
-
|
60
|
-
return o.value
|
61
|
-
end
|
62
|
-
|
63
|
-
# ---------------------------------------------------------------------
|
64
|
-
# Children
|
65
|
-
# ---------------------------------------------------------------------
|
66
|
-
|
67
|
-
# Does this object have children to add when an object
|
68
|
-
# is created in interactive mode?
|
69
|
-
# This does not apply during obj load, etc.
|
70
|
-
def add_children_on_create?
|
71
|
-
return true
|
72
|
-
end
|
73
|
-
|
74
|
-
# Add children to this object.
|
75
|
-
# This is used by containers to add children needed
|
76
|
-
# for default configurations.
|
77
|
-
def add_default_children
|
78
|
-
fac = $engine.factory
|
79
|
-
fac.create_string TEXT, '', self
|
80
|
-
fac.create_string STYLE, '', self
|
81
|
-
fac.create_string COLOR, '', self
|
82
|
-
end
|
83
|
-
|
84
|
-
# ---------------------------------------------------------------------
|
85
|
-
# Messages
|
86
|
-
# ---------------------------------------------------------------------
|
87
|
-
|
88
|
-
#
|
89
|
-
# Get a list of message names that this object receives.
|
90
|
-
#
|
91
|
-
def self.messages
|
92
|
-
return super + %w[show]
|
93
|
-
end
|
94
|
-
|
95
|
-
#
|
96
|
-
# Show the banner bar
|
97
|
-
#
|
98
|
-
def msg_show
|
99
|
-
font = TTY::Font.new self.style_value
|
100
|
-
t = font.write( self.text_value )
|
101
|
-
pastel = ::Pastel.new
|
102
|
-
c = self.color_value.split( ' ' ).map( &:to_sym )
|
103
|
-
puts pastel.decorate( t, *c )
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
@@ -1,133 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# Show a CLI progress bar.
|
5
|
-
#
|
6
|
-
require 'tty-progressbar'
|
7
|
-
|
8
|
-
module GlooLang
|
9
|
-
module Objs
|
10
|
-
class Bar < GlooLang::Core::Obj
|
11
|
-
|
12
|
-
KEYWORD = 'bar'.freeze
|
13
|
-
KEYWORD_SHORT = 'bar'.freeze
|
14
|
-
NAME = 'name'.freeze
|
15
|
-
TOTAL = 'total'.freeze
|
16
|
-
|
17
|
-
#
|
18
|
-
# The name of the object type.
|
19
|
-
#
|
20
|
-
def self.typename
|
21
|
-
return KEYWORD
|
22
|
-
end
|
23
|
-
|
24
|
-
#
|
25
|
-
# The short name of the object type.
|
26
|
-
#
|
27
|
-
def self.short_typename
|
28
|
-
return KEYWORD_SHORT
|
29
|
-
end
|
30
|
-
|
31
|
-
#
|
32
|
-
# Get the bar's name from the child object.
|
33
|
-
#
|
34
|
-
def name_value
|
35
|
-
o = find_child NAME
|
36
|
-
return '' unless o
|
37
|
-
|
38
|
-
return o.value
|
39
|
-
end
|
40
|
-
|
41
|
-
#
|
42
|
-
# Get the bar's total from the child object.
|
43
|
-
#
|
44
|
-
def total_value
|
45
|
-
o = find_child TOTAL
|
46
|
-
return 100 unless o
|
47
|
-
|
48
|
-
return o.value
|
49
|
-
end
|
50
|
-
|
51
|
-
# ---------------------------------------------------------------------
|
52
|
-
# Children
|
53
|
-
# ---------------------------------------------------------------------
|
54
|
-
|
55
|
-
# Does this object have children to add when an object
|
56
|
-
# is created in interactive mode?
|
57
|
-
# This does not apply during obj load, etc.
|
58
|
-
def add_children_on_create?
|
59
|
-
return true
|
60
|
-
end
|
61
|
-
|
62
|
-
# Add children to this object.
|
63
|
-
# This is used by containers to add children needed
|
64
|
-
# for default configurations.
|
65
|
-
def add_default_children
|
66
|
-
fac = $engine.factory
|
67
|
-
fac.create_string NAME, '', self
|
68
|
-
fac.create_int TOTAL, 100, self
|
69
|
-
end
|
70
|
-
|
71
|
-
# ---------------------------------------------------------------------
|
72
|
-
# Messages
|
73
|
-
# ---------------------------------------------------------------------
|
74
|
-
|
75
|
-
#
|
76
|
-
# Get a list of message names that this object receives.
|
77
|
-
#
|
78
|
-
def self.messages
|
79
|
-
return super + %w[start advance stop run]
|
80
|
-
end
|
81
|
-
|
82
|
-
#
|
83
|
-
# Start the progress bar.
|
84
|
-
#
|
85
|
-
def msg_start
|
86
|
-
msg = "#{name_value} [:bar] :percent"
|
87
|
-
@bar = TTY::ProgressBar.new( msg, total: total_value )
|
88
|
-
end
|
89
|
-
|
90
|
-
#
|
91
|
-
# Finish the progress bar.
|
92
|
-
#
|
93
|
-
def msg_stop
|
94
|
-
@bar.finish
|
95
|
-
end
|
96
|
-
|
97
|
-
#
|
98
|
-
# Advance the progress bar.
|
99
|
-
#
|
100
|
-
def msg_advance
|
101
|
-
x = 1
|
102
|
-
if @params&.token_count&.positive?
|
103
|
-
expr = GlooLang::Expr::Expression.new( @params.tokens )
|
104
|
-
x = expr.evaluate.to_i
|
105
|
-
end
|
106
|
-
|
107
|
-
@bar.advance x
|
108
|
-
end
|
109
|
-
|
110
|
-
#
|
111
|
-
# Run for the given number of seconds advancing
|
112
|
-
# the bar to the end.
|
113
|
-
#
|
114
|
-
def msg_run
|
115
|
-
msg_start
|
116
|
-
|
117
|
-
x = 1
|
118
|
-
if @params&.token_count&.positive?
|
119
|
-
expr = GlooLang::Expr::Expression.new( @params.tokens )
|
120
|
-
x = expr.evaluate.to_i
|
121
|
-
end
|
122
|
-
|
123
|
-
100.times do
|
124
|
-
sleep ( 0.0 + x ) / 100.0
|
125
|
-
@bar.advance 1
|
126
|
-
end
|
127
|
-
|
128
|
-
msg_stop
|
129
|
-
end
|
130
|
-
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
@@ -1,73 +0,0 @@
|
|
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
|
-
module GlooLang
|
9
|
-
module Objs
|
10
|
-
class Colorize < GlooLang::Core::Obj
|
11
|
-
|
12
|
-
KEYWORD = 'colorize'.freeze
|
13
|
-
KEYWORD_SHORT = 'color'.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
|
-
# Children
|
31
|
-
# ---------------------------------------------------------------------
|
32
|
-
|
33
|
-
# Does this object have children to add when an object
|
34
|
-
# is created in interactive mode?
|
35
|
-
# This does not apply during obj load, etc.
|
36
|
-
def add_children_on_create?
|
37
|
-
return true
|
38
|
-
end
|
39
|
-
|
40
|
-
# Add children to this object.
|
41
|
-
# This is used by containers to add children needed
|
42
|
-
# for default configurations.
|
43
|
-
def add_default_children
|
44
|
-
fac = $engine.factory
|
45
|
-
fac.create_string 'white', '', self
|
46
|
-
end
|
47
|
-
|
48
|
-
# ---------------------------------------------------------------------
|
49
|
-
# Messages
|
50
|
-
# ---------------------------------------------------------------------
|
51
|
-
|
52
|
-
#
|
53
|
-
# Get a list of message names that this object receives.
|
54
|
-
#
|
55
|
-
def self.messages
|
56
|
-
return super + [ 'run' ]
|
57
|
-
end
|
58
|
-
|
59
|
-
#
|
60
|
-
# Run the colorize command.
|
61
|
-
#
|
62
|
-
def msg_run
|
63
|
-
msg = ''
|
64
|
-
children.each do |o|
|
65
|
-
msg += ColorizedString[ o.value_display ].colorize( o.name.to_sym )
|
66
|
-
end
|
67
|
-
$log.show msg
|
68
|
-
$engine.heap.it.set_to msg.to_s
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
@@ -1,96 +0,0 @@
|
|
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
|
-
module GlooLang
|
8
|
-
module Objs
|
9
|
-
class Confirm < GlooLang::Core::Obj
|
10
|
-
|
11
|
-
KEYWORD = 'confirm'.freeze
|
12
|
-
KEYWORD_SHORT = 'confirm'.freeze
|
13
|
-
PROMPT = 'prompt'.freeze
|
14
|
-
DEFAULT_PROMPT = '> '.freeze
|
15
|
-
RESULT = 'result'.freeze
|
16
|
-
|
17
|
-
#
|
18
|
-
# The name of the object type.
|
19
|
-
#
|
20
|
-
def self.typename
|
21
|
-
return KEYWORD
|
22
|
-
end
|
23
|
-
|
24
|
-
#
|
25
|
-
# The short name of the object type.
|
26
|
-
#
|
27
|
-
def self.short_typename
|
28
|
-
return KEYWORD_SHORT
|
29
|
-
end
|
30
|
-
|
31
|
-
#
|
32
|
-
# Get the URI from the child object.
|
33
|
-
# Returns nil if there is none.
|
34
|
-
#
|
35
|
-
def prompt_value
|
36
|
-
o = find_child PROMPT
|
37
|
-
return nil unless o
|
38
|
-
|
39
|
-
return o.value
|
40
|
-
end
|
41
|
-
|
42
|
-
#
|
43
|
-
# Set the result of the system call.
|
44
|
-
#
|
45
|
-
def set_result( data )
|
46
|
-
r = find_child RESULT
|
47
|
-
return nil unless r
|
48
|
-
|
49
|
-
r.set_value data
|
50
|
-
end
|
51
|
-
|
52
|
-
# ---------------------------------------------------------------------
|
53
|
-
# Children
|
54
|
-
# ---------------------------------------------------------------------
|
55
|
-
|
56
|
-
# Does this object have children to add when an object
|
57
|
-
# is created in interactive mode?
|
58
|
-
# This does not apply during obj load, etc.
|
59
|
-
def add_children_on_create?
|
60
|
-
return true
|
61
|
-
end
|
62
|
-
|
63
|
-
# Add children to this object.
|
64
|
-
# This is used by containers to add children needed
|
65
|
-
# for default configurations.
|
66
|
-
def add_default_children
|
67
|
-
fac = $engine.factory
|
68
|
-
fac.create_string PROMPT, DEFAULT_PROMPT, self
|
69
|
-
fac.create_bool RESULT, nil, self
|
70
|
-
end
|
71
|
-
|
72
|
-
# ---------------------------------------------------------------------
|
73
|
-
# Messages
|
74
|
-
# ---------------------------------------------------------------------
|
75
|
-
|
76
|
-
#
|
77
|
-
# Get a list of message names that this object receives.
|
78
|
-
#
|
79
|
-
def self.messages
|
80
|
-
return super + [ 'run' ]
|
81
|
-
end
|
82
|
-
|
83
|
-
#
|
84
|
-
# Run the confirmation command.
|
85
|
-
#
|
86
|
-
def msg_run
|
87
|
-
prompt = prompt_value
|
88
|
-
return unless prompt
|
89
|
-
|
90
|
-
result = $prompt.yes?( prompt )
|
91
|
-
set_result result
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,206 +0,0 @@
|
|
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
|
-
module GlooLang
|
10
|
-
module Objs
|
11
|
-
class Menu < GlooLang::Core::Obj
|
12
|
-
|
13
|
-
KEYWORD = 'menu'.freeze
|
14
|
-
KEYWORD_SHORT = 'menu'.freeze
|
15
|
-
PROMPT = 'prompt'.freeze
|
16
|
-
ITEMS = 'items'.freeze
|
17
|
-
LOOP = 'loop'.freeze
|
18
|
-
HIDE_ITEMS = 'hide_items'.freeze
|
19
|
-
BEFORE_MENU = 'before_menu'.freeze
|
20
|
-
DEFAULT = 'default'.freeze
|
21
|
-
|
22
|
-
#
|
23
|
-
# The name of the object type.
|
24
|
-
#
|
25
|
-
def self.typename
|
26
|
-
return KEYWORD
|
27
|
-
end
|
28
|
-
|
29
|
-
#
|
30
|
-
# The short name of the object type.
|
31
|
-
#
|
32
|
-
def self.short_typename
|
33
|
-
return KEYWORD_SHORT
|
34
|
-
end
|
35
|
-
|
36
|
-
#
|
37
|
-
# Get the value of the prompt child object.
|
38
|
-
# Returns nil if there is none.
|
39
|
-
#
|
40
|
-
def prompt_value
|
41
|
-
o = find_child PROMPT
|
42
|
-
return '' unless o
|
43
|
-
|
44
|
-
return o.value
|
45
|
-
end
|
46
|
-
|
47
|
-
#
|
48
|
-
# Get the value of the loop child object.
|
49
|
-
# Should we keep looping or should we stop?
|
50
|
-
#
|
51
|
-
def loop?
|
52
|
-
o = find_child LOOP
|
53
|
-
return false unless o
|
54
|
-
|
55
|
-
return o.value
|
56
|
-
end
|
57
|
-
|
58
|
-
# ---------------------------------------------------------------------
|
59
|
-
# Children
|
60
|
-
# ---------------------------------------------------------------------
|
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
|
-
#
|
67
|
-
def add_children_on_create?
|
68
|
-
return true
|
69
|
-
end
|
70
|
-
|
71
|
-
#
|
72
|
-
# Add children to this object.
|
73
|
-
# This is used by containers to add children needed
|
74
|
-
# for default configurations.
|
75
|
-
#
|
76
|
-
def add_default_children
|
77
|
-
fac = $engine.factory
|
78
|
-
fac.create_string PROMPT, '> ', self
|
79
|
-
fac.create_can ITEMS, self
|
80
|
-
fac.create_bool LOOP, true, self
|
81
|
-
fac.create_script DEFAULT, '', self
|
82
|
-
end
|
83
|
-
|
84
|
-
# ---------------------------------------------------------------------
|
85
|
-
# Messages
|
86
|
-
# ---------------------------------------------------------------------
|
87
|
-
|
88
|
-
#
|
89
|
-
# Get a list of message names that this object receives.
|
90
|
-
#
|
91
|
-
def self.messages
|
92
|
-
return super + [ 'run' ]
|
93
|
-
end
|
94
|
-
|
95
|
-
#
|
96
|
-
# Show the menu options, and prompt for user input.
|
97
|
-
#
|
98
|
-
def msg_run
|
99
|
-
loop do
|
100
|
-
begin_menu
|
101
|
-
if prompt_value.empty?
|
102
|
-
dt = DateTime.now
|
103
|
-
d = dt.strftime( '%Y.%m.%d' )
|
104
|
-
t = dt.strftime( '%I:%M:%S' )
|
105
|
-
cmd = $prompt.ask( "#{d.yellow} #{t.white} >" )
|
106
|
-
else
|
107
|
-
cmd = $prompt.ask( prompt_value )
|
108
|
-
end
|
109
|
-
cmd ? run_command( cmd ) : run_default
|
110
|
-
break unless loop?
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
# ---------------------------------------------------------------------
|
115
|
-
# Menu actions
|
116
|
-
# ---------------------------------------------------------------------
|
117
|
-
|
118
|
-
#
|
119
|
-
# Begin the menu execution.
|
120
|
-
# Run the before menu script if there is one,
|
121
|
-
# then show options unless we are hiding them by default.
|
122
|
-
#
|
123
|
-
def begin_menu
|
124
|
-
run_before_menu
|
125
|
-
|
126
|
-
# Check to see if we should show items at all.
|
127
|
-
o = find_child HIDE_ITEMS
|
128
|
-
return if o && o.value == true
|
129
|
-
|
130
|
-
show_options
|
131
|
-
end
|
132
|
-
|
133
|
-
#
|
134
|
-
# If there is a before menu script, run it now.
|
135
|
-
#
|
136
|
-
def run_before_menu
|
137
|
-
o = find_child BEFORE_MENU
|
138
|
-
return unless o
|
139
|
-
|
140
|
-
GlooLang::Exec::Dispatch.message 'run', o
|
141
|
-
end
|
142
|
-
|
143
|
-
#
|
144
|
-
# Show the list of menu options.
|
145
|
-
#
|
146
|
-
def show_options
|
147
|
-
o = find_child ITEMS
|
148
|
-
return unless o
|
149
|
-
|
150
|
-
o.children.each do |mitem|
|
151
|
-
mitem = GlooLang::Objs::Alias.resolve_alias( mitem )
|
152
|
-
puts " #{mitem.shortcut_value} - #{mitem.description_value}"
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
#
|
157
|
-
# Find the command matching user input.
|
158
|
-
#
|
159
|
-
def find_cmd( cmd )
|
160
|
-
o = find_child ITEMS
|
161
|
-
return nil unless o
|
162
|
-
|
163
|
-
o.children.each do |mitem|
|
164
|
-
mitem = GlooLang::Objs::Alias.resolve_alias( mitem )
|
165
|
-
return mitem if mitem.shortcut_value.downcase == cmd.downcase
|
166
|
-
end
|
167
|
-
|
168
|
-
return nil
|
169
|
-
end
|
170
|
-
|
171
|
-
#
|
172
|
-
# Run the default option.
|
173
|
-
#
|
174
|
-
def run_default
|
175
|
-
obj = find_child DEFAULT
|
176
|
-
return unless obj
|
177
|
-
|
178
|
-
s = GlooLang::Exec::Script.new obj
|
179
|
-
s.run
|
180
|
-
end
|
181
|
-
|
182
|
-
#
|
183
|
-
# Run the selected command.
|
184
|
-
#
|
185
|
-
def run_command( cmd )
|
186
|
-
obj = find_cmd cmd
|
187
|
-
|
188
|
-
unless obj
|
189
|
-
if cmd == '?'
|
190
|
-
show_options
|
191
|
-
else
|
192
|
-
puts "#{cmd} is not a valid option"
|
193
|
-
end
|
194
|
-
return
|
195
|
-
end
|
196
|
-
|
197
|
-
script = obj.do_script
|
198
|
-
return unless script
|
199
|
-
|
200
|
-
s = GlooLang::Exec::Script.new script
|
201
|
-
s.run
|
202
|
-
end
|
203
|
-
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|