gloo-lang 0.9.0 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +4 -4
  2. data/lib/VERSION +1 -1
  3. data/lib/dependencies.rb +2 -2
  4. data/lib/{gloo_lang.rb → gloo-lang.rb} +7 -9
  5. data/lib/gloo_lang/app/args.rb +112 -0
  6. data/lib/gloo_lang/app/engine.rb +230 -0
  7. data/lib/gloo_lang/app/help.rb +156 -0
  8. data/lib/gloo_lang/app/log.rb +81 -0
  9. data/lib/gloo_lang/app/mode.rb +27 -0
  10. data/lib/gloo_lang/app/settings.rb +186 -0
  11. data/lib/gloo_lang/convert/converter.rb +35 -0
  12. data/lib/gloo_lang/convert/string_to_datetime.rb +21 -0
  13. data/lib/gloo_lang/convert/string_to_decimal.rb +20 -0
  14. data/lib/gloo_lang/convert/string_to_integer.rb +20 -0
  15. data/lib/gloo_lang/core/baseo.rb +30 -0
  16. data/lib/gloo_lang/core/dictionary.rb +181 -0
  17. data/lib/gloo_lang/core/error.rb +61 -0
  18. data/lib/gloo_lang/core/event_manager.rb +44 -0
  19. data/lib/gloo_lang/core/factory.rb +210 -0
  20. data/lib/gloo_lang/core/gloo_system.rb +266 -0
  21. data/lib/gloo_lang/core/heap.rb +52 -0
  22. data/lib/gloo_lang/core/here.rb +36 -0
  23. data/lib/gloo_lang/core/it.rb +36 -0
  24. data/lib/gloo_lang/core/literal.rb +30 -0
  25. data/lib/gloo_lang/core/obj.rb +303 -0
  26. data/lib/gloo_lang/core/obj_finder.rb +30 -0
  27. data/lib/gloo_lang/core/op.rb +40 -0
  28. data/lib/gloo_lang/core/parser.rb +59 -0
  29. data/lib/gloo_lang/core/pn.rb +188 -0
  30. data/lib/gloo_lang/core/tokens.rb +165 -0
  31. data/lib/gloo_lang/core/verb.rb +86 -0
  32. data/lib/gloo_lang/exec/action.rb +48 -0
  33. data/lib/gloo_lang/exec/dispatch.rb +40 -0
  34. data/lib/gloo_lang/exec/exec_env.rb +74 -0
  35. data/lib/gloo_lang/exec/runner.rb +45 -0
  36. data/lib/gloo_lang/exec/script.rb +49 -0
  37. data/lib/gloo_lang/exec/stack.rb +78 -0
  38. data/lib/gloo_lang/expr/expression.rb +118 -0
  39. data/lib/gloo_lang/expr/l_boolean.rb +36 -0
  40. data/lib/gloo_lang/expr/l_decimal.rb +39 -0
  41. data/lib/gloo_lang/expr/l_integer.rb +37 -0
  42. data/lib/gloo_lang/expr/l_string.rb +58 -0
  43. data/lib/gloo_lang/expr/op_div.rb +22 -0
  44. data/lib/gloo_lang/expr/op_minus.rb +22 -0
  45. data/lib/gloo_lang/expr/op_mult.rb +22 -0
  46. data/lib/gloo_lang/expr/op_plus.rb +24 -0
  47. data/lib/gloo_lang/help/app/application.txt +22 -0
  48. data/lib/gloo_lang/help/app/configuration.txt +7 -0
  49. data/lib/gloo_lang/help/app/default_help.txt +14 -0
  50. data/lib/gloo_lang/help/app/logging.txt +16 -0
  51. data/lib/gloo_lang/help/core/color.txt +31 -0
  52. data/lib/gloo_lang/help/core/error.txt +33 -0
  53. data/lib/gloo_lang/help/core/events.txt +21 -0
  54. data/lib/gloo_lang/help/core/gloo_system.txt +57 -0
  55. data/lib/gloo_lang/help/core/here.txt +30 -0
  56. data/lib/gloo_lang/help/core/it.txt +23 -0
  57. data/lib/gloo_lang/help/core/ops.txt +16 -0
  58. data/lib/gloo_lang/help/core/pathname.txt +29 -0
  59. data/lib/gloo_lang/help/objs/basic/alias.txt +36 -0
  60. data/lib/gloo_lang/help/objs/basic/boolean.txt +28 -0
  61. data/lib/gloo_lang/help/objs/basic/container.txt +33 -0
  62. data/lib/gloo_lang/help/objs/basic/decimal.txt +28 -0
  63. data/lib/gloo_lang/help/objs/basic/integer.txt +27 -0
  64. data/lib/gloo_lang/help/objs/basic/script.txt +29 -0
  65. data/lib/gloo_lang/help/objs/basic/string.txt +28 -0
  66. data/lib/gloo_lang/help/objs/basic/text.txt +27 -0
  67. data/lib/gloo_lang/help/objs/basic/untyped.txt +22 -0
  68. data/lib/gloo_lang/help/objs/cli/banner.txt +49 -0
  69. data/lib/gloo_lang/help/objs/cli/bar.txt +37 -0
  70. data/lib/gloo_lang/help/objs/cli/colorize.txt +33 -0
  71. data/lib/gloo_lang/help/objs/cli/confirm.txt +26 -0
  72. data/lib/gloo_lang/help/objs/cli/menu.txt +44 -0
  73. data/lib/gloo_lang/help/objs/cli/menu_item.txt +26 -0
  74. data/lib/gloo_lang/help/objs/cli/pastel.txt +43 -0
  75. data/lib/gloo_lang/help/objs/cli/prompt.txt +27 -0
  76. data/lib/gloo_lang/help/objs/cli/select.txt +34 -0
  77. data/lib/gloo_lang/help/objs/ctrl/each.txt +48 -0
  78. data/lib/gloo_lang/help/objs/ctrl/repeat.txt +38 -0
  79. data/lib/gloo_lang/help/objs/data/markdown.txt +25 -0
  80. data/lib/gloo_lang/help/objs/data/mysql.txt +40 -0
  81. data/lib/gloo_lang/help/objs/data/query.txt +37 -0
  82. data/lib/gloo_lang/help/objs/data/sqlite.txt +26 -0
  83. data/lib/gloo_lang/help/objs/data/table.txt +46 -0
  84. data/lib/gloo_lang/help/objs/dev/git_repo.txt +36 -0
  85. data/lib/gloo_lang/help/objs/dev/stats.txt +36 -0
  86. data/lib/gloo_lang/help/objs/dt/date.txt +23 -0
  87. data/lib/gloo_lang/help/objs/dt/datetime.txt +24 -0
  88. data/lib/gloo_lang/help/objs/dt/time.txt +23 -0
  89. data/lib/gloo_lang/help/objs/ror/erb.txt +37 -0
  90. data/lib/gloo_lang/help/objs/ror/eval.txt +24 -0
  91. data/lib/gloo_lang/help/objs/snd/play.txt +23 -0
  92. data/lib/gloo_lang/help/objs/snd/say.txt +28 -0
  93. data/lib/gloo_lang/help/objs/system/file.txt +48 -0
  94. data/lib/gloo_lang/help/objs/system/ssh_exec.txt +30 -0
  95. data/lib/gloo_lang/help/objs/system/system.txt +32 -0
  96. data/lib/gloo_lang/help/objs/web/http_get.txt +35 -0
  97. data/lib/gloo_lang/help/objs/web/http_post.txt +34 -0
  98. data/lib/gloo_lang/help/objs/web/json.txt +34 -0
  99. data/lib/gloo_lang/help/objs/web/slack.txt +33 -0
  100. data/lib/gloo_lang/help/objs/web/teams.txt +30 -0
  101. data/lib/gloo_lang/help/objs/web/uri.txt +38 -0
  102. data/lib/gloo_lang/help/verbs/alert.txt +33 -0
  103. data/lib/gloo_lang/help/verbs/beep.txt +25 -0
  104. data/lib/gloo_lang/help/verbs/cls.txt +24 -0
  105. data/lib/gloo_lang/help/verbs/context.txt +43 -0
  106. data/lib/gloo_lang/help/verbs/create.txt +33 -0
  107. data/lib/gloo_lang/help/verbs/execute.txt +27 -0
  108. data/lib/gloo_lang/help/verbs/help.txt +34 -0
  109. data/lib/gloo_lang/help/verbs/if.txt +37 -0
  110. data/lib/gloo_lang/help/verbs/list.txt +34 -0
  111. data/lib/gloo_lang/help/verbs/load.txt +38 -0
  112. data/lib/gloo_lang/help/verbs/move.txt +42 -0
  113. data/lib/gloo_lang/help/verbs/put.txt +38 -0
  114. data/lib/gloo_lang/help/verbs/quit.txt +25 -0
  115. data/lib/gloo_lang/help/verbs/run.txt +41 -0
  116. data/lib/gloo_lang/help/verbs/save.txt +26 -0
  117. data/lib/gloo_lang/help/verbs/show.txt +30 -0
  118. data/lib/gloo_lang/help/verbs/tell.txt +34 -0
  119. data/lib/gloo_lang/help/verbs/unless.txt +38 -0
  120. data/lib/gloo_lang/help/verbs/version.txt +32 -0
  121. data/lib/gloo_lang/help/verbs/wait.txt +29 -0
  122. data/lib/gloo_lang/objs/basic/alias.rb +78 -0
  123. data/lib/gloo_lang/objs/basic/boolean.rb +120 -0
  124. data/lib/gloo_lang/objs/basic/container.rb +76 -0
  125. data/lib/gloo_lang/objs/basic/decimal.rb +76 -0
  126. data/lib/gloo_lang/objs/basic/integer.rb +73 -0
  127. data/lib/gloo_lang/objs/basic/script.rb +99 -0
  128. data/lib/gloo_lang/objs/basic/string.rb +77 -0
  129. data/lib/gloo_lang/objs/basic/text.rb +87 -0
  130. data/lib/gloo_lang/objs/basic/untyped.rb +41 -0
  131. data/lib/gloo_lang/objs/cli/banner.rb +108 -0
  132. data/lib/gloo_lang/objs/cli/bar.rb +133 -0
  133. data/lib/gloo_lang/objs/cli/colorize.rb +73 -0
  134. data/lib/gloo_lang/objs/cli/confirm.rb +96 -0
  135. data/lib/gloo_lang/objs/cli/menu.rb +206 -0
  136. data/lib/gloo_lang/objs/cli/menu_item.rb +95 -0
  137. data/lib/gloo_lang/objs/cli/pastel.rb +97 -0
  138. data/lib/gloo_lang/objs/cli/prompt.rb +110 -0
  139. data/lib/gloo_lang/objs/cli/select.rb +126 -0
  140. data/lib/gloo_lang/objs/ctrl/each.rb +279 -0
  141. data/lib/gloo_lang/objs/ctrl/repeat.rb +108 -0
  142. data/lib/gloo_lang/objs/data/markdown.rb +84 -0
  143. data/lib/gloo_lang/objs/data/mysql.rb +192 -0
  144. data/lib/gloo_lang/objs/data/query.rb +176 -0
  145. data/lib/gloo_lang/objs/data/sqlite.rb +159 -0
  146. data/lib/gloo_lang/objs/data/table.rb +140 -0
  147. data/lib/gloo_lang/objs/dev/git.rb +140 -0
  148. data/lib/gloo_lang/objs/dev/stats.rb +120 -0
  149. data/lib/gloo_lang/objs/dt/date.rb +50 -0
  150. data/lib/gloo_lang/objs/dt/datetime.rb +62 -0
  151. data/lib/gloo_lang/objs/dt/time.rb +50 -0
  152. data/lib/gloo_lang/objs/ror/erb.rb +116 -0
  153. data/lib/gloo_lang/objs/ror/eval.rb +107 -0
  154. data/lib/gloo_lang/objs/snd/play.rb +48 -0
  155. data/lib/gloo_lang/objs/snd/say.rb +98 -0
  156. data/lib/gloo_lang/objs/system/file_handle.rb +138 -0
  157. data/lib/gloo_lang/objs/system/ssh_exec.rb +126 -0
  158. data/lib/gloo_lang/objs/system/system.rb +136 -0
  159. data/lib/gloo_lang/objs/web/http_get.rb +159 -0
  160. data/lib/gloo_lang/objs/web/http_post.rb +183 -0
  161. data/lib/gloo_lang/objs/web/json.rb +135 -0
  162. data/lib/gloo_lang/objs/web/slack.rb +130 -0
  163. data/lib/gloo_lang/objs/web/teams.rb +117 -0
  164. data/lib/gloo_lang/objs/web/uri.rb +148 -0
  165. data/lib/gloo_lang/persist/file_loader.rb +191 -0
  166. data/lib/gloo_lang/persist/file_saver.rb +49 -0
  167. data/lib/gloo_lang/persist/file_storage.rb +45 -0
  168. data/lib/gloo_lang/persist/line_splitter.rb +81 -0
  169. data/lib/gloo_lang/persist/persist_man.rb +120 -0
  170. data/lib/gloo_lang/utils/format.rb +21 -0
  171. data/lib/gloo_lang/utils/stats.rb +205 -0
  172. data/lib/gloo_lang/utils/words.rb +19 -0
  173. data/lib/gloo_lang/verbs/alert.rb +79 -0
  174. data/lib/gloo_lang/verbs/beep.rb +40 -0
  175. data/lib/gloo_lang/verbs/cls.rb +37 -0
  176. data/lib/gloo_lang/verbs/context.rb +62 -0
  177. data/lib/gloo_lang/verbs/create.rb +68 -0
  178. data/lib/gloo_lang/verbs/execute.rb +56 -0
  179. data/lib/gloo_lang/verbs/help.rb +264 -0
  180. data/lib/gloo_lang/verbs/if.rb +92 -0
  181. data/lib/gloo_lang/verbs/list.rb +98 -0
  182. data/lib/gloo_lang/verbs/load.rb +45 -0
  183. data/lib/gloo_lang/verbs/move.rb +89 -0
  184. data/lib/gloo_lang/verbs/put.rb +94 -0
  185. data/lib/gloo_lang/verbs/quit.rb +40 -0
  186. data/lib/gloo_lang/verbs/run.rb +75 -0
  187. data/lib/gloo_lang/verbs/save.rb +39 -0
  188. data/lib/gloo_lang/verbs/show.rb +64 -0
  189. data/lib/gloo_lang/verbs/tell.rb +79 -0
  190. data/lib/gloo_lang/verbs/unless.rb +92 -0
  191. data/lib/gloo_lang/verbs/version.rb +37 -0
  192. data/lib/gloo_lang/verbs/wait.rb +42 -0
  193. metadata +191 -3
@@ -0,0 +1,107 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An object that evaluate a ruby statement.
5
+ #
6
+
7
+ module GlooLang
8
+ module Objs
9
+ class Eval < GlooLang::Core::Obj
10
+
11
+ KEYWORD = 'eval'.freeze
12
+ KEYWORD_SHORT = 'ruby'.freeze
13
+ CMD = 'command'.freeze
14
+ DEFAULT_CMD = '1+2'.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 cmd_value
36
+ cmd = find_child CMD
37
+ return nil unless cmd
38
+
39
+ return cmd.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
+ #
57
+ # Does this object have children to add when an object
58
+ # is created in interactive mode?
59
+ # This does not apply during obj load, etc.
60
+ #
61
+ def add_children_on_create?
62
+ return true
63
+ end
64
+
65
+ #
66
+ # Add children to this object.
67
+ # This is used by containers to add children needed
68
+ # for default configurations.
69
+ #
70
+ def add_default_children
71
+ fac = $engine.factory
72
+ fac.create_string CMD, DEFAULT_CMD, self
73
+ fac.create_string RESULT, nil, self
74
+ end
75
+
76
+ # ---------------------------------------------------------------------
77
+ # Messages
78
+ # ---------------------------------------------------------------------
79
+
80
+ #
81
+ # Get a list of message names that this object receives.
82
+ #
83
+ def self.messages
84
+ return super + [ 'run' ]
85
+ end
86
+
87
+ #
88
+ # Run the command and evaluate the expression.
89
+ #
90
+ def msg_run
91
+ cmd = cmd_value
92
+ return unless cmd
93
+
94
+ begin
95
+ # rubocop:disable Security/Eval
96
+ result = eval cmd
97
+ # rubocop:enable Security/Eval
98
+ set_result result
99
+ $engine.heap.it.set_to result
100
+ rescue => e
101
+ $engine.err e.message
102
+ end
103
+ end
104
+
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,48 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Play an audio file (MP3).
5
+ #
6
+
7
+ module GlooLang
8
+ module Objs
9
+ class Play < GlooLang::Core::Obj
10
+
11
+ KEYWORD = 'play'.freeze
12
+ KEYWORD_SHORT = 'play'.freeze
13
+
14
+ #
15
+ # The name of the object type.
16
+ #
17
+ def self.typename
18
+ return KEYWORD
19
+ end
20
+
21
+ #
22
+ # The short name of the object type.
23
+ #
24
+ def self.short_typename
25
+ return KEYWORD_SHORT
26
+ end
27
+
28
+ # ---------------------------------------------------------------------
29
+ # Messages
30
+ # ---------------------------------------------------------------------
31
+
32
+ #
33
+ # Get a list of message names that this object receives.
34
+ #
35
+ def self.messages
36
+ return super + [ 'run' ]
37
+ end
38
+
39
+ #
40
+ # Play the audio file.
41
+ #
42
+ def msg_run
43
+ system "afplay #{value}"
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,98 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Wrapper for the 'say something' function on the Mac.
5
+ #
6
+ require 'erb'
7
+
8
+ module GlooLang
9
+ module Objs
10
+ class Say < GlooLang::Core::Obj
11
+
12
+ KEYWORD = 'say'.freeze
13
+ KEYWORD_SHORT = 'say'.freeze
14
+ VOICE = 'voice'.freeze
15
+ MSG = 'message'.freeze
16
+ DEFAULT_MSG = 'talk to me'.freeze
17
+
18
+ #
19
+ # The name of the object type.
20
+ #
21
+ def self.typename
22
+ return KEYWORD
23
+ end
24
+
25
+ #
26
+ # The short name of the object type.
27
+ #
28
+ def self.short_typename
29
+ return KEYWORD_SHORT
30
+ end
31
+
32
+ #
33
+ # Get the voice to use.
34
+ #
35
+ def voice_value
36
+ v = find_child VOICE
37
+ return nil unless v
38
+
39
+ return v.value
40
+ end
41
+
42
+ #
43
+ # Get the message to speak.
44
+ #
45
+ def msg_value
46
+ o = find_child MSG
47
+ return nil unless o
48
+
49
+ return o.value
50
+ end
51
+
52
+ # ---------------------------------------------------------------------
53
+ # Children
54
+ # ---------------------------------------------------------------------
55
+
56
+ #
57
+ # Does this object have children to add when an object
58
+ # is created in interactive mode?
59
+ # This does not apply during obj load, etc.
60
+ #
61
+ def add_children_on_create?
62
+ return true
63
+ end
64
+
65
+ #
66
+ # Add children to this object.
67
+ # This is used by containers to add children needed
68
+ # for default configurations.
69
+ #
70
+ def add_default_children
71
+ fac = $engine.factory
72
+ fac.create_string VOICE, '', self
73
+ fac.create_string MSG, DEFAULT_MSG, self
74
+ end
75
+
76
+ # ---------------------------------------------------------------------
77
+ # Messages
78
+ # ---------------------------------------------------------------------
79
+
80
+ #
81
+ # Get a list of message names that this object receives.
82
+ #
83
+ def self.messages
84
+ return super + [ 'run' ]
85
+ end
86
+
87
+ #
88
+ # Have the computer 'speak' the message.
89
+ #
90
+ def msg_run
91
+ v = voice_value.empty? ? '' : "-v '#{voice_value}'"
92
+ cmd = "say #{v} '#{msg_value}'"
93
+ system cmd
94
+ end
95
+
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,138 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An object that points to a file in the system.
5
+ #
6
+ require 'tty-pager'
7
+
8
+ module GlooLang
9
+ module Objs
10
+ class FileHandle < GlooLang::Core::Obj
11
+
12
+ KEYWORD = 'file'.freeze
13
+ KEYWORD_SHORT = 'dir'.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
+ # Messages
31
+ # ---------------------------------------------------------------------
32
+
33
+ #
34
+ # Get a list of message names that this object receives.
35
+ #
36
+ def self.messages
37
+ basic = %w[read write]
38
+ checks = %w[check_exists check_is_file check_is_dir]
39
+ search = %w[find_match]
40
+ show = %w[show page open]
41
+ return super + basic + show + checks + search
42
+ end
43
+
44
+ #
45
+ # Open the file in the default application for the file type.
46
+ #
47
+ def msg_open
48
+ return unless value && File.exist?( value )
49
+
50
+ cmd = GlooLang::Core::GlooSystem.open_for_platform
51
+ cmd_with_param = "#{cmd} \"#{value}\""
52
+ `#{cmd_with_param}`
53
+ end
54
+
55
+ #
56
+ # Show the contents of the file, paginated.
57
+ #
58
+ def msg_page
59
+ return unless value && File.file?( value )
60
+
61
+ pager = TTY::Pager.new
62
+ pager.page( path: value )
63
+ end
64
+
65
+ #
66
+ # Show the contents of the file.
67
+ #
68
+ def msg_show
69
+ return unless value && File.file?( value )
70
+
71
+ puts File.read( value )
72
+ end
73
+
74
+ #
75
+ # Read the contents of the file into the object.
76
+ #
77
+ def msg_read
78
+ return unless value && File.file?( value )
79
+
80
+ data = File.read( value )
81
+ if @params&.token_count&.positive?
82
+ pn = GlooLang::Core::Pn.new @params.first
83
+ o = pn.resolve
84
+ o.set_value data
85
+ else
86
+ $engine.heap.it.set_to data
87
+ end
88
+ end
89
+
90
+ #
91
+ # Write the given data out to the file.
92
+ #
93
+ def msg_write
94
+ data = ''
95
+ return unless value
96
+
97
+ if @params&.token_count&.positive?
98
+ expr = GlooLang::Expr::Expression.new( @params.tokens )
99
+ data = expr.evaluate
100
+ end
101
+ File.write( value, data )
102
+ end
103
+
104
+ #
105
+ # Check to see if the file exists.
106
+ #
107
+ def msg_check_exists
108
+ result = File.exist? value
109
+ $engine.heap.it.set_to result
110
+ end
111
+
112
+ #
113
+ # Check to see if the file is a file.
114
+ #
115
+ def msg_check_is_file
116
+ result = File.file? value
117
+ $engine.heap.it.set_to result
118
+ end
119
+
120
+ #
121
+ # Check to see if the file is a directory.
122
+ #
123
+ def msg_check_is_dir
124
+ result = File.directory? value
125
+ $engine.heap.it.set_to result
126
+ end
127
+
128
+ #
129
+ # Look for any file matching pattern.
130
+ #
131
+ def msg_find_match
132
+ result = !Dir.glob( value ).empty?
133
+ $engine.heap.it.set_to result
134
+ end
135
+
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,126 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # An object that can post JSON to a URI.
5
+ #
6
+ require 'net/ssh'
7
+
8
+ module GlooLang
9
+ module Objs
10
+ class SshExec < GlooLang::Core::Obj
11
+
12
+ KEYWORD = 'ssh_exec'.freeze
13
+ KEYWORD_SHORT = 'ssh'.freeze
14
+ HOST = 'host'.freeze
15
+ DEFAULT_HOST = 'localhost'.freeze
16
+ CMD = 'cmd'.freeze
17
+ RESULT = 'result'.freeze
18
+ HOST_REQUIRED_ERR = 'The host is required!'.freeze
19
+
20
+ #
21
+ # The name of the object type.
22
+ #
23
+ def self.typename
24
+ return KEYWORD
25
+ end
26
+
27
+ #
28
+ # The short name of the object type.
29
+ #
30
+ def self.short_typename
31
+ return KEYWORD_SHORT
32
+ end
33
+
34
+ # ---------------------------------------------------------------------
35
+ # Children
36
+ # ---------------------------------------------------------------------
37
+
38
+ #
39
+ # Does this object have children to add when an object
40
+ # is created in interactive mode?
41
+ # This does not apply during obj load, etc.
42
+ #
43
+ def add_children_on_create?
44
+ return true
45
+ end
46
+
47
+ #
48
+ # Add children to this object.
49
+ # This is used by containers to add children needed
50
+ # for default configurations.
51
+ #
52
+ def add_default_children
53
+ fac = $engine.factory
54
+ fac.create_string HOST, DEFAULT_HOST, self
55
+ fac.create_string CMD, nil, self
56
+ fac.create_string RESULT, nil, self
57
+ end
58
+
59
+ # ---------------------------------------------------------------------
60
+ # Messages
61
+ # ---------------------------------------------------------------------
62
+
63
+ #
64
+ # Get a list of message names that this object receives.
65
+ #
66
+ def self.messages
67
+ return super + [ 'run' ]
68
+ end
69
+
70
+ #
71
+ # SSH to the host and execute the command, then update result.
72
+ #
73
+ def msg_run
74
+ h = host_value
75
+ unless h
76
+ $engine.err HOST_REQUIRED_ERR
77
+ return
78
+ end
79
+
80
+ Net::SSH.start( h ) do |ssh|
81
+ result = ssh.exec!( cmd_value )
82
+ update_result result
83
+ end
84
+ end
85
+
86
+ # ---------------------------------------------------------------------
87
+ # Private functions
88
+ # ---------------------------------------------------------------------
89
+
90
+ private
91
+
92
+ #
93
+ # Get the host from the child object.
94
+ # Returns nil if there is none.
95
+ #
96
+ def host_value
97
+ o = find_child HOST
98
+ return nil unless o
99
+
100
+ return o.value
101
+ end
102
+
103
+ #
104
+ # Get the command from the child object.
105
+ # Returns nil if there is none.
106
+ #
107
+ def cmd_value
108
+ o = find_child CMD
109
+ return nil unless o
110
+
111
+ return o.value
112
+ end
113
+
114
+ #
115
+ # Set the result of the API call.
116
+ #
117
+ def update_result( data )
118
+ r = find_child RESULT
119
+ return nil unless r
120
+
121
+ r.set_value data
122
+ end
123
+
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,136 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An object that can make a system call.
5
+ #
6
+
7
+ module GlooLang
8
+ module Objs
9
+ class System < GlooLang::Core::Obj
10
+
11
+ KEYWORD = 'system'.freeze
12
+ KEYWORD_SHORT = 'sys'.freeze
13
+ CMD = 'command'.freeze
14
+ DEFAULT_CMD = 'date'.freeze
15
+ RESULT = 'result'.freeze
16
+ GET_OUTPUT = 'get_output'.freeze
17
+
18
+ #
19
+ # The name of the object type.
20
+ #
21
+ def self.typename
22
+ return KEYWORD
23
+ end
24
+
25
+ #
26
+ # The short name of the object type.
27
+ #
28
+ def self.short_typename
29
+ return KEYWORD_SHORT
30
+ end
31
+
32
+ #
33
+ # Get the URI from the child object.
34
+ # Returns nil if there is none.
35
+ #
36
+ def cmd_value
37
+ cmd = find_child CMD
38
+ return nil unless cmd
39
+
40
+ return cmd.value
41
+ end
42
+
43
+ #
44
+ # Set the result of the system call.
45
+ #
46
+ def set_result( data )
47
+ r = find_child RESULT
48
+ return nil unless r
49
+
50
+ r.set_value data
51
+ end
52
+
53
+ #
54
+ # Should the system call get output?
55
+ # If so, the system call will run and get output,
56
+ # otherwise it will just get the result of the call.
57
+ #
58
+ def output?
59
+ o = find_child GET_OUTPUT
60
+ return false unless o
61
+
62
+ return o.value
63
+ end
64
+
65
+ # ---------------------------------------------------------------------
66
+ # Children
67
+ # ---------------------------------------------------------------------
68
+
69
+ #
70
+ # Does this object have children to add when an object
71
+ # is created in interactive mode?
72
+ # This does not apply during obj load, etc.
73
+ #
74
+ def add_children_on_create?
75
+ return true
76
+ end
77
+
78
+ #
79
+ # Add children to this object.
80
+ # This is used by containers to add children needed
81
+ # for default configurations.
82
+ #
83
+ def add_default_children
84
+ fac = $engine.factory
85
+ fac.create_string CMD, DEFAULT_CMD, self
86
+ fac.create_bool GET_OUTPUT, true, self
87
+ fac.create_string RESULT, nil, self
88
+ end
89
+
90
+ # ---------------------------------------------------------------------
91
+ # Messages
92
+ # ---------------------------------------------------------------------
93
+
94
+ #
95
+ # Get a list of message names that this object receives.
96
+ #
97
+ def self.messages
98
+ return super + [ 'run' ]
99
+ end
100
+
101
+ #
102
+ # Run the system command.
103
+ #
104
+ def msg_run
105
+ if output?
106
+ run_with_output
107
+ else
108
+ run_with_result
109
+ end
110
+ end
111
+
112
+ #
113
+ # Run the command and collect output.
114
+ #
115
+ def run_with_output
116
+ cmd = cmd_value
117
+ return unless cmd
118
+
119
+ result = `#{cmd}`
120
+ set_result result
121
+ end
122
+
123
+ #
124
+ # Run the command and set the result.
125
+ #
126
+ def run_with_result
127
+ cmd = cmd_value
128
+ return unless cmd
129
+
130
+ result = system cmd
131
+ set_result result
132
+ end
133
+
134
+ end
135
+ end
136
+ end