gloo 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.rubocop.yml +1 -1
- data/Gemfile.lock +80 -81
- data/Rakefile +1 -0
- data/gloo.gemspec +2 -1
- data/lib/gloo/app/engine.rb +48 -3
- data/lib/gloo/app/info.rb +1 -1
- data/lib/gloo/app/settings.rb +12 -5
- data/lib/gloo/convert/string_to_datetime.rb +21 -0
- data/lib/gloo/convert/string_to_decimal.rb +20 -0
- data/lib/gloo/convert/string_to_integer.rb +20 -0
- data/lib/gloo/core/event_manager.rb +2 -6
- data/lib/gloo/core/factory.rb +58 -1
- data/lib/gloo/core/gloo_system.rb +72 -0
- data/lib/gloo/core/obj.rb +50 -1
- data/lib/gloo/core/parser.rb +3 -1
- data/lib/gloo/core/pn.rb +3 -2
- data/lib/gloo/exec/dispatch.rb +30 -0
- data/lib/gloo/exec/runner.rb +43 -0
- data/lib/gloo/expr/expression.rb +1 -0
- data/lib/gloo/expr/l_decimal.rb +34 -0
- data/lib/gloo/expr/op_div.rb +2 -0
- data/lib/gloo/expr/op_minus.rb +2 -0
- data/lib/gloo/expr/op_mult.rb +2 -0
- data/lib/gloo/expr/op_plus.rb +2 -0
- data/lib/gloo/objs/basic/alias.rb +111 -0
- data/lib/gloo/objs/basic/container.rb +11 -1
- data/lib/gloo/objs/basic/decimal.rb +96 -0
- data/lib/gloo/objs/basic/integer.rb +5 -0
- data/lib/gloo/objs/basic/string.rb +9 -1
- data/lib/gloo/objs/basic/text.rb +27 -2
- data/lib/gloo/objs/cli/banner.rb +137 -0
- data/lib/gloo/objs/cli/bar.rb +141 -0
- data/lib/gloo/objs/cli/colorize.rb +1 -1
- data/lib/gloo/objs/cli/menu.rb +236 -0
- data/lib/gloo/objs/cli/menu_item.rb +128 -0
- data/lib/gloo/objs/cli/pastel.rb +120 -0
- data/lib/gloo/objs/cli/prompt.rb +19 -11
- data/lib/gloo/objs/cli/select.rb +153 -0
- data/lib/gloo/objs/ctrl/each.rb +45 -16
- data/lib/gloo/objs/ctrl/repeat.rb +129 -0
- data/lib/gloo/objs/data/markdown.rb +109 -0
- data/lib/gloo/objs/data/table.rb +168 -0
- data/lib/gloo/objs/dt/date.rb +72 -0
- data/lib/gloo/objs/dt/datetime.rb +84 -0
- data/lib/gloo/objs/dt/time.rb +72 -0
- data/lib/gloo/objs/ror/erb.rb +1 -0
- data/lib/gloo/objs/system/file_handle.rb +50 -1
- data/lib/gloo/objs/web/http_get.rb +24 -4
- data/lib/gloo/objs/web/http_post.rb +1 -0
- data/lib/gloo/objs/web/json.rb +155 -0
- data/lib/gloo/objs/web/uri.rb +160 -0
- data/lib/gloo/persist/file_loader.rb +17 -6
- data/lib/gloo/persist/line_splitter.rb +7 -2
- data/lib/gloo/persist/persist_man.rb +37 -13
- data/lib/gloo/verbs/cls.rb +67 -0
- data/lib/gloo/verbs/help.rb +9 -0
- data/lib/gloo/verbs/if.rb +1 -0
- data/lib/gloo/verbs/load.rb +3 -2
- data/lib/gloo/verbs/move.rb +128 -0
- data/lib/gloo/verbs/run.rb +21 -7
- data/lib/gloo/verbs/tell.rb +1 -1
- data/lib/gloo/verbs/unless.rb +1 -0
- data/lib/gloo/verbs/wait.rb +73 -0
- metadata +36 -5
- data/lib/gloo/core/runner.rb +0 -26
data/lib/gloo/objs/ror/erb.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# An object that points to a file in the system.
|
5
5
|
#
|
6
|
+
require 'tty-pager'
|
6
7
|
|
7
8
|
module Gloo
|
8
9
|
module Objs
|
@@ -33,9 +34,45 @@ module Gloo
|
|
33
34
|
# Get a list of message names that this object receives.
|
34
35
|
#
|
35
36
|
def self.messages
|
36
|
-
|
37
|
+
basic = %w[read write]
|
38
|
+
checks = %w[check_exists check_is_file check_is_dir]
|
39
|
+
show = %w[show page open]
|
40
|
+
return super + basic + show + checks
|
37
41
|
end
|
38
42
|
|
43
|
+
#
|
44
|
+
# Open the file in the default application for the file type.
|
45
|
+
#
|
46
|
+
def msg_open
|
47
|
+
return unless value && File.exist?( value )
|
48
|
+
|
49
|
+
cmd = Gloo::Core::GlooSystem.open_for_platform
|
50
|
+
cmd_with_param = "#{cmd} \"#{value}\""
|
51
|
+
`#{cmd_with_param}`
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Show the contents of the file, paginated.
|
56
|
+
#
|
57
|
+
def msg_page
|
58
|
+
return unless value && File.file?( value )
|
59
|
+
|
60
|
+
pager = TTY::Pager.new
|
61
|
+
pager.page( path: value )
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Show the contents of the file.
|
66
|
+
#
|
67
|
+
def msg_show
|
68
|
+
return unless value && File.file?( value )
|
69
|
+
|
70
|
+
puts File.read( value )
|
71
|
+
end
|
72
|
+
|
73
|
+
#
|
74
|
+
# Read the contents of the file into the object.
|
75
|
+
#
|
39
76
|
def msg_read
|
40
77
|
return unless value && File.file?( value )
|
41
78
|
|
@@ -49,6 +86,9 @@ module Gloo
|
|
49
86
|
end
|
50
87
|
end
|
51
88
|
|
89
|
+
#
|
90
|
+
# Write the given data out to the file.
|
91
|
+
#
|
52
92
|
def msg_write
|
53
93
|
data = ''
|
54
94
|
return unless value
|
@@ -60,19 +100,25 @@ module Gloo
|
|
60
100
|
File.write( value, data )
|
61
101
|
end
|
62
102
|
|
103
|
+
#
|
63
104
|
# Check to see if the file exists.
|
105
|
+
#
|
64
106
|
def msg_check_exists
|
65
107
|
result = File.exist? value
|
66
108
|
$engine.heap.it.set_to result
|
67
109
|
end
|
68
110
|
|
111
|
+
#
|
69
112
|
# Check to see if the file is a file.
|
113
|
+
#
|
70
114
|
def msg_check_is_file
|
71
115
|
result = File.file? value
|
72
116
|
$engine.heap.it.set_to result
|
73
117
|
end
|
74
118
|
|
119
|
+
#
|
75
120
|
# Check to see if the file is a directory.
|
121
|
+
#
|
76
122
|
def msg_check_is_dir
|
77
123
|
result = File.directory? value
|
78
124
|
$engine.heap.it.set_to result
|
@@ -104,6 +150,9 @@ module Gloo
|
|
104
150
|
If the <into.obj> is not specified, the data will be in <it>.
|
105
151
|
write <from.obj> - Write the data in the <from.object> into
|
106
152
|
the file.
|
153
|
+
show - Show the contents of the file.
|
154
|
+
page - Show the contents of the file, paginated
|
155
|
+
open - Open the file with the default application for the type.
|
107
156
|
check_exists - Check to see if the file exists.
|
108
157
|
<It> will be true or false.
|
109
158
|
check_is_file - Check to see if the file specified is a
|
@@ -6,6 +6,7 @@
|
|
6
6
|
require 'net/http'
|
7
7
|
require 'uri'
|
8
8
|
require 'json'
|
9
|
+
require 'openssl'
|
9
10
|
|
10
11
|
module Gloo
|
11
12
|
module Objs
|
@@ -16,6 +17,7 @@ module Gloo
|
|
16
17
|
URL = 'uri'.freeze
|
17
18
|
PARAMS = 'params'.freeze
|
18
19
|
RESULT = 'result'.freeze
|
20
|
+
SKIP_SSL_VERIFY = 'skip_ssl_verify'.freeze
|
19
21
|
|
20
22
|
#
|
21
23
|
# The name of the object type.
|
@@ -42,6 +44,16 @@ module Gloo
|
|
42
44
|
return uri.value
|
43
45
|
end
|
44
46
|
|
47
|
+
#
|
48
|
+
# Should we skip SSL verification during the request?
|
49
|
+
#
|
50
|
+
def skip_ssl_verify?
|
51
|
+
skip = find_child SKIP_SSL_VERIFY
|
52
|
+
return false unless skip
|
53
|
+
|
54
|
+
return skip.value
|
55
|
+
end
|
56
|
+
|
45
57
|
#
|
46
58
|
# Set the result of the API call.
|
47
59
|
#
|
@@ -61,6 +73,8 @@ module Gloo
|
|
61
73
|
params.children.each do |child|
|
62
74
|
p << ( p.empty? ? '?' : '&' )
|
63
75
|
|
76
|
+
child = Gloo::Objs::Alias.resolve_alias( child )
|
77
|
+
|
64
78
|
# TODO: Quote URL params for safety
|
65
79
|
p << "#{child.name}=#{child.value}"
|
66
80
|
end
|
@@ -112,7 +126,8 @@ module Gloo
|
|
112
126
|
def msg_run
|
113
127
|
url = full_url_value
|
114
128
|
$log.debug url
|
115
|
-
|
129
|
+
r = Gloo::Objs::HttpGet.invoke_request( url, self.skip_ssl_verify? )
|
130
|
+
update_result r
|
116
131
|
end
|
117
132
|
|
118
133
|
# ---------------------------------------------------------------------
|
@@ -120,10 +135,13 @@ module Gloo
|
|
120
135
|
# ---------------------------------------------------------------------
|
121
136
|
|
122
137
|
# Post the content to the endpoint.
|
123
|
-
def self.invoke_request( url )
|
138
|
+
def self.invoke_request( url, skip_ssl_verify = false )
|
124
139
|
uri = URI( url )
|
125
|
-
|
126
|
-
|
140
|
+
params = { use_ssl: uri.scheme == 'https' }
|
141
|
+
|
142
|
+
params[ :verify_mode ] = ::OpenSSL::SSL::VERIFY_NONE if skip_ssl_verify
|
143
|
+
|
144
|
+
Net::HTTP.start( uri.host, uri.port, params ) do |http|
|
127
145
|
request = Net::HTTP::Get.new uri
|
128
146
|
response = http.request request # Net::HTTPResponse object
|
129
147
|
return response.body
|
@@ -154,6 +172,8 @@ module Gloo
|
|
154
172
|
result - string
|
155
173
|
The result of the request. Whatever was returned from
|
156
174
|
the HTTP Get call.
|
175
|
+
skip_ssl_verify - boolean (optional)
|
176
|
+
Skip the SSL verification as part of the request.
|
157
177
|
|
158
178
|
MESSAGES
|
159
179
|
run - Run the HTTP Get and update the result.
|
@@ -0,0 +1,155 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# JSON data.
|
5
|
+
#
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
module Gloo
|
9
|
+
module Objs
|
10
|
+
class Json < Gloo::Core::Obj
|
11
|
+
|
12
|
+
KEYWORD = 'json'.freeze
|
13
|
+
KEYWORD_SHORT = 'json'.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
|
+
# Set the value with any necessary type conversions.
|
31
|
+
#
|
32
|
+
def set_value( new_value )
|
33
|
+
self.value = new_value.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Does this object support multi-line values?
|
38
|
+
# Initially only true for scripts.
|
39
|
+
#
|
40
|
+
def multiline_value?
|
41
|
+
return false
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# Get the number of lines of text.
|
46
|
+
#
|
47
|
+
def line_count
|
48
|
+
return value.split( "\n" ).count
|
49
|
+
end
|
50
|
+
|
51
|
+
# ---------------------------------------------------------------------
|
52
|
+
# Messages
|
53
|
+
# ---------------------------------------------------------------------
|
54
|
+
|
55
|
+
#
|
56
|
+
# Get a list of message names that this object receives.
|
57
|
+
#
|
58
|
+
def self.messages
|
59
|
+
return super + %w[get parse]
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# Get a value from the JSON data.
|
64
|
+
# The additional parameter is the path to the value.
|
65
|
+
#
|
66
|
+
def msg_get
|
67
|
+
if @params&.token_count&.positive?
|
68
|
+
expr = Gloo::Expr::Expression.new( @params.tokens )
|
69
|
+
data = expr.evaluate
|
70
|
+
end
|
71
|
+
return unless data
|
72
|
+
|
73
|
+
h = JSON.parse( self.value )
|
74
|
+
field = h[ data ]
|
75
|
+
$engine.heap.it.set_to field
|
76
|
+
return field
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# Parse the JSON data and put it in objects.
|
81
|
+
# The additional parameter is the path to the destination
|
82
|
+
# for the parsed objects.
|
83
|
+
#
|
84
|
+
def msg_parse
|
85
|
+
if @params&.token_count&.positive?
|
86
|
+
pn = Gloo::Core::Pn.new @params.tokens.first
|
87
|
+
unless pn&.exists?
|
88
|
+
$engine.err 'Destination path for parsed objects does not exist'
|
89
|
+
return
|
90
|
+
end
|
91
|
+
else
|
92
|
+
$engine.err 'Destination path for parsed objects is required'
|
93
|
+
return
|
94
|
+
end
|
95
|
+
parent = pn.resolve
|
96
|
+
|
97
|
+
json = JSON.parse( self.value )
|
98
|
+
self.handle_json( json, parent )
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# Handle JSON, creating objects and setting values.
|
103
|
+
# Note that this is a recursive function.
|
104
|
+
#
|
105
|
+
def handle_json( json, parent )
|
106
|
+
if json.class == Hash
|
107
|
+
json.each do |k, v|
|
108
|
+
if v.class == Array
|
109
|
+
o = parent.find_add_child( k, 'can' )
|
110
|
+
handle_json( v, o )
|
111
|
+
else
|
112
|
+
o = parent.find_add_child( k, 'untyped' )
|
113
|
+
o.set_value v
|
114
|
+
end
|
115
|
+
end
|
116
|
+
elsif json.class == Array
|
117
|
+
json.each_with_index do |o, index|
|
118
|
+
child = parent.find_add_child( index.to_s, 'can' )
|
119
|
+
handle_json( o, child )
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# ---------------------------------------------------------------------
|
125
|
+
# Help
|
126
|
+
# ---------------------------------------------------------------------
|
127
|
+
|
128
|
+
#
|
129
|
+
# Get help for this object type.
|
130
|
+
#
|
131
|
+
def self.help
|
132
|
+
return <<~TEXT
|
133
|
+
JSON OBJECT TYPE
|
134
|
+
NAME: json
|
135
|
+
SHORTCUT: json
|
136
|
+
|
137
|
+
DESCRIPTION
|
138
|
+
JSON data in a text string.
|
139
|
+
|
140
|
+
CHILDREN
|
141
|
+
None
|
142
|
+
|
143
|
+
MESSAGES
|
144
|
+
get - get a value from the JSON data
|
145
|
+
Example: tell myjson to get ("title")
|
146
|
+
The additional parameter is the path to the value.
|
147
|
+
parse - parse the JSON data and put values in the
|
148
|
+
object specified by the additional parameter
|
149
|
+
Example: tell myjson to parse ("path.to.objects")
|
150
|
+
TEXT
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# A URI (URL).
|
5
|
+
#
|
6
|
+
require 'uri'
|
7
|
+
|
8
|
+
module Gloo
|
9
|
+
module Objs
|
10
|
+
class Uri < Gloo::Core::Obj
|
11
|
+
|
12
|
+
KEYWORD = 'uri'.freeze
|
13
|
+
KEYWORD_SHORT = 'url'.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
|
+
# Set the value with any necessary type conversions.
|
31
|
+
#
|
32
|
+
def set_value( new_value )
|
33
|
+
self.value = new_value.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Does this object support multi-line values?
|
38
|
+
# Initially only true for scripts.
|
39
|
+
#
|
40
|
+
def multiline_value?
|
41
|
+
return false
|
42
|
+
end
|
43
|
+
|
44
|
+
# ---------------------------------------------------------------------
|
45
|
+
# Messages
|
46
|
+
# ---------------------------------------------------------------------
|
47
|
+
|
48
|
+
#
|
49
|
+
# Get a list of message names that this object receives.
|
50
|
+
#
|
51
|
+
def self.messages
|
52
|
+
basic = %w[open]
|
53
|
+
gets = %w[get_scheme get_host get_path]
|
54
|
+
more = %w[get_query get_fragment]
|
55
|
+
return super + basic + gets + more
|
56
|
+
end
|
57
|
+
|
58
|
+
#
|
59
|
+
# Get the URI fragment that comes after the '#'
|
60
|
+
# in the URL. Might be used to scroll down in the page.
|
61
|
+
#
|
62
|
+
def msg_get_fragment
|
63
|
+
return unless value
|
64
|
+
|
65
|
+
o = URI( value ).fragment
|
66
|
+
$engine.heap.it.set_to o
|
67
|
+
return o
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
71
|
+
# Get the URI query parameters.
|
72
|
+
# Example: id=121
|
73
|
+
#
|
74
|
+
def msg_get_query
|
75
|
+
return unless value
|
76
|
+
|
77
|
+
o = URI( value ).query
|
78
|
+
$engine.heap.it.set_to o
|
79
|
+
return o
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# Get the URI path.
|
84
|
+
# Example: /posts
|
85
|
+
#
|
86
|
+
def msg_get_path
|
87
|
+
return unless value
|
88
|
+
|
89
|
+
o = URI( value ).path
|
90
|
+
$engine.heap.it.set_to o
|
91
|
+
return o
|
92
|
+
end
|
93
|
+
|
94
|
+
#
|
95
|
+
# Get the URI host.
|
96
|
+
# Example: google.com
|
97
|
+
#
|
98
|
+
def msg_get_host
|
99
|
+
return unless value
|
100
|
+
|
101
|
+
o = URI( value ).host
|
102
|
+
$engine.heap.it.set_to o
|
103
|
+
return o
|
104
|
+
end
|
105
|
+
|
106
|
+
#
|
107
|
+
# Get the URI Scheme.
|
108
|
+
# Example: http
|
109
|
+
#
|
110
|
+
def msg_get_scheme
|
111
|
+
return unless value
|
112
|
+
|
113
|
+
o = URI( value ).scheme
|
114
|
+
$engine.heap.it.set_to o
|
115
|
+
return o
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# Open the URI in the default browser.
|
120
|
+
#
|
121
|
+
def msg_open
|
122
|
+
return unless value
|
123
|
+
|
124
|
+
cmd = Gloo::Core::GlooSystem.open_for_platform
|
125
|
+
cmd_with_param = "#{cmd} \"#{value}\""
|
126
|
+
`#{cmd_with_param}`
|
127
|
+
end
|
128
|
+
|
129
|
+
# ---------------------------------------------------------------------
|
130
|
+
# Help
|
131
|
+
# ---------------------------------------------------------------------
|
132
|
+
|
133
|
+
#
|
134
|
+
# Get help for this object type.
|
135
|
+
#
|
136
|
+
def self.help
|
137
|
+
return <<~TEXT
|
138
|
+
URI OBJECT TYPE
|
139
|
+
NAME: uri
|
140
|
+
SHORTCUT: url
|
141
|
+
|
142
|
+
DESCRIPTION
|
143
|
+
A URI or URL.
|
144
|
+
|
145
|
+
CHILDREN
|
146
|
+
None
|
147
|
+
|
148
|
+
MESSAGES
|
149
|
+
open - open the URL in the default browser
|
150
|
+
get_scheme - get the URI scheme; example: http
|
151
|
+
get_host - get the URI host; example: google.com
|
152
|
+
get_path - get the URI resource path; example: /post
|
153
|
+
get_query - get the URI query parameterse; example: id=121
|
154
|
+
get_fragment - get the URI fragment
|
155
|
+
TEXT
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|