gloo 0.7.7 → 1.1.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/.gitignore +2 -1
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/LICENSE.txt +1 -1
- data/gloo.gemspec +15 -6
- data/lib/VERSION +1 -1
- data/lib/dependencies.rb +4 -4
- data/lib/gloo/app/info.rb +3 -1
- data/lib/gloo/app/log.rb +1 -29
- data/lib/gloo/app/platform.rb +142 -0
- data/lib/gloo/objs/cli/banner.rb +2 -2
- data/lib/gloo/objs/cli/bar.rb +4 -4
- data/lib/gloo/objs/cli/colorize.rb +3 -3
- data/lib/gloo/objs/cli/confirm.rb +3 -3
- data/lib/gloo/objs/cli/menu.rb +9 -9
- data/lib/gloo/objs/cli/menu_item.rb +2 -2
- data/lib/gloo/objs/cli/pastel.rb +2 -2
- data/lib/gloo/objs/cli/prompt.rb +4 -4
- data/lib/gloo/objs/cli/select.rb +4 -4
- data/lib/gloo/objs/dev/git.rb +7 -7
- data/lib/gloo/objs/dev/stats.rb +8 -5
- data/lib/gloo/objs/snd/play.rb +1 -1
- data/lib/gloo/objs/snd/say.rb +2 -2
- data/lib/gloo/objs/system/file_handle.rb +9 -9
- data/lib/gloo/objs/system/ssh_exec.rb +3 -3
- data/lib/gloo/objs/system/system.rb +2 -2
- data/lib/gloo/verbs/alert.rb +7 -7
- data/lib/gloo/verbs/beep.rb +1 -1
- data/lib/gloo/verbs/cls.rb +2 -2
- data/lib/gloo/verbs/help.rb +7 -189
- data/lib/gloo/verbs/version.rb +3 -3
- data/lib/gloo.rb +5 -1
- data/lib/run.rb +5 -1
- metadata +43 -221
- data/Gemfile.lock +0 -168
- data/lib/gloo/app/args.rb +0 -112
- data/lib/gloo/app/engine.rb +0 -230
- data/lib/gloo/app/help.rb +0 -156
- data/lib/gloo/app/mode.rb +0 -27
- data/lib/gloo/app/settings.rb +0 -186
- data/lib/gloo/convert/converter.rb +0 -35
- data/lib/gloo/convert/string_to_datetime.rb +0 -21
- data/lib/gloo/convert/string_to_decimal.rb +0 -20
- data/lib/gloo/convert/string_to_integer.rb +0 -20
- data/lib/gloo/core/baseo.rb +0 -30
- data/lib/gloo/core/dictionary.rb +0 -181
- data/lib/gloo/core/error.rb +0 -61
- data/lib/gloo/core/event_manager.rb +0 -44
- data/lib/gloo/core/factory.rb +0 -210
- data/lib/gloo/core/gloo_system.rb +0 -266
- data/lib/gloo/core/heap.rb +0 -52
- data/lib/gloo/core/here.rb +0 -36
- data/lib/gloo/core/it.rb +0 -36
- data/lib/gloo/core/literal.rb +0 -30
- data/lib/gloo/core/obj.rb +0 -303
- data/lib/gloo/core/obj_finder.rb +0 -30
- data/lib/gloo/core/op.rb +0 -40
- data/lib/gloo/core/parser.rb +0 -59
- data/lib/gloo/core/pn.rb +0 -188
- data/lib/gloo/core/tokens.rb +0 -165
- data/lib/gloo/core/verb.rb +0 -86
- data/lib/gloo/exec/action.rb +0 -48
- data/lib/gloo/exec/dispatch.rb +0 -40
- data/lib/gloo/exec/exec_env.rb +0 -74
- data/lib/gloo/exec/runner.rb +0 -45
- data/lib/gloo/exec/script.rb +0 -49
- data/lib/gloo/exec/stack.rb +0 -78
- data/lib/gloo/expr/expression.rb +0 -118
- data/lib/gloo/expr/l_boolean.rb +0 -36
- data/lib/gloo/expr/l_decimal.rb +0 -39
- data/lib/gloo/expr/l_integer.rb +0 -37
- data/lib/gloo/expr/l_string.rb +0 -58
- data/lib/gloo/expr/op_div.rb +0 -22
- data/lib/gloo/expr/op_minus.rb +0 -22
- data/lib/gloo/expr/op_mult.rb +0 -22
- data/lib/gloo/expr/op_plus.rb +0 -24
- data/lib/gloo/help/app/application.txt +0 -22
- data/lib/gloo/help/app/configuration.txt +0 -7
- data/lib/gloo/help/app/default_help.txt +0 -14
- data/lib/gloo/help/app/logging.txt +0 -16
- data/lib/gloo/help/core/color.txt +0 -31
- data/lib/gloo/help/core/error.txt +0 -33
- data/lib/gloo/help/core/events.txt +0 -21
- data/lib/gloo/help/core/gloo_system.txt +0 -57
- data/lib/gloo/help/core/here.txt +0 -30
- data/lib/gloo/help/core/it.txt +0 -23
- data/lib/gloo/help/core/ops.txt +0 -16
- data/lib/gloo/help/core/pathname.txt +0 -29
- data/lib/gloo/help/objs/basic/alias.txt +0 -36
- data/lib/gloo/help/objs/basic/boolean.txt +0 -28
- data/lib/gloo/help/objs/basic/container.txt +0 -33
- data/lib/gloo/help/objs/basic/decimal.txt +0 -28
- data/lib/gloo/help/objs/basic/integer.txt +0 -27
- data/lib/gloo/help/objs/basic/script.txt +0 -29
- data/lib/gloo/help/objs/basic/string.txt +0 -28
- data/lib/gloo/help/objs/basic/text.txt +0 -27
- data/lib/gloo/help/objs/basic/untyped.txt +0 -22
- data/lib/gloo/help/objs/cli/banner.txt +0 -49
- data/lib/gloo/help/objs/cli/bar.txt +0 -37
- data/lib/gloo/help/objs/cli/colorize.txt +0 -33
- data/lib/gloo/help/objs/cli/confirm.txt +0 -26
- data/lib/gloo/help/objs/cli/menu.txt +0 -44
- data/lib/gloo/help/objs/cli/menu_item.txt +0 -26
- data/lib/gloo/help/objs/cli/pastel.txt +0 -43
- data/lib/gloo/help/objs/cli/prompt.txt +0 -27
- data/lib/gloo/help/objs/cli/select.txt +0 -34
- data/lib/gloo/help/objs/ctrl/each.txt +0 -48
- data/lib/gloo/help/objs/ctrl/repeat.txt +0 -38
- data/lib/gloo/help/objs/data/markdown.txt +0 -25
- data/lib/gloo/help/objs/data/mysql.txt +0 -40
- data/lib/gloo/help/objs/data/query.txt +0 -37
- data/lib/gloo/help/objs/data/sqlite.txt +0 -26
- data/lib/gloo/help/objs/data/table.txt +0 -46
- data/lib/gloo/help/objs/dev/git_repo.txt +0 -36
- data/lib/gloo/help/objs/dev/stats.txt +0 -36
- data/lib/gloo/help/objs/dt/date.txt +0 -23
- data/lib/gloo/help/objs/dt/datetime.txt +0 -24
- data/lib/gloo/help/objs/dt/time.txt +0 -23
- data/lib/gloo/help/objs/ror/erb.txt +0 -37
- data/lib/gloo/help/objs/ror/eval.txt +0 -24
- data/lib/gloo/help/objs/snd/play.txt +0 -23
- data/lib/gloo/help/objs/snd/say.txt +0 -28
- data/lib/gloo/help/objs/system/file.txt +0 -48
- data/lib/gloo/help/objs/system/ssh_exec.txt +0 -30
- data/lib/gloo/help/objs/system/system.txt +0 -32
- data/lib/gloo/help/objs/web/http_get.txt +0 -35
- data/lib/gloo/help/objs/web/http_post.txt +0 -34
- data/lib/gloo/help/objs/web/json.txt +0 -34
- data/lib/gloo/help/objs/web/slack.txt +0 -33
- data/lib/gloo/help/objs/web/teams.txt +0 -30
- data/lib/gloo/help/objs/web/uri.txt +0 -38
- data/lib/gloo/help/verbs/alert.txt +0 -33
- data/lib/gloo/help/verbs/beep.txt +0 -25
- data/lib/gloo/help/verbs/cls.txt +0 -24
- data/lib/gloo/help/verbs/context.txt +0 -43
- data/lib/gloo/help/verbs/create.txt +0 -33
- data/lib/gloo/help/verbs/execute.txt +0 -27
- data/lib/gloo/help/verbs/help.txt +0 -34
- data/lib/gloo/help/verbs/if.txt +0 -37
- data/lib/gloo/help/verbs/list.txt +0 -34
- data/lib/gloo/help/verbs/load.txt +0 -38
- data/lib/gloo/help/verbs/move.txt +0 -42
- data/lib/gloo/help/verbs/put.txt +0 -38
- data/lib/gloo/help/verbs/quit.txt +0 -25
- data/lib/gloo/help/verbs/run.txt +0 -41
- data/lib/gloo/help/verbs/save.txt +0 -26
- data/lib/gloo/help/verbs/show.txt +0 -30
- data/lib/gloo/help/verbs/tell.txt +0 -34
- data/lib/gloo/help/verbs/unless.txt +0 -38
- data/lib/gloo/help/verbs/version.txt +0 -32
- data/lib/gloo/help/verbs/wait.txt +0 -29
- data/lib/gloo/objs/basic/alias.rb +0 -78
- data/lib/gloo/objs/basic/boolean.rb +0 -120
- data/lib/gloo/objs/basic/container.rb +0 -76
- data/lib/gloo/objs/basic/decimal.rb +0 -76
- data/lib/gloo/objs/basic/integer.rb +0 -73
- data/lib/gloo/objs/basic/script.rb +0 -99
- data/lib/gloo/objs/basic/string.rb +0 -77
- data/lib/gloo/objs/basic/text.rb +0 -87
- data/lib/gloo/objs/basic/untyped.rb +0 -41
- data/lib/gloo/objs/ctrl/each.rb +0 -279
- data/lib/gloo/objs/ctrl/repeat.rb +0 -108
- data/lib/gloo/objs/data/markdown.rb +0 -84
- data/lib/gloo/objs/data/mysql.rb +0 -192
- data/lib/gloo/objs/data/query.rb +0 -176
- data/lib/gloo/objs/data/sqlite.rb +0 -159
- data/lib/gloo/objs/data/table.rb +0 -140
- data/lib/gloo/objs/dt/date.rb +0 -50
- data/lib/gloo/objs/dt/datetime.rb +0 -62
- data/lib/gloo/objs/dt/time.rb +0 -50
- data/lib/gloo/objs/ror/erb.rb +0 -116
- data/lib/gloo/objs/ror/eval.rb +0 -107
- data/lib/gloo/objs/web/http_get.rb +0 -159
- data/lib/gloo/objs/web/http_post.rb +0 -183
- data/lib/gloo/objs/web/json.rb +0 -135
- data/lib/gloo/objs/web/slack.rb +0 -130
- data/lib/gloo/objs/web/teams.rb +0 -117
- data/lib/gloo/objs/web/uri.rb +0 -148
- data/lib/gloo/persist/file_loader.rb +0 -191
- data/lib/gloo/persist/file_saver.rb +0 -49
- data/lib/gloo/persist/file_storage.rb +0 -45
- data/lib/gloo/persist/line_splitter.rb +0 -81
- data/lib/gloo/persist/persist_man.rb +0 -120
- data/lib/gloo/utils/format.rb +0 -21
- data/lib/gloo/utils/stats.rb +0 -205
- data/lib/gloo/utils/words.rb +0 -19
- data/lib/gloo/verbs/context.rb +0 -62
- data/lib/gloo/verbs/create.rb +0 -68
- data/lib/gloo/verbs/execute.rb +0 -56
- data/lib/gloo/verbs/if.rb +0 -92
- data/lib/gloo/verbs/list.rb +0 -98
- data/lib/gloo/verbs/load.rb +0 -45
- data/lib/gloo/verbs/move.rb +0 -89
- data/lib/gloo/verbs/put.rb +0 -94
- data/lib/gloo/verbs/quit.rb +0 -40
- data/lib/gloo/verbs/run.rb +0 -75
- data/lib/gloo/verbs/save.rb +0 -39
- data/lib/gloo/verbs/show.rb +0 -64
- data/lib/gloo/verbs/tell.rb +0 -79
- data/lib/gloo/verbs/unless.rb +0 -92
- data/lib/gloo/verbs/wait.rb +0 -42
data/lib/gloo/app/engine.rb
DELETED
@@ -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
|
data/lib/gloo/app/help.rb
DELETED
@@ -1,156 +0,0 @@
|
|
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
|
-
require 'tty-markdown'
|
8
|
-
require 'tty-pager'
|
9
|
-
|
10
|
-
module Gloo
|
11
|
-
module App
|
12
|
-
class Help
|
13
|
-
|
14
|
-
APPLICATION = 'application'.freeze
|
15
|
-
|
16
|
-
attr_accessor :topics
|
17
|
-
|
18
|
-
#
|
19
|
-
# Set up the help system.
|
20
|
-
# We won't load help topics until we know we need them.
|
21
|
-
#
|
22
|
-
def initialize
|
23
|
-
@topics = nil
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
# Show application help.
|
28
|
-
# This is the what is shown when help is run from the CLI.
|
29
|
-
#
|
30
|
-
def show_app_help
|
31
|
-
puts Info.display_title unless $engine.args.quiet?
|
32
|
-
self.show_topic APPLICATION
|
33
|
-
end
|
34
|
-
|
35
|
-
#
|
36
|
-
# Check to see if there is a topic by the given name.
|
37
|
-
#
|
38
|
-
def topic?( name )
|
39
|
-
lazy_load_index
|
40
|
-
|
41
|
-
return @topics.key?( name )
|
42
|
-
end
|
43
|
-
|
44
|
-
#
|
45
|
-
# Is the current topic Markdown?
|
46
|
-
#
|
47
|
-
def topic_is_md?( name )
|
48
|
-
lazy_load_index
|
49
|
-
|
50
|
-
topic_file = @topics[ name ]
|
51
|
-
return topic_file.end_with? '.md'
|
52
|
-
end
|
53
|
-
|
54
|
-
#
|
55
|
-
# Show a help topic, optionally paginaged.
|
56
|
-
# If the content of the help page fits on a single
|
57
|
-
# screen, it won't paginate.
|
58
|
-
#
|
59
|
-
def page_topic( topic )
|
60
|
-
return if $engine.args.quiet?
|
61
|
-
|
62
|
-
data = self.get_topic_data( topic )
|
63
|
-
page = data.lines.count > Settings.page_size
|
64
|
-
if topic_is_md?( topic )
|
65
|
-
show_markdown_data( data, page )
|
66
|
-
else
|
67
|
-
show_text_data( data, page )
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
#
|
72
|
-
# Show a help topic.
|
73
|
-
#
|
74
|
-
def show_topic( topic )
|
75
|
-
return if $engine.args.quiet?
|
76
|
-
|
77
|
-
data = self.get_topic_data( topic )
|
78
|
-
if topic_is_md?( topic )
|
79
|
-
show_markdown_data data
|
80
|
-
else
|
81
|
-
show_text_data data
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
#
|
86
|
-
# Show the markdown data.
|
87
|
-
#
|
88
|
-
def show_text_data( data, page = false )
|
89
|
-
if page
|
90
|
-
pager = TTY::Pager.new
|
91
|
-
pager.page( data )
|
92
|
-
else
|
93
|
-
puts data.white
|
94
|
-
puts
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
#
|
99
|
-
# Show the markdown data.
|
100
|
-
#
|
101
|
-
def show_markdown_data( data, page = false )
|
102
|
-
md = TTY::Markdown.parse data
|
103
|
-
|
104
|
-
if page
|
105
|
-
pager = TTY::Pager.new
|
106
|
-
pager.page( md )
|
107
|
-
else
|
108
|
-
puts md
|
109
|
-
puts
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
#
|
114
|
-
# Get topic data.
|
115
|
-
#
|
116
|
-
def get_topic_data( topic )
|
117
|
-
lazy_load_index
|
118
|
-
|
119
|
-
topic_file = @topics[ topic ]
|
120
|
-
return nil unless topic_file
|
121
|
-
|
122
|
-
File.read topic_file
|
123
|
-
end
|
124
|
-
|
125
|
-
#
|
126
|
-
# Lazy load topic index.
|
127
|
-
# We'll only load the index the first time a help topic
|
128
|
-
# is requested. After that we'll use the cached index.
|
129
|
-
#
|
130
|
-
def lazy_load_index
|
131
|
-
return if @topics
|
132
|
-
|
133
|
-
@topics = {}
|
134
|
-
$log.debug 'loading help file index...'
|
135
|
-
|
136
|
-
pn = File.dirname( File.absolute_path( __FILE__ ) )
|
137
|
-
pn = File.dirname( pn )
|
138
|
-
|
139
|
-
root = File.join( pn, 'help', '**/*.txt' )
|
140
|
-
Dir.glob( root ).each do |txt_file|
|
141
|
-
key = File.basename( txt_file, '.txt' )
|
142
|
-
@topics[ key ] = txt_file
|
143
|
-
end
|
144
|
-
|
145
|
-
root = File.join( pn, 'help', '**/*.md' )
|
146
|
-
Dir.glob( root ).each do |md_file|
|
147
|
-
key = File.basename( md_file, '.md' )
|
148
|
-
@topics[ key ] = md_file
|
149
|
-
end
|
150
|
-
|
151
|
-
$log.debug "Found #{@topics.count} help files"
|
152
|
-
end
|
153
|
-
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
data/lib/gloo/app/mode.rb
DELETED
@@ -1,27 +0,0 @@
|
|
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 Gloo
|
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
|
data/lib/gloo/app/settings.rb
DELETED
@@ -1,186 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# Application and user settings.
|
5
|
-
#
|
6
|
-
|
7
|
-
require 'yaml'
|
8
|
-
require 'tty-screen'
|
9
|
-
require 'colorize'
|
10
|
-
|
11
|
-
module Gloo
|
12
|
-
module App
|
13
|
-
class Settings
|
14
|
-
|
15
|
-
attr_reader :user_root, :log_path, :config_path, :project_path,
|
16
|
-
:start_with, :list_indent, :tmp_path,
|
17
|
-
:debug_path, :debug
|
18
|
-
|
19
|
-
#
|
20
|
-
# Load setting from the yml file.
|
21
|
-
# The mode parameter is used to determine if we are running in TEST.
|
22
|
-
#
|
23
|
-
def initialize( mode )
|
24
|
-
@mode = mode
|
25
|
-
init_root
|
26
|
-
init_path_settings
|
27
|
-
init_user_settings
|
28
|
-
end
|
29
|
-
|
30
|
-
#
|
31
|
-
# Are we in test mode?
|
32
|
-
#
|
33
|
-
def in_test_mode?
|
34
|
-
return @mode == 'TEST'
|
35
|
-
end
|
36
|
-
|
37
|
-
#
|
38
|
-
# Get the project path for the current mode.
|
39
|
-
#
|
40
|
-
def project_path_for_mode( settings )
|
41
|
-
return File.join( @user_root, 'projects' ) if in_test_mode?
|
42
|
-
|
43
|
-
return settings[ 'gloo' ][ 'project_path' ]
|
44
|
-
end
|
45
|
-
|
46
|
-
#
|
47
|
-
# Show the current application settings.
|
48
|
-
# Can be seen in app with 'help settings'
|
49
|
-
#
|
50
|
-
def show
|
51
|
-
puts "\nApplication Settings:".blue
|
52
|
-
puts ' Startup with: '.yellow + @start_with.white
|
53
|
-
puts ' Indent in Listing: '.yellow + @list_indent.to_s.white
|
54
|
-
puts ' Screen Lines: '.yellow + Gloo::App::Settings.lines.to_s.white
|
55
|
-
puts ' Page Size: '.yellow + Gloo::App::Settings.page_size.to_s.white
|
56
|
-
puts ''
|
57
|
-
self.show_paths
|
58
|
-
puts ''
|
59
|
-
end
|
60
|
-
|
61
|
-
#
|
62
|
-
# Show path settings
|
63
|
-
#
|
64
|
-
def show_paths
|
65
|
-
puts ' User Root Path is here: '.yellow + @user_root.white
|
66
|
-
puts ' Projects Path: '.yellow + @project_path.white
|
67
|
-
puts ' Tmp Path: '.yellow + @tmp_path.white
|
68
|
-
puts ' Debug Path: '.yellow + @debug_path.white
|
69
|
-
end
|
70
|
-
|
71
|
-
#
|
72
|
-
# Get the number of vertical lines on screen.
|
73
|
-
#
|
74
|
-
def self.lines
|
75
|
-
TTY::Screen.rows
|
76
|
-
end
|
77
|
-
|
78
|
-
#
|
79
|
-
# Get the number of horizontal columns on screen.
|
80
|
-
#
|
81
|
-
def self.cols
|
82
|
-
TTY::Screen.cols
|
83
|
-
end
|
84
|
-
|
85
|
-
#
|
86
|
-
# Get the default page size.
|
87
|
-
# This is the number of lines of text we can show.
|
88
|
-
#
|
89
|
-
def self.page_size
|
90
|
-
Settings.lines - 3
|
91
|
-
end
|
92
|
-
|
93
|
-
#
|
94
|
-
# How many lines should we use for a preview?
|
95
|
-
#
|
96
|
-
def self.preview_lines
|
97
|
-
return 7
|
98
|
-
end
|
99
|
-
|
100
|
-
# ---------------------------------------------------------------------
|
101
|
-
# Private
|
102
|
-
# ---------------------------------------------------------------------
|
103
|
-
|
104
|
-
private
|
105
|
-
|
106
|
-
#
|
107
|
-
# Initialize gloo's root path.
|
108
|
-
#
|
109
|
-
def init_root
|
110
|
-
if in_test_mode?
|
111
|
-
path = File.dirname( File.dirname( File.absolute_path( __FILE__ ) ) )
|
112
|
-
path = File.dirname( File.dirname( path ) )
|
113
|
-
path = File.join( path, 'test', 'gloo' )
|
114
|
-
@user_root = path
|
115
|
-
else
|
116
|
-
@user_root = File.join( Dir.home, 'gloo' )
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
#
|
121
|
-
# Get the app's required directories.
|
122
|
-
#
|
123
|
-
def init_path_settings
|
124
|
-
Dir.mkdir( @user_root ) unless File.exist?( @user_root )
|
125
|
-
|
126
|
-
@log_path = File.join( @user_root, 'logs' )
|
127
|
-
Dir.mkdir( @log_path ) unless File.exist?( @log_path )
|
128
|
-
|
129
|
-
@config_path = File.join( @user_root, 'config' )
|
130
|
-
Dir.mkdir( @config_path ) unless File.exist?( @config_path )
|
131
|
-
|
132
|
-
@tmp_path = File.join( @user_root, 'tmp' )
|
133
|
-
Dir.mkdir( @tmp_path ) unless File.exist?( @tmp_path )
|
134
|
-
|
135
|
-
@debug_path = File.join( @user_root, 'debug' )
|
136
|
-
Dir.mkdir( @debug_path ) unless File.exist?( @debug_path )
|
137
|
-
end
|
138
|
-
|
139
|
-
#
|
140
|
-
# Initialize the user settings for the currently
|
141
|
-
# running environment.
|
142
|
-
#
|
143
|
-
def init_user_settings
|
144
|
-
settings = get_settings
|
145
|
-
|
146
|
-
@project_path = project_path_for_mode settings
|
147
|
-
@start_with = settings[ 'gloo' ][ 'start_with' ]
|
148
|
-
@list_indent = settings[ 'gloo' ][ 'list_indent' ]
|
149
|
-
|
150
|
-
@debug = settings[ 'gloo' ][ 'debug' ]
|
151
|
-
end
|
152
|
-
|
153
|
-
#
|
154
|
-
# Get the app's required directories.
|
155
|
-
#
|
156
|
-
def get_settings
|
157
|
-
f = File.join( @config_path, 'gloo.yml' )
|
158
|
-
create_settings( f ) unless File.exist?( f )
|
159
|
-
return YAML.load_file f
|
160
|
-
end
|
161
|
-
|
162
|
-
#
|
163
|
-
# Create settings file.
|
164
|
-
#
|
165
|
-
def create_settings( file )
|
166
|
-
IO.write( file, get_default_settings )
|
167
|
-
end
|
168
|
-
|
169
|
-
#
|
170
|
-
# Get the value for default settings.
|
171
|
-
#
|
172
|
-
def get_default_settings
|
173
|
-
projects = File.join( @user_root, 'projects' )
|
174
|
-
str = <<~TEXT
|
175
|
-
gloo:
|
176
|
-
project_path: #{projects}
|
177
|
-
start_with:
|
178
|
-
list_indent: 1
|
179
|
-
debug: false
|
180
|
-
TEXT
|
181
|
-
return str
|
182
|
-
end
|
183
|
-
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# Data conversion manager.
|
5
|
-
#
|
6
|
-
|
7
|
-
module Gloo
|
8
|
-
module Convert
|
9
|
-
class Converter
|
10
|
-
|
11
|
-
# ---------------------------------------------------------------------
|
12
|
-
# Convert
|
13
|
-
# ---------------------------------------------------------------------
|
14
|
-
|
15
|
-
#
|
16
|
-
# Convert the given value to the specified type,
|
17
|
-
# or if no conversion is available, revert to default.
|
18
|
-
#
|
19
|
-
def convert( value, to_type, default = nil )
|
20
|
-
begin
|
21
|
-
name = "Gloo::Convert::#{value.class}To#{to_type}"
|
22
|
-
clazz = name.split( '::' ).inject( Object ) { |o, c| o.const_get c }
|
23
|
-
o = clazz.new
|
24
|
-
return o.convert( value )
|
25
|
-
rescue => e
|
26
|
-
$log.error e.message
|
27
|
-
$engine.heap.error.set_to e.message
|
28
|
-
end
|
29
|
-
|
30
|
-
return default
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# Conversion tool: String to Date Time.
|
5
|
-
#
|
6
|
-
require 'chronic'
|
7
|
-
|
8
|
-
module Gloo
|
9
|
-
module Convert
|
10
|
-
class StringToDateTime
|
11
|
-
|
12
|
-
#
|
13
|
-
# Convert the given string value to a date and time.
|
14
|
-
#
|
15
|
-
def convert( value )
|
16
|
-
return Chronic.parse( value )
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# Conversion tool: String to Decimal.
|
5
|
-
#
|
6
|
-
|
7
|
-
module Gloo
|
8
|
-
module Convert
|
9
|
-
class StringToDecimal
|
10
|
-
|
11
|
-
#
|
12
|
-
# Convert the given string value to an integer.
|
13
|
-
#
|
14
|
-
def convert( value )
|
15
|
-
return value.to_f
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# Conversion tool: String to Integer.
|
5
|
-
#
|
6
|
-
|
7
|
-
module Gloo
|
8
|
-
module Convert
|
9
|
-
class StringToInteger
|
10
|
-
|
11
|
-
#
|
12
|
-
# Convert the given string value to an integer.
|
13
|
-
#
|
14
|
-
def convert( value )
|
15
|
-
return value.to_i
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|