gloo 0.7.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/Gemfile.lock +46 -39
  4. data/LICENSE.txt +1 -1
  5. data/gloo.gemspec +12 -6
  6. data/lib/VERSION +1 -1
  7. data/lib/dependencies.rb +28 -0
  8. data/lib/gloo/app/info.rb +3 -1
  9. data/lib/gloo/app/log.rb +1 -29
  10. data/lib/gloo/app/platform.rb +142 -0
  11. data/lib/gloo/objs/cli/banner.rb +2 -2
  12. data/lib/gloo/objs/cli/bar.rb +4 -4
  13. data/lib/gloo/objs/cli/colorize.rb +3 -3
  14. data/lib/gloo/objs/cli/confirm.rb +3 -3
  15. data/lib/gloo/objs/cli/menu.rb +9 -9
  16. data/lib/gloo/objs/cli/menu_item.rb +2 -2
  17. data/lib/gloo/objs/cli/pastel.rb +2 -2
  18. data/lib/gloo/objs/cli/prompt.rb +4 -4
  19. data/lib/gloo/objs/cli/select.rb +4 -4
  20. data/lib/gloo/objs/dev/git.rb +7 -7
  21. data/lib/gloo/objs/dev/stats.rb +8 -5
  22. data/lib/gloo/objs/snd/play.rb +1 -1
  23. data/lib/gloo/objs/snd/say.rb +2 -2
  24. data/lib/gloo/objs/system/file_handle.rb +9 -9
  25. data/lib/gloo/objs/system/ssh_exec.rb +3 -3
  26. data/lib/gloo/objs/system/system.rb +2 -2
  27. data/lib/gloo/verbs/alert.rb +7 -7
  28. data/lib/gloo/verbs/beep.rb +1 -1
  29. data/lib/gloo/verbs/cls.rb +2 -2
  30. data/lib/gloo.rb +7 -7
  31. data/lib/run.rb +7 -5
  32. metadata +42 -147
  33. data/lib/gloo/app/args.rb +0 -112
  34. data/lib/gloo/app/engine.rb +0 -230
  35. data/lib/gloo/app/help.rb +0 -156
  36. data/lib/gloo/app/mode.rb +0 -27
  37. data/lib/gloo/app/settings.rb +0 -186
  38. data/lib/gloo/convert/converter.rb +0 -35
  39. data/lib/gloo/convert/string_to_datetime.rb +0 -21
  40. data/lib/gloo/convert/string_to_decimal.rb +0 -20
  41. data/lib/gloo/convert/string_to_integer.rb +0 -20
  42. data/lib/gloo/core/baseo.rb +0 -28
  43. data/lib/gloo/core/dictionary.rb +0 -181
  44. data/lib/gloo/core/error.rb +0 -61
  45. data/lib/gloo/core/event_manager.rb +0 -44
  46. data/lib/gloo/core/factory.rb +0 -210
  47. data/lib/gloo/core/gloo_system.rb +0 -266
  48. data/lib/gloo/core/heap.rb +0 -52
  49. data/lib/gloo/core/here.rb +0 -36
  50. data/lib/gloo/core/it.rb +0 -36
  51. data/lib/gloo/core/literal.rb +0 -30
  52. data/lib/gloo/core/obj.rb +0 -305
  53. data/lib/gloo/core/obj_finder.rb +0 -30
  54. data/lib/gloo/core/op.rb +0 -40
  55. data/lib/gloo/core/parser.rb +0 -59
  56. data/lib/gloo/core/pn.rb +0 -188
  57. data/lib/gloo/core/tokens.rb +0 -165
  58. data/lib/gloo/core/verb.rb +0 -86
  59. data/lib/gloo/exec/action.rb +0 -48
  60. data/lib/gloo/exec/dispatch.rb +0 -40
  61. data/lib/gloo/exec/exec_env.rb +0 -74
  62. data/lib/gloo/exec/runner.rb +0 -45
  63. data/lib/gloo/exec/script.rb +0 -49
  64. data/lib/gloo/exec/stack.rb +0 -78
  65. data/lib/gloo/expr/expression.rb +0 -118
  66. data/lib/gloo/expr/l_boolean.rb +0 -36
  67. data/lib/gloo/expr/l_decimal.rb +0 -39
  68. data/lib/gloo/expr/l_integer.rb +0 -37
  69. data/lib/gloo/expr/l_string.rb +0 -58
  70. data/lib/gloo/expr/op_div.rb +0 -22
  71. data/lib/gloo/expr/op_minus.rb +0 -22
  72. data/lib/gloo/expr/op_mult.rb +0 -22
  73. data/lib/gloo/expr/op_plus.rb +0 -24
  74. data/lib/gloo/objs/basic/alias.rb +0 -78
  75. data/lib/gloo/objs/basic/boolean.rb +0 -120
  76. data/lib/gloo/objs/basic/container.rb +0 -76
  77. data/lib/gloo/objs/basic/decimal.rb +0 -76
  78. data/lib/gloo/objs/basic/integer.rb +0 -73
  79. data/lib/gloo/objs/basic/script.rb +0 -99
  80. data/lib/gloo/objs/basic/string.rb +0 -77
  81. data/lib/gloo/objs/basic/text.rb +0 -87
  82. data/lib/gloo/objs/basic/untyped.rb +0 -41
  83. data/lib/gloo/objs/ctrl/each.rb +0 -279
  84. data/lib/gloo/objs/ctrl/repeat.rb +0 -108
  85. data/lib/gloo/objs/data/markdown.rb +0 -84
  86. data/lib/gloo/objs/data/mysql.rb +0 -192
  87. data/lib/gloo/objs/data/query.rb +0 -176
  88. data/lib/gloo/objs/data/sqlite.rb +0 -159
  89. data/lib/gloo/objs/data/table.rb +0 -140
  90. data/lib/gloo/objs/dt/date.rb +0 -50
  91. data/lib/gloo/objs/dt/datetime.rb +0 -62
  92. data/lib/gloo/objs/dt/time.rb +0 -50
  93. data/lib/gloo/objs/ror/erb.rb +0 -116
  94. data/lib/gloo/objs/ror/eval.rb +0 -107
  95. data/lib/gloo/objs/web/http_get.rb +0 -159
  96. data/lib/gloo/objs/web/http_post.rb +0 -183
  97. data/lib/gloo/objs/web/json.rb +0 -135
  98. data/lib/gloo/objs/web/slack.rb +0 -130
  99. data/lib/gloo/objs/web/teams.rb +0 -117
  100. data/lib/gloo/objs/web/uri.rb +0 -148
  101. data/lib/gloo/persist/file_loader.rb +0 -191
  102. data/lib/gloo/persist/file_saver.rb +0 -49
  103. data/lib/gloo/persist/file_storage.rb +0 -45
  104. data/lib/gloo/persist/line_splitter.rb +0 -81
  105. data/lib/gloo/persist/persist_man.rb +0 -120
  106. data/lib/gloo/utils/format.rb +0 -21
  107. data/lib/gloo/utils/stats.rb +0 -205
  108. data/lib/gloo/utils/words.rb +0 -19
  109. data/lib/gloo/verbs/context.rb +0 -62
  110. data/lib/gloo/verbs/create.rb +0 -68
  111. data/lib/gloo/verbs/execute.rb +0 -56
  112. data/lib/gloo/verbs/help.rb +0 -264
  113. data/lib/gloo/verbs/if.rb +0 -92
  114. data/lib/gloo/verbs/list.rb +0 -98
  115. data/lib/gloo/verbs/load.rb +0 -45
  116. data/lib/gloo/verbs/move.rb +0 -89
  117. data/lib/gloo/verbs/put.rb +0 -94
  118. data/lib/gloo/verbs/quit.rb +0 -40
  119. data/lib/gloo/verbs/run.rb +0 -75
  120. data/lib/gloo/verbs/save.rb +0 -39
  121. data/lib/gloo/verbs/show.rb +0 -64
  122. data/lib/gloo/verbs/tell.rb +0 -79
  123. data/lib/gloo/verbs/unless.rb +0 -92
  124. data/lib/gloo/verbs/version.rb +0 -37
  125. data/lib/gloo/verbs/wait.rb +0 -42
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gloo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.6
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Crane
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-11 00:00:00.000000000 Z
11
+ date: 2022-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,34 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: 1.17.3
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: 1.17.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.0'
33
+ version: '5.1'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 5.14.2
34
37
  type: :development
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
41
  - - "~>"
39
42
  - !ruby/object:Gem::Version
40
- version: '5.0'
43
+ version: '5.1'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 5.14.2
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: rake
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -58,26 +64,46 @@ dependencies:
58
64
  - - ">="
59
65
  - !ruby/object:Gem::Version
60
66
  version: 13.0.1
67
+ - !ruby/object:Gem::Dependency
68
+ name: gloo-lang
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '1.0'
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 1.0.1
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '1.0'
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 1.0.1
61
87
  - !ruby/object:Gem::Dependency
62
88
  name: activesupport
63
89
  requirement: !ruby/object:Gem::Requirement
64
90
  requirements:
65
91
  - - "~>"
66
92
  - !ruby/object:Gem::Version
67
- version: '5.2'
93
+ version: '6.1'
68
94
  - - ">="
69
95
  - !ruby/object:Gem::Version
70
- version: 5.2.4.3
96
+ version: 6.1.5
71
97
  type: :runtime
72
98
  prerelease: false
73
99
  version_requirements: !ruby/object:Gem::Requirement
74
100
  requirements:
75
101
  - - "~>"
76
102
  - !ruby/object:Gem::Version
77
- version: '5.2'
103
+ version: '6.1'
78
104
  - - ">="
79
105
  - !ruby/object:Gem::Version
80
- version: 5.2.4.3
106
+ version: 6.1.5
81
107
  - !ruby/object:Gem::Dependency
82
108
  name: chronic
83
109
  requirement: !ruby/object:Gem::Requirement
@@ -124,20 +150,20 @@ dependencies:
124
150
  requirements:
125
151
  - - "~>"
126
152
  - !ruby/object:Gem::Version
127
- version: '0.8'
153
+ version: '0.10'
128
154
  - - ">="
129
155
  - !ruby/object:Gem::Version
130
- version: 0.8.1
156
+ version: 0.10.0
131
157
  type: :runtime
132
158
  prerelease: false
133
159
  version_requirements: !ruby/object:Gem::Requirement
134
160
  requirements:
135
161
  - - "~>"
136
162
  - !ruby/object:Gem::Version
137
- version: '0.8'
163
+ version: '0.10'
138
164
  - - ">="
139
165
  - !ruby/object:Gem::Version
140
- version: 0.8.1
166
+ version: 0.10.0
141
167
  - !ruby/object:Gem::Dependency
142
168
  name: json
143
169
  requirement: !ruby/object:Gem::Requirement
@@ -198,46 +224,6 @@ dependencies:
198
224
  - - ">="
199
225
  - !ruby/object:Gem::Version
200
226
  version: 6.1.0
201
- - !ruby/object:Gem::Dependency
202
- name: mysql2
203
- requirement: !ruby/object:Gem::Requirement
204
- requirements:
205
- - - "~>"
206
- - !ruby/object:Gem::Version
207
- version: '0.5'
208
- - - ">="
209
- - !ruby/object:Gem::Version
210
- version: 0.5.3
211
- type: :runtime
212
- prerelease: false
213
- version_requirements: !ruby/object:Gem::Requirement
214
- requirements:
215
- - - "~>"
216
- - !ruby/object:Gem::Version
217
- version: '0.5'
218
- - - ">="
219
- - !ruby/object:Gem::Version
220
- version: 0.5.3
221
- - !ruby/object:Gem::Dependency
222
- name: sqlite3
223
- requirement: !ruby/object:Gem::Requirement
224
- requirements:
225
- - - "~>"
226
- - !ruby/object:Gem::Version
227
- version: '1.4'
228
- - - ">="
229
- - !ruby/object:Gem::Version
230
- version: 1.4.2
231
- type: :runtime
232
- prerelease: false
233
- version_requirements: !ruby/object:Gem::Requirement
234
- requirements:
235
- - - "~>"
236
- - !ruby/object:Gem::Version
237
- version: '1.4'
238
- - - ">="
239
- - !ruby/object:Gem::Version
240
- version: 1.4.2
241
227
  description: A scripting languge to keep it all together.
242
228
  email:
243
229
  - eric.crane@mac.com
@@ -263,50 +249,11 @@ files:
263
249
  - exe/o
264
250
  - gloo.gemspec
265
251
  - lib/VERSION
252
+ - lib/dependencies.rb
266
253
  - lib/gloo.rb
267
- - lib/gloo/app/args.rb
268
- - lib/gloo/app/engine.rb
269
- - lib/gloo/app/help.rb
270
254
  - lib/gloo/app/info.rb
271
255
  - lib/gloo/app/log.rb
272
- - lib/gloo/app/mode.rb
273
- - lib/gloo/app/settings.rb
274
- - lib/gloo/convert/converter.rb
275
- - lib/gloo/convert/string_to_datetime.rb
276
- - lib/gloo/convert/string_to_decimal.rb
277
- - lib/gloo/convert/string_to_integer.rb
278
- - lib/gloo/core/baseo.rb
279
- - lib/gloo/core/dictionary.rb
280
- - lib/gloo/core/error.rb
281
- - lib/gloo/core/event_manager.rb
282
- - lib/gloo/core/factory.rb
283
- - lib/gloo/core/gloo_system.rb
284
- - lib/gloo/core/heap.rb
285
- - lib/gloo/core/here.rb
286
- - lib/gloo/core/it.rb
287
- - lib/gloo/core/literal.rb
288
- - lib/gloo/core/obj.rb
289
- - lib/gloo/core/obj_finder.rb
290
- - lib/gloo/core/op.rb
291
- - lib/gloo/core/parser.rb
292
- - lib/gloo/core/pn.rb
293
- - lib/gloo/core/tokens.rb
294
- - lib/gloo/core/verb.rb
295
- - lib/gloo/exec/action.rb
296
- - lib/gloo/exec/dispatch.rb
297
- - lib/gloo/exec/exec_env.rb
298
- - lib/gloo/exec/runner.rb
299
- - lib/gloo/exec/script.rb
300
- - lib/gloo/exec/stack.rb
301
- - lib/gloo/expr/expression.rb
302
- - lib/gloo/expr/l_boolean.rb
303
- - lib/gloo/expr/l_decimal.rb
304
- - lib/gloo/expr/l_integer.rb
305
- - lib/gloo/expr/l_string.rb
306
- - lib/gloo/expr/op_div.rb
307
- - lib/gloo/expr/op_minus.rb
308
- - lib/gloo/expr/op_mult.rb
309
- - lib/gloo/expr/op_plus.rb
256
+ - lib/gloo/app/platform.rb
310
257
  - lib/gloo/help/app/application.txt
311
258
  - lib/gloo/help/app/configuration.txt
312
259
  - lib/gloo/help/app/default_help.txt
@@ -382,15 +329,6 @@ files:
382
329
  - lib/gloo/help/verbs/unless.txt
383
330
  - lib/gloo/help/verbs/version.txt
384
331
  - lib/gloo/help/verbs/wait.txt
385
- - lib/gloo/objs/basic/alias.rb
386
- - lib/gloo/objs/basic/boolean.rb
387
- - lib/gloo/objs/basic/container.rb
388
- - lib/gloo/objs/basic/decimal.rb
389
- - lib/gloo/objs/basic/integer.rb
390
- - lib/gloo/objs/basic/script.rb
391
- - lib/gloo/objs/basic/string.rb
392
- - lib/gloo/objs/basic/text.rb
393
- - lib/gloo/objs/basic/untyped.rb
394
332
  - lib/gloo/objs/cli/banner.rb
395
333
  - lib/gloo/objs/cli/bar.rb
396
334
  - lib/gloo/objs/cli/colorize.rb
@@ -400,59 +338,16 @@ files:
400
338
  - lib/gloo/objs/cli/pastel.rb
401
339
  - lib/gloo/objs/cli/prompt.rb
402
340
  - lib/gloo/objs/cli/select.rb
403
- - lib/gloo/objs/ctrl/each.rb
404
- - lib/gloo/objs/ctrl/repeat.rb
405
- - lib/gloo/objs/data/markdown.rb
406
- - lib/gloo/objs/data/mysql.rb
407
- - lib/gloo/objs/data/query.rb
408
- - lib/gloo/objs/data/sqlite.rb
409
- - lib/gloo/objs/data/table.rb
410
341
  - lib/gloo/objs/dev/git.rb
411
342
  - lib/gloo/objs/dev/stats.rb
412
- - lib/gloo/objs/dt/date.rb
413
- - lib/gloo/objs/dt/datetime.rb
414
- - lib/gloo/objs/dt/time.rb
415
- - lib/gloo/objs/ror/erb.rb
416
- - lib/gloo/objs/ror/eval.rb
417
343
  - lib/gloo/objs/snd/play.rb
418
344
  - lib/gloo/objs/snd/say.rb
419
345
  - lib/gloo/objs/system/file_handle.rb
420
346
  - lib/gloo/objs/system/ssh_exec.rb
421
347
  - lib/gloo/objs/system/system.rb
422
- - lib/gloo/objs/web/http_get.rb
423
- - lib/gloo/objs/web/http_post.rb
424
- - lib/gloo/objs/web/json.rb
425
- - lib/gloo/objs/web/slack.rb
426
- - lib/gloo/objs/web/teams.rb
427
- - lib/gloo/objs/web/uri.rb
428
- - lib/gloo/persist/file_loader.rb
429
- - lib/gloo/persist/file_saver.rb
430
- - lib/gloo/persist/file_storage.rb
431
- - lib/gloo/persist/line_splitter.rb
432
- - lib/gloo/persist/persist_man.rb
433
- - lib/gloo/utils/format.rb
434
- - lib/gloo/utils/stats.rb
435
- - lib/gloo/utils/words.rb
436
348
  - lib/gloo/verbs/alert.rb
437
349
  - lib/gloo/verbs/beep.rb
438
350
  - lib/gloo/verbs/cls.rb
439
- - lib/gloo/verbs/context.rb
440
- - lib/gloo/verbs/create.rb
441
- - lib/gloo/verbs/execute.rb
442
- - lib/gloo/verbs/help.rb
443
- - lib/gloo/verbs/if.rb
444
- - lib/gloo/verbs/list.rb
445
- - lib/gloo/verbs/load.rb
446
- - lib/gloo/verbs/move.rb
447
- - lib/gloo/verbs/put.rb
448
- - lib/gloo/verbs/quit.rb
449
- - lib/gloo/verbs/run.rb
450
- - lib/gloo/verbs/save.rb
451
- - lib/gloo/verbs/show.rb
452
- - lib/gloo/verbs/tell.rb
453
- - lib/gloo/verbs/unless.rb
454
- - lib/gloo/verbs/version.rb
455
- - lib/gloo/verbs/wait.rb
456
351
  - lib/run.rb
457
352
  homepage: http://github.com/ecrane/gloo
458
353
  licenses:
data/lib/gloo/app/args.rb DELETED
@@ -1,112 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
- #
4
- # Arguments (parameters) used to specify functionality.
5
- # These might have come from the CLI or as parameters
6
- # in the constructor.
7
- #
8
- require 'active_support'
9
- require 'colorize'
10
-
11
- module Gloo
12
- module App
13
- class Args
14
-
15
- QUIET = 'quiet'.freeze
16
- GLOO_ENV = 'GLOO_ENV'.freeze
17
-
18
- attr_reader :switches, :files
19
-
20
- #
21
- # Create arguments and setup.
22
- #
23
- def initialize( params = [] )
24
- @switches = []
25
- @files = []
26
-
27
- params.each { |o| process_one_arg( o ) }
28
- ARGV.each { |o| process_one_arg( o ) }
29
- end
30
-
31
- #
32
- # Was the --quiet arg passed?
33
- #
34
- def quiet?
35
- return @switches.include?( QUIET )
36
- end
37
-
38
- #
39
- # Is the version switch set?
40
- #
41
- def version?
42
- @switches.include?( Gloo::App::Mode::VERSION.to_s )
43
- end
44
-
45
- #
46
- # Is the help switch set?
47
- #
48
- def help?
49
- @switches.include?( Gloo::App::Mode::HELP.to_s )
50
- end
51
-
52
- #
53
- # Is the cli switch set?
54
- #
55
- def cli?
56
- @switches.include?( Gloo::App::Mode::CLI.to_s )
57
- end
58
-
59
- #
60
- # Is the embed switch set?
61
- #
62
- def embed?
63
- @switches.include?( Gloo::App::Mode::EMBED.to_s )
64
- end
65
-
66
- #
67
- # Detect the mode to be run in.
68
- # Start by seeing if a mode is specified.
69
- # Then look for the presence of files.
70
- # Then finally use the default: embedded mode.
71
- #
72
- def detect_mode
73
- mode = if ENV[ GLOO_ENV ] == Gloo::App::Mode::TEST.to_s
74
- Mode::TEST
75
- elsif version?
76
- Mode::VERSION
77
- elsif help?
78
- Mode::HELP
79
- elsif cli?
80
- Mode::CLI
81
- elsif embed?
82
- Mode::EMBED
83
- elsif @files.count.positive?
84
- Mode::SCRIPT
85
- else
86
- Mode.default_mode
87
- end
88
- $log.debug "running in #{mode} mode"
89
-
90
- return mode
91
- end
92
-
93
- # ---------------------------------------------------------------------
94
- # Private
95
- # ---------------------------------------------------------------------
96
-
97
- private
98
-
99
- #
100
- # Process one argument or parameter.
101
- #
102
- def process_one_arg( arg )
103
- if arg.start_with? '--'
104
- switches << arg[ 2..-1 ]
105
- else
106
- files << arg
107
- end
108
- end
109
-
110
- end
111
- end
112
- end
@@ -1,230 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
- #
4
- # The Gloo Script Engine.
5
- # The Engine aggregates all the elements needed to run gloo.
6
- # The Engine runs the main event loop and delegates processing
7
- # to the relevant element.
8
- #
9
-
10
- require 'tty-prompt'
11
- require 'tty-cursor'
12
- require 'colorize'
13
-
14
- module Gloo
15
- module App
16
- class Engine
17
-
18
- attr_reader :args, :mode, :running,
19
- :dictionary, :parser, :heap, :factory
20
- attr_accessor :last_cmd, :persist_man, :event_manager,
21
- :exec_env, :help, :converter
22
-
23
- #
24
- # Set up the engine with basic elements.
25
- #
26
- def initialize( params = [] )
27
- $engine = self
28
- @args = Args.new( params )
29
- $settings = Settings.new( ENV[ 'GLOO_ENV' ] )
30
- $log = Log.new( @args.quiet? )
31
- $prompt = TTY::Prompt.new
32
- $log.debug 'engine intialized...'
33
- end
34
-
35
- #
36
- # Start the engine.
37
- # Load object and verb definitions and setup engine elements.
38
- #
39
- def start
40
- $log.debug 'starting the engine...'
41
- $log.debug Info.display_title
42
- @mode = @args.detect_mode
43
- @running = true
44
-
45
- @dictionary = Gloo::Core::Dictionary.instance
46
- @dictionary.init
47
- @parser = Gloo::Core::Parser.new
48
- @heap = Gloo::Core::Heap.new
49
- @factory = Gloo::Core::Factory.new
50
- @persist_man = Gloo::Persist::PersistMan.new
51
- @event_manager = Gloo::Core::EventManager.new
52
-
53
- @exec_env = Gloo::Exec::ExecEnv.new
54
- @help = Gloo::App::Help.new
55
- @converter = Gloo::Convert::Converter.new
56
-
57
- $log.debug 'the engine has started'
58
- run_mode
59
- end
60
-
61
- # ---------------------------------------------------------------------
62
- # Run
63
- # ---------------------------------------------------------------------
64
-
65
- #
66
- # Run gloo in the selected mode.
67
- #
68
- def run_mode
69
- $log.debug "running gloo in #{@mode} mode"
70
-
71
- if @mode == Mode::VERSION
72
- run_version
73
- elsif @mode == Mode::HELP
74
- show_help_and_quit
75
- elsif @mode == Mode::SCRIPT
76
- run_files
77
- else
78
- run
79
- end
80
- end
81
-
82
- #
83
- # Run files specified on the CLI.
84
- # Then quit.
85
- #
86
- def run_files
87
- @args.files.each { |f| @persist_man.load( f ) }
88
- quit
89
- end
90
-
91
- #
92
- # Run in interactive mode.
93
- #
94
- def run
95
- # Open default file(s)
96
- self.open_start_file
97
-
98
- # TODO: open any files specifed in args
99
-
100
- unless @mode == Mode::SCRIPT || @args.quiet?
101
- @cursor = TTY::Cursor
102
- self.loop
103
- end
104
-
105
- quit
106
- end
107
-
108
- #
109
- # Get the setting for the start_with file and open it.
110
- #
111
- def open_start_file
112
- name = $settings.start_with
113
- @persist_man.load( name ) if name
114
- end
115
-
116
- #
117
- # Prompt for the next command.
118
- #
119
- def prompt_cmd
120
- @last_cmd = $prompt.ask( default_prompt )
121
- end
122
-
123
- #
124
- # Get the default prompt text.
125
- #
126
- def default_prompt
127
- dt = DateTime.now
128
- d = dt.strftime( '%Y.%m.%d' )
129
- t = dt.strftime( '%I:%M:%S' )
130
- return "#{'gloo'.blue} #{d.yellow} #{t.white} >"
131
- end
132
-
133
- #
134
- # Is the last command entered blank?
135
- #
136
- def last_cmd_blank?
137
- return true if @last_cmd.nil?
138
- return true if @last_cmd.strip.empty?
139
-
140
- return false
141
- end
142
-
143
- #
144
- # Prompt, Get input, process.
145
- #
146
- def loop
147
- while @running
148
- prompt_cmd
149
- process_cmd
150
- end
151
- end
152
-
153
- #
154
- # Process the command.
155
- #
156
- def process_cmd
157
- if last_cmd_blank?
158
- clear_screen
159
- return
160
- end
161
-
162
- @parser.run @last_cmd
163
- end
164
-
165
- #
166
- # Request the engine to stop running.
167
- #
168
- def stop_running
169
- @running = false
170
- end
171
-
172
- #
173
- # Do any clean up and quit.
174
- #
175
- def quit
176
- $log.debug 'quitting...'
177
- end
178
-
179
- # ---------------------------------------------------------------------
180
- # Helpers
181
- # ---------------------------------------------------------------------
182
-
183
- #
184
- # Show the version information and then quit.
185
- #
186
- def run_version
187
- puts Info.display_title unless @args.quiet?
188
- quit
189
- end
190
-
191
- #
192
- # Show the help information and then quit.
193
- #
194
- def show_help_and_quit
195
- @help.show_app_help
196
- quit
197
- end
198
-
199
- #
200
- # Clear the screen.
201
- #
202
- def clear_screen
203
- @cursor ||= TTY::Cursor
204
- print @cursor.clear_screen
205
- print @cursor.move_to( 0, 0 )
206
- end
207
-
208
- # ---------------------------------------------------------------------
209
- # Error Handling
210
- # ---------------------------------------------------------------------
211
-
212
- #
213
- # Did the last command result in an error?
214
- #
215
- def error?
216
- return !@heap.error.value.nil?
217
- end
218
-
219
- #
220
- # Report an error.
221
- # Write it to the log and set the heap error value.
222
- #
223
- def err( msg )
224
- $log.error msg
225
- self.heap.error.set_to msg
226
- end
227
-
228
- end
229
- end
230
- end