gloo-lang 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/VERSION +1 -1
- data/lib/dependencies.rb +2 -2
- data/lib/gloo-lang.rb +1 -5
- data/lib/gloo_lang/app/args.rb +112 -0
- data/lib/gloo_lang/app/engine.rb +230 -0
- data/lib/gloo_lang/app/help.rb +156 -0
- data/lib/gloo_lang/app/log.rb +81 -0
- data/lib/gloo_lang/app/mode.rb +27 -0
- data/lib/gloo_lang/app/settings.rb +186 -0
- data/lib/gloo_lang/convert/converter.rb +35 -0
- data/lib/gloo_lang/convert/string_to_datetime.rb +21 -0
- data/lib/gloo_lang/convert/string_to_decimal.rb +20 -0
- data/lib/gloo_lang/convert/string_to_integer.rb +20 -0
- data/lib/gloo_lang/core/baseo.rb +30 -0
- data/lib/gloo_lang/core/dictionary.rb +181 -0
- data/lib/gloo_lang/core/error.rb +61 -0
- data/lib/gloo_lang/core/event_manager.rb +44 -0
- data/lib/gloo_lang/core/factory.rb +210 -0
- data/lib/gloo_lang/core/gloo_system.rb +266 -0
- data/lib/gloo_lang/core/heap.rb +52 -0
- data/lib/gloo_lang/core/here.rb +36 -0
- data/lib/gloo_lang/core/it.rb +36 -0
- data/lib/gloo_lang/core/literal.rb +30 -0
- data/lib/gloo_lang/core/obj.rb +303 -0
- data/lib/gloo_lang/core/obj_finder.rb +30 -0
- data/lib/gloo_lang/core/op.rb +40 -0
- data/lib/gloo_lang/core/parser.rb +59 -0
- data/lib/gloo_lang/core/pn.rb +188 -0
- data/lib/gloo_lang/core/tokens.rb +165 -0
- data/lib/gloo_lang/core/verb.rb +86 -0
- data/lib/gloo_lang/exec/action.rb +48 -0
- data/lib/gloo_lang/exec/dispatch.rb +40 -0
- data/lib/gloo_lang/exec/exec_env.rb +74 -0
- data/lib/gloo_lang/exec/runner.rb +45 -0
- data/lib/gloo_lang/exec/script.rb +49 -0
- data/lib/gloo_lang/exec/stack.rb +78 -0
- data/lib/gloo_lang/expr/expression.rb +118 -0
- data/lib/gloo_lang/expr/l_boolean.rb +36 -0
- data/lib/gloo_lang/expr/l_decimal.rb +39 -0
- data/lib/gloo_lang/expr/l_integer.rb +37 -0
- data/lib/gloo_lang/expr/l_string.rb +58 -0
- data/lib/gloo_lang/expr/op_div.rb +22 -0
- data/lib/gloo_lang/expr/op_minus.rb +22 -0
- data/lib/gloo_lang/expr/op_mult.rb +22 -0
- data/lib/gloo_lang/expr/op_plus.rb +24 -0
- data/lib/gloo_lang/help/app/application.txt +22 -0
- data/lib/gloo_lang/help/app/configuration.txt +7 -0
- data/lib/gloo_lang/help/app/default_help.txt +14 -0
- data/lib/gloo_lang/help/app/logging.txt +16 -0
- data/lib/gloo_lang/help/core/color.txt +31 -0
- data/lib/gloo_lang/help/core/error.txt +33 -0
- data/lib/gloo_lang/help/core/events.txt +21 -0
- data/lib/gloo_lang/help/core/gloo_system.txt +57 -0
- data/lib/gloo_lang/help/core/here.txt +30 -0
- data/lib/gloo_lang/help/core/it.txt +23 -0
- data/lib/gloo_lang/help/core/ops.txt +16 -0
- data/lib/gloo_lang/help/core/pathname.txt +29 -0
- data/lib/gloo_lang/help/objs/basic/alias.txt +36 -0
- data/lib/gloo_lang/help/objs/basic/boolean.txt +28 -0
- data/lib/gloo_lang/help/objs/basic/container.txt +33 -0
- data/lib/gloo_lang/help/objs/basic/decimal.txt +28 -0
- data/lib/gloo_lang/help/objs/basic/integer.txt +27 -0
- data/lib/gloo_lang/help/objs/basic/script.txt +29 -0
- data/lib/gloo_lang/help/objs/basic/string.txt +28 -0
- data/lib/gloo_lang/help/objs/basic/text.txt +27 -0
- data/lib/gloo_lang/help/objs/basic/untyped.txt +22 -0
- data/lib/gloo_lang/help/objs/cli/banner.txt +49 -0
- data/lib/gloo_lang/help/objs/cli/bar.txt +37 -0
- data/lib/gloo_lang/help/objs/cli/colorize.txt +33 -0
- data/lib/gloo_lang/help/objs/cli/confirm.txt +26 -0
- data/lib/gloo_lang/help/objs/cli/menu.txt +44 -0
- data/lib/gloo_lang/help/objs/cli/menu_item.txt +26 -0
- data/lib/gloo_lang/help/objs/cli/pastel.txt +43 -0
- data/lib/gloo_lang/help/objs/cli/prompt.txt +27 -0
- data/lib/gloo_lang/help/objs/cli/select.txt +34 -0
- data/lib/gloo_lang/help/objs/ctrl/each.txt +48 -0
- data/lib/gloo_lang/help/objs/ctrl/repeat.txt +38 -0
- data/lib/gloo_lang/help/objs/data/markdown.txt +25 -0
- data/lib/gloo_lang/help/objs/data/mysql.txt +40 -0
- data/lib/gloo_lang/help/objs/data/query.txt +37 -0
- data/lib/gloo_lang/help/objs/data/sqlite.txt +26 -0
- data/lib/gloo_lang/help/objs/data/table.txt +46 -0
- data/lib/gloo_lang/help/objs/dev/git_repo.txt +36 -0
- data/lib/gloo_lang/help/objs/dev/stats.txt +36 -0
- data/lib/gloo_lang/help/objs/dt/date.txt +23 -0
- data/lib/gloo_lang/help/objs/dt/datetime.txt +24 -0
- data/lib/gloo_lang/help/objs/dt/time.txt +23 -0
- data/lib/gloo_lang/help/objs/ror/erb.txt +37 -0
- data/lib/gloo_lang/help/objs/ror/eval.txt +24 -0
- data/lib/gloo_lang/help/objs/snd/play.txt +23 -0
- data/lib/gloo_lang/help/objs/snd/say.txt +28 -0
- data/lib/gloo_lang/help/objs/system/file.txt +48 -0
- data/lib/gloo_lang/help/objs/system/ssh_exec.txt +30 -0
- data/lib/gloo_lang/help/objs/system/system.txt +32 -0
- data/lib/gloo_lang/help/objs/web/http_get.txt +35 -0
- data/lib/gloo_lang/help/objs/web/http_post.txt +34 -0
- data/lib/gloo_lang/help/objs/web/json.txt +34 -0
- data/lib/gloo_lang/help/objs/web/slack.txt +33 -0
- data/lib/gloo_lang/help/objs/web/teams.txt +30 -0
- data/lib/gloo_lang/help/objs/web/uri.txt +38 -0
- data/lib/gloo_lang/help/verbs/alert.txt +33 -0
- data/lib/gloo_lang/help/verbs/beep.txt +25 -0
- data/lib/gloo_lang/help/verbs/cls.txt +24 -0
- data/lib/gloo_lang/help/verbs/context.txt +43 -0
- data/lib/gloo_lang/help/verbs/create.txt +33 -0
- data/lib/gloo_lang/help/verbs/execute.txt +27 -0
- data/lib/gloo_lang/help/verbs/help.txt +34 -0
- data/lib/gloo_lang/help/verbs/if.txt +37 -0
- data/lib/gloo_lang/help/verbs/list.txt +34 -0
- data/lib/gloo_lang/help/verbs/load.txt +38 -0
- data/lib/gloo_lang/help/verbs/move.txt +42 -0
- data/lib/gloo_lang/help/verbs/put.txt +38 -0
- data/lib/gloo_lang/help/verbs/quit.txt +25 -0
- data/lib/gloo_lang/help/verbs/run.txt +41 -0
- data/lib/gloo_lang/help/verbs/save.txt +26 -0
- data/lib/gloo_lang/help/verbs/show.txt +30 -0
- data/lib/gloo_lang/help/verbs/tell.txt +34 -0
- data/lib/gloo_lang/help/verbs/unless.txt +38 -0
- data/lib/gloo_lang/help/verbs/version.txt +32 -0
- data/lib/gloo_lang/help/verbs/wait.txt +29 -0
- data/lib/gloo_lang/objs/basic/alias.rb +78 -0
- data/lib/gloo_lang/objs/basic/boolean.rb +120 -0
- data/lib/gloo_lang/objs/basic/container.rb +76 -0
- data/lib/gloo_lang/objs/basic/decimal.rb +76 -0
- data/lib/gloo_lang/objs/basic/integer.rb +73 -0
- data/lib/gloo_lang/objs/basic/script.rb +99 -0
- data/lib/gloo_lang/objs/basic/string.rb +77 -0
- data/lib/gloo_lang/objs/basic/text.rb +87 -0
- data/lib/gloo_lang/objs/basic/untyped.rb +41 -0
- data/lib/gloo_lang/objs/cli/banner.rb +108 -0
- data/lib/gloo_lang/objs/cli/bar.rb +133 -0
- data/lib/gloo_lang/objs/cli/colorize.rb +73 -0
- data/lib/gloo_lang/objs/cli/confirm.rb +96 -0
- data/lib/gloo_lang/objs/cli/menu.rb +206 -0
- data/lib/gloo_lang/objs/cli/menu_item.rb +95 -0
- data/lib/gloo_lang/objs/cli/pastel.rb +97 -0
- data/lib/gloo_lang/objs/cli/prompt.rb +110 -0
- data/lib/gloo_lang/objs/cli/select.rb +126 -0
- data/lib/gloo_lang/objs/ctrl/each.rb +279 -0
- data/lib/gloo_lang/objs/ctrl/repeat.rb +108 -0
- data/lib/gloo_lang/objs/data/markdown.rb +84 -0
- data/lib/gloo_lang/objs/data/mysql.rb +192 -0
- data/lib/gloo_lang/objs/data/query.rb +176 -0
- data/lib/gloo_lang/objs/data/sqlite.rb +159 -0
- data/lib/gloo_lang/objs/data/table.rb +140 -0
- data/lib/gloo_lang/objs/dev/git.rb +140 -0
- data/lib/gloo_lang/objs/dev/stats.rb +120 -0
- data/lib/gloo_lang/objs/dt/date.rb +50 -0
- data/lib/gloo_lang/objs/dt/datetime.rb +62 -0
- data/lib/gloo_lang/objs/dt/time.rb +50 -0
- data/lib/gloo_lang/objs/ror/erb.rb +116 -0
- data/lib/gloo_lang/objs/ror/eval.rb +107 -0
- data/lib/gloo_lang/objs/snd/play.rb +48 -0
- data/lib/gloo_lang/objs/snd/say.rb +98 -0
- data/lib/gloo_lang/objs/system/file_handle.rb +138 -0
- data/lib/gloo_lang/objs/system/ssh_exec.rb +126 -0
- data/lib/gloo_lang/objs/system/system.rb +136 -0
- data/lib/gloo_lang/objs/web/http_get.rb +159 -0
- data/lib/gloo_lang/objs/web/http_post.rb +183 -0
- data/lib/gloo_lang/objs/web/json.rb +135 -0
- data/lib/gloo_lang/objs/web/slack.rb +130 -0
- data/lib/gloo_lang/objs/web/teams.rb +117 -0
- data/lib/gloo_lang/objs/web/uri.rb +148 -0
- data/lib/gloo_lang/persist/file_loader.rb +191 -0
- data/lib/gloo_lang/persist/file_saver.rb +49 -0
- data/lib/gloo_lang/persist/file_storage.rb +45 -0
- data/lib/gloo_lang/persist/line_splitter.rb +81 -0
- data/lib/gloo_lang/persist/persist_man.rb +120 -0
- data/lib/gloo_lang/utils/format.rb +21 -0
- data/lib/gloo_lang/utils/stats.rb +205 -0
- data/lib/gloo_lang/utils/words.rb +19 -0
- data/lib/gloo_lang/verbs/alert.rb +79 -0
- data/lib/gloo_lang/verbs/beep.rb +40 -0
- data/lib/gloo_lang/verbs/cls.rb +37 -0
- data/lib/gloo_lang/verbs/context.rb +62 -0
- data/lib/gloo_lang/verbs/create.rb +68 -0
- data/lib/gloo_lang/verbs/execute.rb +56 -0
- data/lib/gloo_lang/verbs/help.rb +264 -0
- data/lib/gloo_lang/verbs/if.rb +92 -0
- data/lib/gloo_lang/verbs/list.rb +98 -0
- data/lib/gloo_lang/verbs/load.rb +45 -0
- data/lib/gloo_lang/verbs/move.rb +89 -0
- data/lib/gloo_lang/verbs/put.rb +94 -0
- data/lib/gloo_lang/verbs/quit.rb +40 -0
- data/lib/gloo_lang/verbs/run.rb +75 -0
- data/lib/gloo_lang/verbs/save.rb +39 -0
- data/lib/gloo_lang/verbs/show.rb +64 -0
- data/lib/gloo_lang/verbs/tell.rb +79 -0
- data/lib/gloo_lang/verbs/unless.rb +92 -0
- data/lib/gloo_lang/verbs/version.rb +37 -0
- data/lib/gloo_lang/verbs/wait.rb +42 -0
- metadata +190 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a97b50f311067cb36399d283816c85ab0ca4756ffbd1e9c90c06776be38cf5fa
|
4
|
+
data.tar.gz: c5bdb27db5edcb57fab3ec8bd0e50a4a2e6a2cd7f6c1b46001741da96c5b68c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc547e429ebe3ee5cc948d7647ef6a5226fa4d499adb467b832a276d1d9b83fb2f3ad56f91d1bc2033df46c3241f02257e05ea02369ad41f90a74897bbeab105
|
7
|
+
data.tar.gz: c415a1953ceb79b38e6b445cecf566547fa5d1fcac4cd6b8b93f980dcdf087d4ecb4ed31b317b8cb2354c560905329e3e9e9473691b19dc68fe8fa1a2af6bdd6
|
data/lib/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.3
|
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
|
-
|
15
|
-
|
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
|
-
#
|
15
|
+
# GlooLang::App::Engine.new( params ).start
|
20
16
|
# end
|
21
17
|
end
|
@@ -0,0 +1,112 @@
|
|
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
|
+
require 'colorize'
|
10
|
+
|
11
|
+
module GlooLang
|
12
|
+
module App
|
13
|
+
class Args
|
14
|
+
|
15
|
+
QUIET = 'quiet'.freeze
|
16
|
+
GLOO_ENV = 'GLOO_ENV'.freeze
|
17
|
+
|
18
|
+
attr_reader :switches, :files
|
19
|
+
|
20
|
+
#
|
21
|
+
# Create arguments and setup.
|
22
|
+
#
|
23
|
+
def initialize( params = [] )
|
24
|
+
@switches = []
|
25
|
+
@files = []
|
26
|
+
|
27
|
+
params.each { |o| process_one_arg( o ) }
|
28
|
+
ARGV.each { |o| process_one_arg( o ) }
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Was the --quiet arg passed?
|
33
|
+
#
|
34
|
+
def quiet?
|
35
|
+
return @switches.include?( QUIET )
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Is the version switch set?
|
40
|
+
#
|
41
|
+
def version?
|
42
|
+
@switches.include?( GlooLang::App::Mode::VERSION.to_s )
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Is the help switch set?
|
47
|
+
#
|
48
|
+
def help?
|
49
|
+
@switches.include?( GlooLang::App::Mode::HELP.to_s )
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Is the cli switch set?
|
54
|
+
#
|
55
|
+
def cli?
|
56
|
+
@switches.include?( GlooLang::App::Mode::CLI.to_s )
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# Is the embed switch set?
|
61
|
+
#
|
62
|
+
def embed?
|
63
|
+
@switches.include?( GlooLang::App::Mode::EMBED.to_s )
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# Detect the mode to be run in.
|
68
|
+
# Start by seeing if a mode is specified.
|
69
|
+
# Then look for the presence of files.
|
70
|
+
# Then finally use the default: embedded mode.
|
71
|
+
#
|
72
|
+
def detect_mode
|
73
|
+
mode = if ENV[ GLOO_ENV ] == GlooLang::App::Mode::TEST.to_s
|
74
|
+
Mode::TEST
|
75
|
+
elsif version?
|
76
|
+
Mode::VERSION
|
77
|
+
elsif help?
|
78
|
+
Mode::HELP
|
79
|
+
elsif cli?
|
80
|
+
Mode::CLI
|
81
|
+
elsif embed?
|
82
|
+
Mode::EMBED
|
83
|
+
elsif @files.count.positive?
|
84
|
+
Mode::SCRIPT
|
85
|
+
else
|
86
|
+
Mode.default_mode
|
87
|
+
end
|
88
|
+
$log.debug "running in #{mode} mode"
|
89
|
+
|
90
|
+
return mode
|
91
|
+
end
|
92
|
+
|
93
|
+
# ---------------------------------------------------------------------
|
94
|
+
# Private
|
95
|
+
# ---------------------------------------------------------------------
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
#
|
100
|
+
# Process one argument or parameter.
|
101
|
+
#
|
102
|
+
def process_one_arg( arg )
|
103
|
+
if arg.start_with? '--'
|
104
|
+
switches << arg[ 2..-1 ]
|
105
|
+
else
|
106
|
+
files << arg
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,230 @@
|
|
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 GlooLang
|
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 = GlooLang::Core::Dictionary.instance
|
46
|
+
@dictionary.init
|
47
|
+
@parser = GlooLang::Core::Parser.new
|
48
|
+
@heap = GlooLang::Core::Heap.new
|
49
|
+
@factory = GlooLang::Core::Factory.new
|
50
|
+
@persist_man = GlooLang::Persist::PersistMan.new
|
51
|
+
@event_manager = GlooLang::Core::EventManager.new
|
52
|
+
|
53
|
+
@exec_env = GlooLang::Exec::ExecEnv.new
|
54
|
+
@help = GlooLang::App::Help.new
|
55
|
+
@converter = GlooLang::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
|
@@ -0,0 +1,156 @@
|
|
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 GlooLang
|
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
|
@@ -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
|