gloo-lang 0.9.2 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/gloo-lang.gemspec +1 -0
  4. data/lib/VERSION +1 -1
  5. data/lib/dependencies.rb +2 -2
  6. data/lib/gloo-lang.rb +1 -5
  7. data/lib/gloo_lang/app/args.rb +111 -0
  8. data/lib/gloo_lang/app/engine.rb +200 -0
  9. data/lib/gloo_lang/app/help.rb +117 -0
  10. data/lib/gloo_lang/app/info.rb +34 -0
  11. data/lib/gloo_lang/app/log.rb +81 -0
  12. data/lib/gloo_lang/app/mode.rb +27 -0
  13. data/lib/gloo_lang/app/platform.rb +75 -0
  14. data/lib/gloo_lang/app/settings.rb +185 -0
  15. data/lib/gloo_lang/convert/converter.rb +35 -0
  16. data/lib/gloo_lang/convert/string_to_datetime.rb +21 -0
  17. data/lib/gloo_lang/convert/string_to_decimal.rb +20 -0
  18. data/lib/gloo_lang/convert/string_to_integer.rb +20 -0
  19. data/lib/gloo_lang/core/baseo.rb +30 -0
  20. data/lib/gloo_lang/core/dictionary.rb +181 -0
  21. data/lib/gloo_lang/core/error.rb +61 -0
  22. data/lib/gloo_lang/core/event_manager.rb +44 -0
  23. data/lib/gloo_lang/core/factory.rb +210 -0
  24. data/lib/gloo_lang/core/gloo_system.rb +266 -0
  25. data/lib/gloo_lang/core/heap.rb +52 -0
  26. data/lib/gloo_lang/core/here.rb +36 -0
  27. data/lib/gloo_lang/core/it.rb +36 -0
  28. data/lib/gloo_lang/core/literal.rb +30 -0
  29. data/lib/gloo_lang/core/obj.rb +303 -0
  30. data/lib/gloo_lang/core/obj_finder.rb +30 -0
  31. data/lib/gloo_lang/core/op.rb +40 -0
  32. data/lib/gloo_lang/core/parser.rb +59 -0
  33. data/lib/gloo_lang/core/pn.rb +188 -0
  34. data/lib/gloo_lang/core/tokens.rb +165 -0
  35. data/lib/gloo_lang/core/verb.rb +86 -0
  36. data/lib/gloo_lang/exec/action.rb +48 -0
  37. data/lib/gloo_lang/exec/dispatch.rb +40 -0
  38. data/lib/gloo_lang/exec/exec_env.rb +74 -0
  39. data/lib/gloo_lang/exec/runner.rb +45 -0
  40. data/lib/gloo_lang/exec/script.rb +49 -0
  41. data/lib/gloo_lang/exec/stack.rb +78 -0
  42. data/lib/gloo_lang/expr/expression.rb +118 -0
  43. data/lib/gloo_lang/expr/l_boolean.rb +36 -0
  44. data/lib/gloo_lang/expr/l_decimal.rb +39 -0
  45. data/lib/gloo_lang/expr/l_integer.rb +37 -0
  46. data/lib/gloo_lang/expr/l_string.rb +58 -0
  47. data/lib/gloo_lang/expr/op_div.rb +22 -0
  48. data/lib/gloo_lang/expr/op_minus.rb +22 -0
  49. data/lib/gloo_lang/expr/op_mult.rb +22 -0
  50. data/lib/gloo_lang/expr/op_plus.rb +24 -0
  51. data/lib/gloo_lang/help/app/application.txt +22 -0
  52. data/lib/gloo_lang/help/app/configuration.txt +7 -0
  53. data/lib/gloo_lang/help/app/default_help.txt +14 -0
  54. data/lib/gloo_lang/help/app/logging.txt +16 -0
  55. data/lib/gloo_lang/help/core/color.txt +31 -0
  56. data/lib/gloo_lang/help/core/error.txt +33 -0
  57. data/lib/gloo_lang/help/core/events.txt +21 -0
  58. data/lib/gloo_lang/help/core/gloo_system.txt +57 -0
  59. data/lib/gloo_lang/help/core/here.txt +30 -0
  60. data/lib/gloo_lang/help/core/it.txt +23 -0
  61. data/lib/gloo_lang/help/core/ops.txt +16 -0
  62. data/lib/gloo_lang/help/core/pathname.txt +29 -0
  63. data/lib/gloo_lang/help/objs/basic/alias.txt +36 -0
  64. data/lib/gloo_lang/help/objs/basic/boolean.txt +28 -0
  65. data/lib/gloo_lang/help/objs/basic/container.txt +33 -0
  66. data/lib/gloo_lang/help/objs/basic/decimal.txt +28 -0
  67. data/lib/gloo_lang/help/objs/basic/integer.txt +27 -0
  68. data/lib/gloo_lang/help/objs/basic/script.txt +29 -0
  69. data/lib/gloo_lang/help/objs/basic/string.txt +28 -0
  70. data/lib/gloo_lang/help/objs/basic/text.txt +27 -0
  71. data/lib/gloo_lang/help/objs/basic/untyped.txt +22 -0
  72. data/lib/gloo_lang/help/objs/cli/banner.txt +49 -0
  73. data/lib/gloo_lang/help/objs/cli/bar.txt +37 -0
  74. data/lib/gloo_lang/help/objs/cli/colorize.txt +33 -0
  75. data/lib/gloo_lang/help/objs/cli/confirm.txt +26 -0
  76. data/lib/gloo_lang/help/objs/cli/menu.txt +44 -0
  77. data/lib/gloo_lang/help/objs/cli/menu_item.txt +26 -0
  78. data/lib/gloo_lang/help/objs/cli/pastel.txt +43 -0
  79. data/lib/gloo_lang/help/objs/cli/prompt.txt +27 -0
  80. data/lib/gloo_lang/help/objs/cli/select.txt +34 -0
  81. data/lib/gloo_lang/help/objs/ctrl/each.txt +48 -0
  82. data/lib/gloo_lang/help/objs/ctrl/repeat.txt +38 -0
  83. data/lib/gloo_lang/help/objs/data/markdown.txt +25 -0
  84. data/lib/gloo_lang/help/objs/data/mysql.txt +40 -0
  85. data/lib/gloo_lang/help/objs/data/query.txt +37 -0
  86. data/lib/gloo_lang/help/objs/data/sqlite.txt +26 -0
  87. data/lib/gloo_lang/help/objs/data/table.txt +46 -0
  88. data/lib/gloo_lang/help/objs/dev/git_repo.txt +36 -0
  89. data/lib/gloo_lang/help/objs/dev/stats.txt +36 -0
  90. data/lib/gloo_lang/help/objs/dt/date.txt +23 -0
  91. data/lib/gloo_lang/help/objs/dt/datetime.txt +24 -0
  92. data/lib/gloo_lang/help/objs/dt/time.txt +23 -0
  93. data/lib/gloo_lang/help/objs/ror/erb.txt +37 -0
  94. data/lib/gloo_lang/help/objs/ror/eval.txt +24 -0
  95. data/lib/gloo_lang/help/objs/snd/play.txt +23 -0
  96. data/lib/gloo_lang/help/objs/snd/say.txt +28 -0
  97. data/lib/gloo_lang/help/objs/system/file.txt +48 -0
  98. data/lib/gloo_lang/help/objs/system/ssh_exec.txt +30 -0
  99. data/lib/gloo_lang/help/objs/system/system.txt +32 -0
  100. data/lib/gloo_lang/help/objs/web/http_get.txt +35 -0
  101. data/lib/gloo_lang/help/objs/web/http_post.txt +34 -0
  102. data/lib/gloo_lang/help/objs/web/json.txt +34 -0
  103. data/lib/gloo_lang/help/objs/web/slack.txt +33 -0
  104. data/lib/gloo_lang/help/objs/web/teams.txt +30 -0
  105. data/lib/gloo_lang/help/objs/web/uri.txt +38 -0
  106. data/lib/gloo_lang/help/verbs/alert.txt +33 -0
  107. data/lib/gloo_lang/help/verbs/beep.txt +25 -0
  108. data/lib/gloo_lang/help/verbs/cls.txt +24 -0
  109. data/lib/gloo_lang/help/verbs/context.txt +43 -0
  110. data/lib/gloo_lang/help/verbs/create.txt +33 -0
  111. data/lib/gloo_lang/help/verbs/execute.txt +27 -0
  112. data/lib/gloo_lang/help/verbs/help.txt +34 -0
  113. data/lib/gloo_lang/help/verbs/if.txt +37 -0
  114. data/lib/gloo_lang/help/verbs/list.txt +34 -0
  115. data/lib/gloo_lang/help/verbs/load.txt +38 -0
  116. data/lib/gloo_lang/help/verbs/move.txt +42 -0
  117. data/lib/gloo_lang/help/verbs/put.txt +38 -0
  118. data/lib/gloo_lang/help/verbs/quit.txt +25 -0
  119. data/lib/gloo_lang/help/verbs/run.txt +41 -0
  120. data/lib/gloo_lang/help/verbs/save.txt +26 -0
  121. data/lib/gloo_lang/help/verbs/show.txt +30 -0
  122. data/lib/gloo_lang/help/verbs/tell.txt +34 -0
  123. data/lib/gloo_lang/help/verbs/unless.txt +38 -0
  124. data/lib/gloo_lang/help/verbs/version.txt +32 -0
  125. data/lib/gloo_lang/help/verbs/wait.txt +29 -0
  126. data/lib/gloo_lang/objs/basic/alias.rb +78 -0
  127. data/lib/gloo_lang/objs/basic/boolean.rb +120 -0
  128. data/lib/gloo_lang/objs/basic/container.rb +65 -0
  129. data/lib/gloo_lang/objs/basic/decimal.rb +76 -0
  130. data/lib/gloo_lang/objs/basic/integer.rb +73 -0
  131. data/lib/gloo_lang/objs/basic/script.rb +99 -0
  132. data/lib/gloo_lang/objs/basic/string.rb +77 -0
  133. data/lib/gloo_lang/objs/basic/text.rb +79 -0
  134. data/lib/gloo_lang/objs/basic/untyped.rb +41 -0
  135. data/lib/gloo_lang/objs/ctrl/each.rb +279 -0
  136. data/lib/gloo_lang/objs/ctrl/repeat.rb +108 -0
  137. data/lib/gloo_lang/objs/data/markdown.rb +79 -0
  138. data/lib/gloo_lang/objs/data/mysql.rb +192 -0
  139. data/lib/gloo_lang/objs/data/query.rb +176 -0
  140. data/lib/gloo_lang/objs/data/sqlite.rb +159 -0
  141. data/lib/gloo_lang/objs/data/table.rb +112 -0
  142. data/lib/gloo_lang/objs/dt/date.rb +50 -0
  143. data/lib/gloo_lang/objs/dt/datetime.rb +62 -0
  144. data/lib/gloo_lang/objs/dt/time.rb +50 -0
  145. data/lib/gloo_lang/objs/ror/erb.rb +116 -0
  146. data/lib/gloo_lang/objs/ror/eval.rb +107 -0
  147. data/lib/gloo_lang/objs/web/http_get.rb +159 -0
  148. data/lib/gloo_lang/objs/web/http_post.rb +183 -0
  149. data/lib/gloo_lang/objs/web/json.rb +135 -0
  150. data/lib/gloo_lang/objs/web/slack.rb +130 -0
  151. data/lib/gloo_lang/objs/web/teams.rb +117 -0
  152. data/lib/gloo_lang/objs/web/uri.rb +148 -0
  153. data/lib/gloo_lang/persist/file_loader.rb +191 -0
  154. data/lib/gloo_lang/persist/file_saver.rb +49 -0
  155. data/lib/gloo_lang/persist/file_storage.rb +45 -0
  156. data/lib/gloo_lang/persist/line_splitter.rb +81 -0
  157. data/lib/gloo_lang/persist/persist_man.rb +120 -0
  158. data/lib/gloo_lang/utils/format.rb +21 -0
  159. data/lib/gloo_lang/utils/stats.rb +205 -0
  160. data/lib/gloo_lang/utils/words.rb +19 -0
  161. data/lib/gloo_lang/verbs/context.rb +62 -0
  162. data/lib/gloo_lang/verbs/create.rb +68 -0
  163. data/lib/gloo_lang/verbs/execute.rb +56 -0
  164. data/lib/gloo_lang/verbs/help.rb +264 -0
  165. data/lib/gloo_lang/verbs/if.rb +92 -0
  166. data/lib/gloo_lang/verbs/list.rb +98 -0
  167. data/lib/gloo_lang/verbs/load.rb +45 -0
  168. data/lib/gloo_lang/verbs/move.rb +89 -0
  169. data/lib/gloo_lang/verbs/put.rb +94 -0
  170. data/lib/gloo_lang/verbs/quit.rb +40 -0
  171. data/lib/gloo_lang/verbs/run.rb +75 -0
  172. data/lib/gloo_lang/verbs/save.rb +39 -0
  173. data/lib/gloo_lang/verbs/show.rb +64 -0
  174. data/lib/gloo_lang/verbs/tell.rb +79 -0
  175. data/lib/gloo_lang/verbs/unless.rb +92 -0
  176. data/lib/gloo_lang/verbs/version.rb +37 -0
  177. data/lib/gloo_lang/verbs/wait.rb +42 -0
  178. metadata +192 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8cf5f126ee8c3c4198d6532c443098e3e7943473ea6fe79d70b01bc01b997253
4
- data.tar.gz: e57eae5fcc2d910d576092c740d8c6d0907ef01ecbfd85443cc6277ce26429c3
3
+ metadata.gz: d19934c8b9f0ae7c4b7770b353555c19c4acb4b755775222e14cde8aa1a4bbee
4
+ data.tar.gz: b88f21b0a86cf71b92fcc3fe8c018884109b83293e54db266bb17cef5111e7c0
5
5
  SHA512:
6
- metadata.gz: 10eb7ea0801448637295f4edabdf8a7d5255d4f484ef96d418c5f821116f422f2ad4129a0589cac0b23b9a53309cd683193a1a5a20a88f56c63ab2c542b682e6
7
- data.tar.gz: 19d9f88b7ddf70ef89bc5a722e55f268d84cc8d4bbdaa95e429bd56a4a2d4ba9150a2e93b323876c129d51fd99a23b02df360a52d1461e207f4b8c2414b44459
6
+ metadata.gz: f3475c8c03da31aa4a05feb948b10a89a3b0fae818800ef14329c5028add3e5a788f3a6e7fff7b21c762c53fb67619ffa875dd6586044373110316e78c494480
7
+ data.tar.gz: 27d759c5e86633db59786a3a7db230c4f26c2e54d94a3d339af759983799fd6a4dccb21b84f0dd4cd8de80f1f3a46650c0d3bb283cee246ce95f5cca439ace4e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gloo-lang (0.9.0)
4
+ gloo-lang (0.9.4)
5
5
  chronic (~> 0.10, >= 0.10.2)
6
6
  json (~> 2.1, >= 2.1.0)
7
7
  net-ssh (~> 6.1, >= 6.1.0)
data/gloo-lang.gemspec CHANGED
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_dependency 'json', '~> 2.1', '>= 2.1.0'
33
33
  spec.add_dependency 'openssl', '~> 2.1', '>= 2.1.0'
34
34
  spec.add_dependency 'net-ssh', '~> 6.1', '>= 6.1.0'
35
+ spec.add_dependency 'tty-platform', '~> 0.3', '>= 0.3.0'
35
36
  # spec.add_dependency 'mysql2', '~> 0.5', '>= 0.5.3'
36
37
  # spec.add_dependency 'sqlite3', '~> 1.4', '>= 1.4.2'
37
38
  end
data/lib/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.2
1
+ 0.9.5
data/lib/dependencies.rb CHANGED
@@ -11,8 +11,8 @@ files = []
11
11
  #
12
12
  # We want to start with these to avoid dependency errors later on.
13
13
  #
14
- # files << File.join( path, 'gloo_lang', 'core', 'baseo.rb' )
15
- # files << File.join( path, 'gloo_lang', 'core', 'obj.rb' )
14
+ files << File.join( path, 'gloo_lang', 'core', 'baseo.rb' )
15
+ files << File.join( path, 'gloo_lang', 'core', 'obj.rb' )
16
16
 
17
17
  root = File.join( path, 'gloo_lang', '**/*.rb' )
18
18
  Dir.glob( root ).each do |ruby_file|
data/lib/gloo-lang.rb CHANGED
@@ -9,13 +9,9 @@ path = File.dirname( File.absolute_path( __FILE__ ) )
9
9
  require File.join( path, 'dependencies.rb' )
10
10
 
11
11
  module GlooLang
12
-
13
- ERROR_MSG = 'Error: the gloo_lang gem is not runnable!'.freeze
14
- puts ERROR_MSG
15
-
16
12
  # def self.run
17
13
  # params = []
18
14
  # ( params << '--cli' ) if ARGV.count.zero?
19
- # Gloo::App::Engine.new( params ).start
15
+ # GlooLang::App::Engine.new( params ).start
20
16
  # end
21
17
  end
@@ -0,0 +1,111 @@
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
+
10
+ module GlooLang
11
+ module App
12
+ class Args
13
+
14
+ QUIET = 'quiet'.freeze
15
+ GLOO_ENV = 'GLOO_ENV'.freeze
16
+
17
+ attr_reader :switches, :files
18
+
19
+ #
20
+ # Create arguments and setup.
21
+ #
22
+ def initialize( params = [] )
23
+ @switches = []
24
+ @files = []
25
+
26
+ params.each { |o| process_one_arg( o ) }
27
+ ARGV.each { |o| process_one_arg( o ) }
28
+ end
29
+
30
+ #
31
+ # Was the --quiet arg passed?
32
+ #
33
+ def quiet?
34
+ return @switches.include?( QUIET )
35
+ end
36
+
37
+ #
38
+ # Is the version switch set?
39
+ #
40
+ def version?
41
+ @switches.include?( GlooLang::App::Mode::VERSION.to_s )
42
+ end
43
+
44
+ #
45
+ # Is the help switch set?
46
+ #
47
+ def help?
48
+ @switches.include?( GlooLang::App::Mode::HELP.to_s )
49
+ end
50
+
51
+ #
52
+ # Is the cli switch set?
53
+ #
54
+ def cli?
55
+ @switches.include?( GlooLang::App::Mode::CLI.to_s )
56
+ end
57
+
58
+ #
59
+ # Is the embed switch set?
60
+ #
61
+ def embed?
62
+ @switches.include?( GlooLang::App::Mode::EMBED.to_s )
63
+ end
64
+
65
+ #
66
+ # Detect the mode to be run in.
67
+ # Start by seeing if a mode is specified.
68
+ # Then look for the presence of files.
69
+ # Then finally use the default: embedded mode.
70
+ #
71
+ def detect_mode
72
+ mode = if ENV[ GLOO_ENV ] == GlooLang::App::Mode::TEST.to_s
73
+ Mode::TEST
74
+ elsif version?
75
+ Mode::VERSION
76
+ elsif help?
77
+ Mode::HELP
78
+ elsif cli?
79
+ Mode::CLI
80
+ elsif embed?
81
+ Mode::EMBED
82
+ elsif @files.count.positive?
83
+ Mode::SCRIPT
84
+ else
85
+ Mode.default_mode
86
+ end
87
+ $log.debug "running in #{mode} mode"
88
+
89
+ return mode
90
+ end
91
+
92
+ # ---------------------------------------------------------------------
93
+ # Private
94
+ # ---------------------------------------------------------------------
95
+
96
+ private
97
+
98
+ #
99
+ # Process one argument or parameter.
100
+ #
101
+ def process_one_arg( arg )
102
+ if arg.start_with? '--'
103
+ switches << arg[ 2..-1 ]
104
+ else
105
+ files << arg
106
+ end
107
+ end
108
+
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,200 @@
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
+ module GlooLang
11
+ module App
12
+ class Engine
13
+
14
+ attr_reader :args, :mode, :running, :platform,
15
+ :dictionary, :parser, :heap, :factory
16
+ attr_accessor :last_cmd, :persist_man, :event_manager,
17
+ :exec_env, :help, :converter
18
+
19
+ #
20
+ # Set up the engine with basic elements.
21
+ #
22
+ def initialize( params = [], platform=nil )
23
+ $engine = self
24
+ @args = Args.new( params )
25
+ $settings = Settings.new( ENV[ 'GLOO_ENV' ] )
26
+ $log = Log.new( @args.quiet? )
27
+ @platform = platform ? platform : Platform.new
28
+ $log.debug 'engine intialized...'
29
+ end
30
+
31
+ #
32
+ # Start the engine.
33
+ # Load object and verb definitions and setup engine elements.
34
+ #
35
+ def start
36
+ $log.debug 'starting the engine...'
37
+ $log.debug Info.display_title
38
+ @mode = @args.detect_mode
39
+ @running = true
40
+
41
+ @dictionary = GlooLang::Core::Dictionary.instance
42
+ @dictionary.init
43
+ @parser = GlooLang::Core::Parser.new
44
+ @heap = GlooLang::Core::Heap.new
45
+ @factory = GlooLang::Core::Factory.new
46
+ @persist_man = GlooLang::Persist::PersistMan.new
47
+ @event_manager = GlooLang::Core::EventManager.new
48
+
49
+ @exec_env = GlooLang::Exec::ExecEnv.new
50
+ @help = GlooLang::App::Help.new
51
+ @converter = GlooLang::Convert::Converter.new
52
+
53
+ $log.debug 'the engine has started'
54
+ run_mode
55
+ end
56
+
57
+ # ---------------------------------------------------------------------
58
+ # Run
59
+ # ---------------------------------------------------------------------
60
+
61
+ #
62
+ # Run gloo in the selected mode.
63
+ #
64
+ def run_mode
65
+ $log.debug "running gloo in #{@mode} mode"
66
+
67
+ if @mode == Mode::VERSION
68
+ run_version
69
+ elsif @mode == Mode::HELP
70
+ show_help_and_quit
71
+ elsif @mode == Mode::SCRIPT
72
+ run_files
73
+ else
74
+ run
75
+ end
76
+ end
77
+
78
+ #
79
+ # Run files specified on the CLI.
80
+ # Then quit.
81
+ #
82
+ def run_files
83
+ @args.files.each { |f| @persist_man.load( f ) }
84
+ quit
85
+ end
86
+
87
+ #
88
+ # Run in interactive mode.
89
+ #
90
+ def run
91
+ # Open default file(s)
92
+ self.open_start_file
93
+
94
+ # TODO: open any files specifed in args
95
+
96
+ unless @mode == Mode::SCRIPT || @args.quiet?
97
+ @cursor = TTY::Cursor
98
+ self.loop
99
+ end
100
+
101
+ quit
102
+ end
103
+
104
+ #
105
+ # Get the setting for the start_with file and open it.
106
+ #
107
+ def open_start_file
108
+ name = $settings.start_with
109
+ @persist_man.load( name ) if name
110
+ end
111
+
112
+ #
113
+ # Is the last command entered blank?
114
+ #
115
+ def last_cmd_blank?
116
+ return true if @last_cmd.nil?
117
+ return true if @last_cmd.strip.empty?
118
+
119
+ return false
120
+ end
121
+
122
+ #
123
+ # Prompt, Get input, process.
124
+ #
125
+ def loop
126
+ while @running
127
+ @last_cmd = @platform.prompt_cmd
128
+ process_cmd
129
+ end
130
+ end
131
+
132
+ #
133
+ # Process the command.
134
+ #
135
+ def process_cmd
136
+ if last_cmd_blank?
137
+ @platform.clear_screen
138
+ return
139
+ end
140
+
141
+ @parser.run @last_cmd
142
+ end
143
+
144
+ #
145
+ # Request the engine to stop running.
146
+ #
147
+ def stop_running
148
+ @running = false
149
+ end
150
+
151
+ #
152
+ # Do any clean up and quit.
153
+ #
154
+ def quit
155
+ $log.debug 'quitting...'
156
+ end
157
+
158
+ # ---------------------------------------------------------------------
159
+ # Helpers
160
+ # ---------------------------------------------------------------------
161
+
162
+ #
163
+ # Show the version information and then quit.
164
+ #
165
+ def run_version
166
+ @platform.show Info.display_title unless @args.quiet?
167
+ quit
168
+ end
169
+
170
+ #
171
+ # Show the help information and then quit.
172
+ #
173
+ def show_help_and_quit
174
+ @help.show_app_help
175
+ quit
176
+ end
177
+
178
+ # ---------------------------------------------------------------------
179
+ # Error Handling
180
+ # ---------------------------------------------------------------------
181
+
182
+ #
183
+ # Did the last command result in an error?
184
+ #
185
+ def error?
186
+ return !@heap.error.value.nil?
187
+ end
188
+
189
+ #
190
+ # Report an error.
191
+ # Write it to the log and set the heap error value.
192
+ #
193
+ def err( msg )
194
+ $log.error msg
195
+ self.heap.error.set_to msg
196
+ end
197
+
198
+ end
199
+ end
200
+ end
@@ -0,0 +1,117 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Help system.
5
+ #
6
+
7
+ module GlooLang
8
+ module App
9
+ class Help
10
+
11
+ APPLICATION = 'application'.freeze
12
+
13
+ attr_accessor :topics
14
+
15
+ #
16
+ # Set up the help system.
17
+ # We won't load help topics until we know we need them.
18
+ #
19
+ def initialize
20
+ @topics = nil
21
+ end
22
+
23
+ #
24
+ # Show application help.
25
+ # This is the what is shown when help is run from the CLI.
26
+ #
27
+ def show_app_help
28
+ puts Info.display_title unless $engine.args.quiet?
29
+ self.show_topic APPLICATION
30
+ end
31
+
32
+ #
33
+ # Check to see if there is a topic by the given name.
34
+ #
35
+ def topic?( name )
36
+ lazy_load_index
37
+
38
+ return @topics.key?( name )
39
+ end
40
+
41
+ #
42
+ # Is the current topic Markdown?
43
+ #
44
+ def topic_is_md?( name )
45
+ lazy_load_index
46
+
47
+ topic_file = @topics[ name ]
48
+ return topic_file.end_with? '.md'
49
+ end
50
+
51
+ #
52
+ # Show a help topic, optionally paginaged.
53
+ # If the content of the help page fits on a single
54
+ # screen, it won't paginate.
55
+ #
56
+ def page_topic( topic )
57
+ return if $engine.args.quiet?
58
+
59
+ data = self.get_topic_data( topic )
60
+ page = data.lines.count > Settings.page_size
61
+ $engine.platform.show( data, topic_is_md?( topic ), page )
62
+ end
63
+
64
+ #
65
+ # Show a help topic.
66
+ #
67
+ def show_topic( topic )
68
+ return if $engine.args.quiet?
69
+
70
+ data = self.get_topic_data( topic )
71
+ $engine.platform.show( data, topic_is_md?( topic ), false )
72
+ end
73
+
74
+ #
75
+ # Get topic data.
76
+ #
77
+ def get_topic_data( topic )
78
+ lazy_load_index
79
+
80
+ topic_file = @topics[ topic ]
81
+ return nil unless topic_file
82
+
83
+ File.read topic_file
84
+ end
85
+
86
+ #
87
+ # Lazy load topic index.
88
+ # We'll only load the index the first time a help topic
89
+ # is requested. After that we'll use the cached index.
90
+ #
91
+ def lazy_load_index
92
+ return if @topics
93
+
94
+ @topics = {}
95
+ $log.debug 'loading help file index...'
96
+
97
+ pn = File.dirname( File.absolute_path( __FILE__ ) )
98
+ pn = File.dirname( pn )
99
+
100
+ root = File.join( pn, 'help', '**/*.txt' )
101
+ Dir.glob( root ).each do |txt_file|
102
+ key = File.basename( txt_file, '.txt' )
103
+ @topics[ key ] = txt_file
104
+ end
105
+
106
+ root = File.join( pn, 'help', '**/*.md' )
107
+ Dir.glob( root ).each do |md_file|
108
+ key = File.basename( md_file, '.md' )
109
+ @topics[ key ] = md_file
110
+ end
111
+
112
+ $log.debug "Found #{@topics.count} help files"
113
+ end
114
+
115
+ end
116
+ end
117
+ end
@@ -8,6 +8,14 @@ module GlooLang
8
8
  module App
9
9
  class Info
10
10
 
11
+ #
12
+ # Register other Info classes when they are loaded.
13
+ #
14
+ def self.inherited( subclass )
15
+ $infos = [] unless $infos
16
+ $infos << subclass
17
+ end
18
+
11
19
  #
12
20
  # Load the version from the VERSION file.
13
21
  #
@@ -28,6 +36,32 @@ module GlooLang
28
36
  return "#{APP_NAME}, version #{VERSION}"
29
37
  end
30
38
 
39
+ #
40
+ # Get the full application version information,
41
+ # including engine version.
42
+ #
43
+ def self.full_version
44
+ str = "#{display_title}"
45
+ if $infos
46
+ $infos.each do |o|
47
+ str << "\n#{o.display_title}"
48
+ end
49
+ end
50
+ return str
51
+ end
52
+
31
53
  end
54
+
55
+ #
56
+ # Add the ruby version information.
57
+ #
58
+ class RubyInfo < Info
59
+
60
+ def self.display_title
61
+ return "Ruby version: #{RUBY_VERSION}"
62
+ end
63
+
64
+ end
65
+
32
66
  end
33
67
  end
@@ -0,0 +1,81 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Application Logging wrapper.
5
+ #
6
+ require 'active_support'
7
+ require 'colorize'
8
+ require 'colorized_string'
9
+
10
+ module GlooLang
11
+ module App
12
+ class Log
13
+
14
+ attr_reader :logger, :quiet
15
+
16
+ #
17
+ # Set up a logger.
18
+ # If quiet is true, then message are written to the log
19
+ # but not to the console.
20
+ #
21
+ def initialize( quiet )
22
+ f = File.join( $settings.log_path, 'gloo.log' )
23
+ @logger = Logger.new( f )
24
+ @logger.level = Logger::DEBUG
25
+ @quiet = quiet
26
+ end
27
+
28
+ #
29
+ # Show a message unless we're in quite mode.
30
+ #
31
+ def show( msg )
32
+ puts msg unless @quiet
33
+ end
34
+
35
+ #
36
+ # Write a debug message to the log.
37
+ #
38
+ def debug( msg )
39
+ @logger.debug msg
40
+ end
41
+
42
+ #
43
+ # Write an information message to the log.
44
+ # Also write to the console unless quiet.
45
+ #
46
+ def info( msg )
47
+ @logger.info msg
48
+ puts msg.blue unless @quiet
49
+ end
50
+
51
+ #
52
+ # Write a warning message to the log.
53
+ # Also write to the console unless quiet.
54
+ #
55
+ def warn( msg )
56
+ @logger.warn msg
57
+ puts msg.yellow unless @quiet
58
+ end
59
+
60
+ #
61
+ # Write an error message to the log and set the error
62
+ # in the engine's data heap.
63
+ # Also write to the console unless quiet.
64
+ #
65
+ def error( msg, ex = nil, engine = nil )
66
+ engine&.heap&.error&.set_to msg
67
+ @logger.error msg
68
+ if ex
69
+ @logger.error ex.message
70
+ @logger.error ex.backtrace
71
+ puts msg.red unless @quiet
72
+ puts ex.message.red unless @quiet
73
+ puts ex.backtrace unless @quiet
74
+ else
75
+ puts msg.red unless @quiet
76
+ end
77
+ end
78
+
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,27 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Mode the Application is running in.
5
+ #
6
+
7
+ module GlooLang
8
+ module App
9
+ class Mode
10
+
11
+ EMBED = :embed # Run as embedded script processor
12
+ CLI = :cli # Run in interactive (CLI) mode
13
+ SCRIPT = :script # Run a script
14
+ VERSION = :version # Show version information
15
+ HELP = :help # Show the help screen
16
+ TEST = :test # Running in Unit Test mode.
17
+
18
+ #
19
+ # Get the default mode.
20
+ #
21
+ def self.default_mode
22
+ return EMBED
23
+ end
24
+
25
+ end
26
+ end
27
+ end