gloo 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +73 -0
  3. data/Gemfile +2 -2
  4. data/Gemfile.lock +3 -3
  5. data/Rakefile +6 -6
  6. data/bin/console +4 -4
  7. data/gloo.gemspec +19 -18
  8. data/lib/gloo.rb +6 -6
  9. data/lib/gloo/app/args.rb +30 -31
  10. data/lib/gloo/app/engine.rb +33 -28
  11. data/lib/gloo/app/help.rb +17 -11
  12. data/lib/gloo/app/info.rb +3 -3
  13. data/lib/gloo/app/log.rb +17 -17
  14. data/lib/gloo/app/mode.rb +4 -4
  15. data/lib/gloo/app/settings.rb +43 -40
  16. data/lib/gloo/core/baseo.rb +7 -7
  17. data/lib/gloo/core/dictionary.rb +30 -27
  18. data/lib/gloo/core/error.rb +50 -0
  19. data/lib/gloo/core/event_manager.rb +17 -19
  20. data/lib/gloo/core/factory.rb +92 -39
  21. data/lib/gloo/core/gloo_system.rb +49 -54
  22. data/lib/gloo/core/heap.rb +15 -13
  23. data/lib/gloo/core/it.rb +5 -5
  24. data/lib/gloo/core/literal.rb +7 -7
  25. data/lib/gloo/core/obj.rb +89 -79
  26. data/lib/gloo/core/obj_finder.rb +9 -14
  27. data/lib/gloo/core/op.rb +8 -8
  28. data/lib/gloo/core/parser.rb +25 -26
  29. data/lib/gloo/core/pn.rb +65 -50
  30. data/lib/gloo/core/runner.rb +26 -0
  31. data/lib/gloo/core/script.rb +7 -7
  32. data/lib/gloo/core/tokens.rb +39 -41
  33. data/lib/gloo/core/verb.rb +30 -19
  34. data/lib/gloo/expr/expression.rb +35 -43
  35. data/lib/gloo/expr/l_boolean.rb +7 -6
  36. data/lib/gloo/expr/l_integer.rb +5 -4
  37. data/lib/gloo/expr/l_string.rb +13 -15
  38. data/lib/gloo/expr/op_div.rb +3 -5
  39. data/lib/gloo/expr/op_minus.rb +3 -5
  40. data/lib/gloo/expr/op_mult.rb +3 -5
  41. data/lib/gloo/expr/op_plus.rb +5 -7
  42. data/lib/gloo/objs/basic/boolean.rb +63 -38
  43. data/lib/gloo/objs/basic/container.rb +40 -12
  44. data/lib/gloo/objs/basic/integer.rb +40 -16
  45. data/lib/gloo/objs/basic/script.rb +62 -38
  46. data/lib/gloo/objs/basic/string.rb +39 -15
  47. data/lib/gloo/objs/basic/text.rb +43 -20
  48. data/lib/gloo/objs/basic/untyped.rb +35 -10
  49. data/lib/gloo/objs/cli/colorize.rb +53 -23
  50. data/lib/gloo/objs/cli/confirm.rb +63 -29
  51. data/lib/gloo/objs/cli/prompt.rb +63 -29
  52. data/lib/gloo/objs/ctrl/each.rb +98 -60
  53. data/lib/gloo/objs/dev/git.rb +98 -64
  54. data/lib/gloo/objs/ror/erb.rb +81 -41
  55. data/lib/gloo/objs/ror/eval.rb +73 -31
  56. data/lib/gloo/objs/snd/play.rb +71 -0
  57. data/lib/gloo/objs/snd/say.rb +120 -0
  58. data/lib/gloo/objs/system/file_handle.rb +80 -48
  59. data/lib/gloo/objs/system/system.rb +84 -38
  60. data/lib/gloo/objs/web/http_get.rb +83 -46
  61. data/lib/gloo/objs/web/http_post.rb +69 -43
  62. data/lib/gloo/objs/web/slack.rb +89 -58
  63. data/lib/gloo/objs/web/teams.rb +88 -53
  64. data/lib/gloo/persist/file_loader.rb +81 -82
  65. data/lib/gloo/persist/file_saver.rb +12 -12
  66. data/lib/gloo/persist/file_storage.rb +15 -15
  67. data/lib/gloo/persist/line_splitter.rb +74 -0
  68. data/lib/gloo/persist/persist_man.rb +29 -29
  69. data/lib/gloo/utils/words.rb +2 -2
  70. data/lib/gloo/verbs/alert.rb +67 -16
  71. data/lib/gloo/verbs/beep.rb +70 -0
  72. data/lib/gloo/verbs/context.rb +61 -21
  73. data/lib/gloo/verbs/create.rb +52 -21
  74. data/lib/gloo/verbs/help.rb +177 -27
  75. data/lib/gloo/verbs/if.rb +54 -21
  76. data/lib/gloo/verbs/list.rb +55 -24
  77. data/lib/gloo/verbs/load.rb +46 -12
  78. data/lib/gloo/verbs/put.rb +90 -34
  79. data/lib/gloo/verbs/quit.rb +43 -12
  80. data/lib/gloo/verbs/run.rb +42 -11
  81. data/lib/gloo/verbs/save.rb +45 -10
  82. data/lib/gloo/verbs/show.rb +56 -22
  83. data/lib/gloo/verbs/tell.rb +44 -12
  84. data/lib/gloo/verbs/unless.rb +55 -21
  85. data/lib/gloo/verbs/version.rb +42 -12
  86. data/lib/run.rb +5 -5
  87. metadata +19 -12
@@ -9,11 +9,11 @@ require 'active_support/inflector'
9
9
  module Gloo
10
10
  module Utils
11
11
  class Words
12
-
12
+
13
13
  def self.pluralize( word )
14
14
  return word.pluralize
15
15
  end
16
-
16
+
17
17
  end
18
18
  end
19
19
  end
@@ -7,36 +7,87 @@
7
7
  module Gloo
8
8
  module Verbs
9
9
  class Alert < Gloo::Core::Verb
10
-
11
- KEYWORD = 'alert'
12
- KEYWORD_SHORT = '!'
13
10
 
14
- #
11
+ KEYWORD = 'alert'.freeze
12
+ KEYWORD_SHORT = '!'.freeze
13
+
14
+ #
15
15
  # Run the verb.
16
- #
16
+ #
17
17
  def run
18
- if @tokens.token_count > 1
19
- expr = Gloo::Expr::Expression.new( @tokens.params )
20
- result = expr.evaluate
21
- $engine.heap.it.set_to result
22
- system( '/usr/bin/osascript -e "display notification \"' + result.to_s + '\" with title \"OutlineScript\" "' )
23
- end
18
+ return unless @tokens.token_count > 1
19
+
20
+ expr = Gloo::Expr::Expression.new( @tokens.params )
21
+ result = expr.evaluate
22
+ $engine.heap.it.set_to result
23
+ self.post_alert result
24
+ end
25
+
26
+ #
27
+ # Post the alert for the specific platform.
28
+ # Notice is not posted if we're in quiet mode.
29
+ #
30
+ def post_alert( msg )
31
+ return if $engine.args.quiet?
32
+
33
+ post_osx msg
34
+ end
35
+
36
+ #
37
+ # Post the alert on the Mac OSX.
38
+ #
39
+ def post_osx( msg )
40
+ cmd1 = '/usr/bin/osascript -e "display notification \"'
41
+ cmd2 = '\" with title \"Gloo\" "'
42
+ system( cmd1 + msg.to_s + cmd2 )
24
43
  end
25
-
26
- #
44
+
45
+ #
27
46
  # Get the Verb's keyword.
28
- #
47
+ #
29
48
  def self.keyword
30
49
  return KEYWORD
31
50
  end
32
51
 
33
- #
52
+ #
34
53
  # Get the Verb's keyword shortcut.
35
- #
54
+ #
36
55
  def self.keyword_shortcut
37
56
  return KEYWORD_SHORT
38
57
  end
39
58
 
59
+ # ---------------------------------------------------------------------
60
+ # Help
61
+ # ---------------------------------------------------------------------
62
+
63
+ #
64
+ # Get help for this verb.
65
+ #
66
+ def self.help
67
+ return <<~TEXT
68
+ ALERT VERB
69
+ NAME: alert
70
+ SHORTCUT: !
71
+
72
+ DESCRIPTION
73
+ Show a pop-up notification.
74
+ This has only been implemented for the Mac OSX as of yet.
75
+
76
+ SYNTAX
77
+ alert <messsage>
78
+
79
+ PARAMETERS
80
+ messsage - The message that will be displayed in the alert.
81
+
82
+ RESULT
83
+ On the Mac, a notification will popup on screen.
84
+ <it> will be set to the message.
85
+
86
+ ERRORS
87
+ None
88
+ TEXT
89
+ end
90
+
40
91
  end
41
92
  end
42
93
  end
@@ -0,0 +1,70 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Play a standard system beep sound.
5
+ #
6
+
7
+ module Gloo
8
+ module Verbs
9
+ class Beep < Gloo::Core::Verb
10
+
11
+ KEYWORD = 'beep'.freeze
12
+ KEYWORD_SHORT = 'b'.freeze
13
+
14
+ #
15
+ # Run the verb.
16
+ #
17
+ # We'll mark the application as not running and let the
18
+ # engine stop gracefully next time through the loop.
19
+ #
20
+ def run
21
+ print 7.chr
22
+ end
23
+
24
+ #
25
+ # Get the Verb's keyword.
26
+ #
27
+ def self.keyword
28
+ return KEYWORD
29
+ end
30
+
31
+ #
32
+ # Get the Verb's keyword shortcut.
33
+ #
34
+ def self.keyword_shortcut
35
+ return KEYWORD_SHORT
36
+ end
37
+
38
+ # ---------------------------------------------------------------------
39
+ # Help
40
+ # ---------------------------------------------------------------------
41
+
42
+ #
43
+ # Get help for this verb.
44
+ #
45
+ def self.help
46
+ return <<~TEXT
47
+ BEEP VERB
48
+ NAME: beep
49
+ SHORTCUT: b
50
+
51
+ DESCRIPTION
52
+ Play a standard system beep sound.
53
+
54
+ SYNTAX
55
+ beep
56
+
57
+ PARAMETERS
58
+ None
59
+
60
+ RESULT
61
+ None
62
+
63
+ ERRORS
64
+ None
65
+ TEXT
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -8,45 +8,85 @@
8
8
  module Gloo
9
9
  module Verbs
10
10
  class Context < Gloo::Core::Verb
11
-
12
- KEYWORD = 'context'
13
- KEYWORD_SHORT = '@'
14
11
 
15
- #
12
+ KEYWORD = 'context'.freeze
13
+ KEYWORD_SHORT = '@'.freeze
14
+
15
+ #
16
16
  # Run the verb.
17
- #
17
+ #
18
18
  def run
19
- if @tokens.token_count == 1
20
- show_context
21
- else
22
- path = @tokens.second
23
- $engine.heap.context.set_to path
24
- $engine.heap.it.set_to path
25
- $log.debug "Context set to #{$engine.heap.context}"
26
- end
19
+ set_context if @tokens.token_count > 1
20
+ show_context
21
+ end
22
+
23
+ #
24
+ # Set the context to the given path.
25
+ #
26
+ def set_context
27
+ path = @tokens.second
28
+ $engine.heap.context.set_to path
29
+ $engine.heap.it.set_to path
30
+ $log.debug "Context set to #{$engine.heap.context}"
27
31
  end
28
-
29
- #
32
+
33
+ #
30
34
  # Show the current context.
31
- #
35
+ #
32
36
  def show_context
33
37
  $log.show "Context: #{$engine.heap.context}"
34
38
  end
35
-
36
- #
39
+
40
+ #
37
41
  # Get the Verb's keyword.
38
- #
42
+ #
39
43
  def self.keyword
40
44
  return KEYWORD
41
45
  end
42
46
 
43
- #
47
+ #
44
48
  # Get the Verb's keyword shortcut.
45
- #
49
+ #
46
50
  def self.keyword_shortcut
47
51
  return KEYWORD_SHORT
48
52
  end
49
53
 
54
+ # ---------------------------------------------------------------------
55
+ # Help
56
+ # ---------------------------------------------------------------------
57
+
58
+ #
59
+ # Get help for this verb.
60
+ #
61
+ def self.help
62
+ return <<~TEXT
63
+ CONTEXT VERB
64
+ NAME: context
65
+ SHORTCUT: @
66
+
67
+ DESCRIPTION
68
+ Get or set the current context.
69
+ When no parameter is provided, the context will be shown.
70
+ Whe the optional path paramter is provided, the context will
71
+ be set to that path.
72
+ Use 'context root' to set the context back to the root level.
73
+
74
+ SYNTAX
75
+ context <path.to.new.context>
76
+
77
+ PARAMETERS
78
+ path.to.new.context - Optional. The path to the new context.
79
+
80
+ RESULT
81
+ Context is optionally set.
82
+ <it> will be set to the new context path when we are changing context.
83
+ Context is show in either case.
84
+
85
+ ERRORS
86
+ None
87
+ TEXT
88
+ end
89
+
50
90
  end
51
91
  end
52
92
  end
@@ -7,46 +7,77 @@
7
7
  module Gloo
8
8
  module Verbs
9
9
  class Create < Gloo::Core::Verb
10
-
11
- KEYWORD = 'create'
12
- KEYWORD_SHORT = '`'
13
- AS = 'as'
14
- VAL = ':'
15
-
16
- #
10
+
11
+ KEYWORD = 'create'.freeze
12
+ KEYWORD_SHORT = '`'.freeze
13
+ AS = 'as'.freeze
14
+ VAL = ':'.freeze
15
+
16
+ #
17
17
  # Run the verb.
18
- #
18
+ #
19
19
  def run
20
20
  name = @tokens.second
21
21
  type = @tokens.after_token( AS )
22
22
  value = @tokens.after_token( VAL )
23
-
24
- if Gloo::Expr::LString.is_string?( value )
23
+
24
+ if Gloo::Expr::LString.string?( value )
25
25
  value = Gloo::Expr::LString.strip_quotes( value )
26
26
  end
27
- obj = $engine.factory.create( name, type, value )
28
-
29
- if obj && obj.add_children_on_create?
30
- obj.add_default_children
31
- end
32
-
27
+ obj = $engine.factory.create( { name: name, type: type, value: value } )
28
+
29
+ obj.add_default_children if obj&.add_children_on_create?
33
30
  $engine.heap.it.set_to value
34
31
  end
35
-
36
- #
32
+
33
+ #
37
34
  # Get the Verb's keyword.
38
- #
35
+ #
39
36
  def self.keyword
40
37
  return KEYWORD
41
38
  end
42
39
 
43
- #
40
+ #
44
41
  # Get the Verb's keyword shortcut.
45
- #
42
+ #
46
43
  def self.keyword_shortcut
47
44
  return KEYWORD_SHORT
48
45
  end
49
46
 
47
+ # ---------------------------------------------------------------------
48
+ # Help
49
+ # ---------------------------------------------------------------------
50
+
51
+ #
52
+ # Get help for this verb.
53
+ #
54
+ def self.help
55
+ return <<~TEXT
56
+ CREATE VERB
57
+ NAME: create
58
+ SHORTCUT: `
59
+
60
+ DESCRIPTION
61
+ Create a new object of given type with given value.
62
+ Both type and value are optional when creating an object.
63
+
64
+ SYNTAX
65
+ create <new.object.path> as <type> : <value>
66
+
67
+ PARAMETERS
68
+ new.object.path - The path and name of the new object
69
+ type - The type of the new object
70
+ value - The initial value for the new object
71
+
72
+ RESULT
73
+ The new object will be created and added to the object heap.
74
+ <it> will be set to the new object's intitial value.
75
+
76
+ ERRORS
77
+ None
78
+ TEXT
79
+ end
80
+
50
81
  end
51
82
  end
52
83
  end
@@ -7,63 +7,213 @@
7
7
  module Gloo
8
8
  module Verbs
9
9
  class Help < Gloo::Core::Verb
10
-
11
- KEYWORD = 'help'
12
- KEYWORD_SHORT = '?'
13
10
 
14
- #
11
+ KEYWORD = 'help'.freeze
12
+ KEYWORD_SHORT = '?'.freeze
13
+
14
+ DISPATCH = {
15
+ verb: 'show_verbs',
16
+ verbs: 'show_verbs',
17
+ v: 'show_verbs',
18
+ obj: 'show_objs',
19
+ object: 'show_objs',
20
+ objects: 'show_objs',
21
+ o: 'show_objs'
22
+ }.freeze
23
+
24
+ #
15
25
  # Run the verb.
16
- #
26
+ #
17
27
  def run
18
28
  opts = @tokens.second if @tokens
19
-
20
- if opts && opts.strip.downcase == 'verbs'
21
- show_verbs
22
- elsif opts && opts.strip.downcase == 'objects'
23
- show_objs
29
+ opts = opts.strip.downcase if opts
30
+
31
+ if opts
32
+ self.dispatch opts
33
+ else
34
+ show_default
35
+ end
36
+ end
37
+
38
+ #
39
+ # Dispatch the help to the right place.
40
+ #
41
+ def dispatch( opts )
42
+ cmd = DISPATCH[ opts.to_sym ]
43
+ if cmd
44
+ send cmd
24
45
  else
25
- $engine.run_help( true )
46
+ entity_help opts
26
47
  end
48
+ rescue
49
+ report_help_error opts
50
+ end
51
+
52
+ #
53
+ # Dispatch the help command to a verb or object
54
+ # if we can find one matching the request.
55
+ #
56
+ def entity_help( opts )
57
+ return if try_verb_help opts
58
+ return if try_object_help opts
59
+
60
+ report_help_error opts
61
+ end
62
+
63
+ #
64
+ # See if there is a verb we can show help
65
+ # information about.
66
+ #
67
+ def try_verb_help( opts )
68
+ if $engine.dictionary.verb?( opts )
69
+ t = $engine.dictionary.find_verb( opts )
70
+ out = t.send 'help'
71
+ self.show_output out
72
+ return true
73
+ end
74
+
75
+ return false
76
+ end
77
+
78
+ #
79
+ # See if there is a verb we can show help
80
+ # information about.
81
+ #
82
+ def try_object_help( opts )
83
+ if $engine.dictionary.obj?( opts )
84
+ t = $engine.dictionary.find_obj( opts )
85
+ out = t.send 'help'
86
+ self.show_output out
87
+ return true
88
+ end
89
+
90
+ return false
91
+ end
92
+
93
+ #
94
+ # Lookup the opts in the dispatch table.
95
+ #
96
+ def lookup_opts( opts )
97
+ return DISPATCH[ opts.to_sym ]
98
+ end
99
+
100
+ #
101
+ # Report an error with the inline help.
102
+ #
103
+ def report_help_error( opts )
104
+ msg = "Help command '#{opts}' could not be found"
105
+ $log.warn msg
106
+ $engine.heap.error.set_to msg
107
+ end
108
+
109
+ #
110
+ # If no parameter is given, show the default help page.
111
+ #
112
+ def show_default
113
+ $engine.run_help( true )
27
114
  end
28
-
29
- #
115
+
116
+ #
30
117
  # List the verbs
31
- #
118
+ #
32
119
  def show_verbs
33
- return if $engine.args.quiet?
120
+ out = self.get_verb_list
121
+ self.show_output out
122
+ end
34
123
 
35
- puts "Verbs:"
124
+ #
125
+ # Get the text for the list of verbs.
126
+ #
127
+ def get_verb_list
128
+ out = "Verbs:\n"
36
129
  $engine.dictionary.get_verbs.each do |v|
37
- puts " \t #{v.keyword_shortcut} \t #{v.keyword}"
130
+ out << " #{v.keyword_shortcut} - #{v.keyword}\n"
38
131
  end
132
+ return out
39
133
  end
40
134
 
41
- #
135
+ #
42
136
  # List the object types
43
- #
137
+ #
44
138
  def show_objs
45
- return if $engine.args.quiet?
139
+ out = self.get_obj_list
140
+ self.show_output out
141
+ end
46
142
 
47
- puts "Object Types:"
143
+ #
144
+ # Get the text for the list of verbs.
145
+ #
146
+ def get_obj_list
147
+ out = "Object Types:\n"
48
148
  $engine.dictionary.get_obj_types.each do |v|
49
- puts " \t #{v.short_typename} \t #{v.typename}"
149
+ out << " #{v.short_typename} - #{v.typename}\n"
50
150
  end
151
+ return out
152
+ end
153
+
154
+ #
155
+ # Write output to it and show it unless we are in
156
+ # silent mode.
157
+ #
158
+ def show_output( out )
159
+ $engine.heap.it.set_to out
160
+ puts out unless $engine.args.quiet?
51
161
  end
52
-
53
- #
162
+
163
+ #
54
164
  # Get the Verb's keyword.
55
- #
165
+ #
56
166
  def self.keyword
57
167
  return KEYWORD
58
168
  end
59
169
 
60
- #
170
+ #
61
171
  # Get the Verb's keyword shortcut.
62
- #
172
+ #
63
173
  def self.keyword_shortcut
64
174
  return KEYWORD_SHORT
65
175
  end
66
176
 
177
+ # ---------------------------------------------------------------------
178
+ # Help
179
+ # ---------------------------------------------------------------------
180
+
181
+ #
182
+ # Get help for this verb.
183
+ #
184
+ def self.help
185
+ return <<~TEXT
186
+ HELP VERB
187
+ NAME: helps
188
+ SHORTCUT: ?
189
+
190
+ DESCRIPTION
191
+ Show information about the application.
192
+ The help command can also be used to show a list of objects,
193
+ verbs, or to show detail about a single object or a
194
+ single verb.
195
+
196
+ SYNTAX
197
+ help <about>
198
+
199
+ PARAMETERS
200
+ about - Optional parameter.
201
+ If no parameter is given, shows the default help screen
202
+ verbs - List available verbs
203
+ objects - List available objects
204
+ <verb> - Look up detail about a verb
205
+ <object> - Look up detail about an object
206
+
207
+ RESULT
208
+ The help screen will be shown with relevant information.
209
+ <it> will also contain the help text.
210
+
211
+ ERRORS
212
+ Trying to access a help topic that does not exist will result
213
+ in an error.
214
+ TEXT
215
+ end
216
+
67
217
  end
68
218
  end
69
219
  end