gloo 0.5.4 → 0.7.2
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/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/lib/gloo/app/args.rb +48 -6
- data/lib/gloo/app/engine.rb +60 -38
- data/lib/gloo/app/help.rb +137 -16
- data/lib/gloo/app/info.rb +3 -1
- data/lib/gloo/app/log.rb +23 -0
- data/lib/gloo/app/mode.rb +2 -0
- data/lib/gloo/app/settings.rb +98 -47
- data/lib/gloo/convert/converter.rb +35 -0
- data/lib/gloo/convert/string_to_datetime.rb +1 -1
- data/lib/gloo/convert/string_to_decimal.rb +1 -1
- data/lib/gloo/convert/string_to_integer.rb +1 -1
- data/lib/gloo/core/dictionary.rb +99 -22
- data/lib/gloo/core/error.rb +19 -8
- data/lib/gloo/core/event_manager.rb +4 -0
- data/lib/gloo/core/factory.rb +11 -0
- data/lib/gloo/core/gloo_system.rb +1 -1
- data/lib/gloo/core/heap.rb +11 -3
- data/lib/gloo/core/here.rb +36 -0
- data/lib/gloo/core/it.rb +6 -0
- data/lib/gloo/core/literal.rb +5 -0
- data/lib/gloo/core/obj.rb +22 -0
- data/lib/gloo/core/op.rb +7 -0
- data/lib/gloo/core/parser.rb +6 -0
- data/lib/gloo/core/pn.rb +38 -0
- data/lib/gloo/core/tokens.rb +66 -22
- data/lib/gloo/core/verb.rb +12 -0
- data/lib/gloo/exec/action.rb +48 -0
- data/lib/gloo/exec/dispatch.rb +15 -5
- data/lib/gloo/exec/exec_env.rb +74 -0
- data/lib/gloo/exec/runner.rb +4 -2
- data/lib/gloo/{core → exec}/script.rb +21 -9
- data/lib/gloo/exec/stack.rb +78 -0
- data/lib/gloo/expr/expression.rb +26 -4
- data/lib/gloo/expr/l_boolean.rb +6 -0
- data/lib/gloo/expr/l_decimal.rb +5 -0
- data/lib/gloo/expr/l_integer.rb +7 -0
- data/lib/gloo/expr/l_string.rb +7 -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/help/app/application.txt +22 -0
- data/lib/gloo/help/app/configuration.txt +7 -0
- data/lib/gloo/help/app/default_help.txt +14 -0
- data/lib/gloo/help/app/logging.txt +16 -0
- data/lib/gloo/help/core/color.txt +31 -0
- data/lib/gloo/help/core/error.txt +33 -0
- data/lib/gloo/help/core/events.txt +21 -0
- data/lib/gloo/help/core/gloo_system.txt +54 -0
- data/lib/gloo/help/core/here.txt +30 -0
- data/lib/gloo/help/core/it.txt +23 -0
- data/lib/gloo/help/core/ops.txt +16 -0
- data/lib/gloo/help/core/pathname.txt +29 -0
- data/lib/gloo/help/objs/basic/alias.txt +36 -0
- data/lib/gloo/help/objs/basic/boolean.txt +28 -0
- data/lib/gloo/help/objs/basic/container.txt +33 -0
- data/lib/gloo/help/objs/basic/decimal.txt +28 -0
- data/lib/gloo/help/objs/basic/integer.txt +27 -0
- data/lib/gloo/help/objs/basic/script.txt +29 -0
- data/lib/gloo/help/objs/basic/string.txt +28 -0
- data/lib/gloo/help/objs/basic/text.txt +27 -0
- data/lib/gloo/help/objs/basic/untyped.txt +22 -0
- data/lib/gloo/help/objs/cli/banner.txt +49 -0
- data/lib/gloo/help/objs/cli/bar.txt +34 -0
- data/lib/gloo/help/objs/cli/colorize.txt +33 -0
- data/lib/gloo/help/objs/cli/confirm.txt +26 -0
- data/lib/gloo/help/objs/cli/menu.txt +44 -0
- data/lib/gloo/help/objs/cli/menu_item.txt +26 -0
- data/lib/gloo/help/objs/cli/pastel.txt +43 -0
- data/lib/gloo/help/objs/cli/prompt.txt +27 -0
- data/lib/gloo/help/objs/cli/select.txt +34 -0
- data/lib/gloo/help/objs/ctrl/each.txt +48 -0
- data/lib/gloo/help/objs/ctrl/repeat.txt +38 -0
- data/lib/gloo/help/objs/data/markdown.txt +25 -0
- data/lib/gloo/help/objs/data/table.txt +46 -0
- data/lib/gloo/help/objs/dev/git_repo.txt +35 -0
- data/lib/gloo/help/objs/dt/date.txt +23 -0
- data/lib/gloo/help/objs/dt/datetime.txt +24 -0
- data/lib/gloo/help/objs/dt/time.txt +23 -0
- data/lib/gloo/help/objs/ror/erb.txt +37 -0
- data/lib/gloo/help/objs/ror/eval.txt +24 -0
- data/lib/gloo/help/objs/snd/play.txt +23 -0
- data/lib/gloo/help/objs/snd/say.txt +28 -0
- data/lib/gloo/help/objs/system/file.txt +41 -0
- data/lib/gloo/help/objs/system/system.txt +32 -0
- data/lib/gloo/help/objs/web/http_get.txt +35 -0
- data/lib/gloo/help/objs/web/http_post.txt +32 -0
- data/lib/gloo/help/objs/web/json.txt +34 -0
- data/lib/gloo/help/objs/web/slack.txt +33 -0
- data/lib/gloo/help/objs/web/teams.txt +30 -0
- data/lib/gloo/help/objs/web/uri.txt +37 -0
- data/lib/gloo/help/verbs/alert.txt +33 -0
- data/lib/gloo/help/verbs/beep.txt +25 -0
- data/lib/gloo/help/verbs/cls.txt +24 -0
- data/lib/gloo/help/verbs/context.txt +43 -0
- data/lib/gloo/help/verbs/create.txt +33 -0
- data/lib/gloo/help/verbs/execute.txt +27 -0
- data/lib/gloo/help/verbs/help.txt +34 -0
- data/lib/gloo/help/verbs/if.txt +37 -0
- data/lib/gloo/help/verbs/list.txt +34 -0
- data/lib/gloo/help/verbs/load.txt +38 -0
- data/lib/gloo/help/verbs/move.txt +42 -0
- data/lib/gloo/help/verbs/put.txt +38 -0
- data/lib/gloo/help/verbs/quit.txt +25 -0
- data/lib/gloo/help/verbs/run.txt +41 -0
- data/lib/gloo/help/verbs/save.txt +26 -0
- data/lib/gloo/help/verbs/show.txt +30 -0
- data/lib/gloo/help/verbs/tell.txt +34 -0
- data/lib/gloo/help/verbs/unless.txt +38 -0
- data/lib/gloo/help/verbs/version.txt +32 -0
- data/lib/gloo/help/verbs/wait.txt +29 -0
- data/lib/gloo/objs/basic/alias.rb +0 -33
- data/lib/gloo/objs/basic/boolean.rb +6 -27
- data/lib/gloo/objs/basic/container.rb +0 -33
- data/lib/gloo/objs/basic/decimal.rb +8 -28
- data/lib/gloo/objs/basic/integer.rb +5 -26
- data/lib/gloo/objs/basic/script.rb +1 -27
- data/lib/gloo/objs/basic/string.rb +6 -26
- data/lib/gloo/objs/basic/text.rb +0 -25
- data/lib/gloo/objs/basic/untyped.rb +0 -26
- data/lib/gloo/objs/cli/banner.rb +0 -29
- data/lib/gloo/objs/cli/bar.rb +0 -29
- data/lib/gloo/objs/cli/colorize.rb +4 -34
- data/lib/gloo/objs/cli/confirm.rb +6 -36
- data/lib/gloo/objs/cli/menu.rb +6 -36
- data/lib/gloo/objs/cli/menu_item.rb +0 -33
- data/lib/gloo/objs/cli/pastel.rb +4 -27
- data/lib/gloo/objs/cli/prompt.rb +4 -28
- data/lib/gloo/objs/cli/select.rb +4 -31
- data/lib/gloo/objs/ctrl/each.rb +33 -33
- data/lib/gloo/objs/ctrl/repeat.rb +8 -29
- data/lib/gloo/objs/data/markdown.rb +0 -25
- data/lib/gloo/objs/data/table.rb +4 -32
- data/lib/gloo/objs/dev/git.rb +12 -30
- data/lib/gloo/objs/dt/date.rb +3 -25
- data/lib/gloo/objs/dt/datetime.rb +4 -26
- data/lib/gloo/objs/dt/time.rb +3 -25
- data/lib/gloo/objs/ror/erb.rb +11 -45
- data/lib/gloo/objs/ror/eval.rb +11 -38
- data/lib/gloo/objs/snd/play.rb +2 -25
- data/lib/gloo/objs/snd/say.rb +9 -31
- data/lib/gloo/objs/system/file_handle.rb +0 -38
- data/lib/gloo/objs/system/system.rb +16 -46
- data/lib/gloo/objs/web/http_get.rb +57 -83
- data/lib/gloo/objs/web/http_post.rb +8 -31
- data/lib/gloo/objs/web/json.rb +11 -31
- data/lib/gloo/objs/web/slack.rb +7 -34
- data/lib/gloo/objs/web/teams.rb +13 -48
- data/lib/gloo/objs/web/uri.rb +0 -29
- data/lib/gloo/persist/file_loader.rb +8 -0
- data/lib/gloo/persist/file_saver.rb +6 -0
- data/lib/gloo/persist/file_storage.rb +2 -0
- data/lib/gloo/persist/line_splitter.rb +2 -0
- data/lib/gloo/persist/persist_man.rb +6 -0
- data/lib/gloo/verbs/alert.rb +30 -44
- data/lib/gloo/verbs/beep.rb +0 -30
- data/lib/gloo/verbs/cls.rb +0 -30
- data/lib/gloo/verbs/context.rb +9 -39
- data/lib/gloo/verbs/create.rb +17 -32
- data/lib/gloo/verbs/execute.rb +52 -0
- data/lib/gloo/verbs/help.rb +151 -115
- data/lib/gloo/verbs/if.rb +46 -44
- data/lib/gloo/verbs/list.rb +36 -54
- data/lib/gloo/verbs/load.rb +8 -37
- data/lib/gloo/verbs/move.rb +12 -51
- data/lib/gloo/verbs/put.rb +28 -52
- data/lib/gloo/verbs/quit.rb +0 -31
- data/lib/gloo/verbs/run.rb +23 -39
- data/lib/gloo/verbs/save.rb +0 -33
- data/lib/gloo/verbs/show.rb +6 -31
- data/lib/gloo/verbs/tell.rb +31 -31
- data/lib/gloo/verbs/unless.rb +47 -46
- data/lib/gloo/verbs/version.rb +0 -30
- data/lib/gloo/verbs/wait.rb +0 -31
- metadata +79 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08083ccc21ecec108fbfd0addc6a09686462caca7ebb2ce6e17418166a186708'
|
4
|
+
data.tar.gz: 575ae047c999595d8f9d79c510df3a19a66910a4b9494c5da3c6a5ce81a1c37b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d320a745b4ba806060e76f72088951bbd348ba9fbd3332509ef81caa710e3afb8a136b29b2cb2a7b1c796a2c8fdcdddd8f8963c8d5b5519905f3d6cd23041c49
|
7
|
+
data.tar.gz: 57c9d6cb0509e50bd76e53b218000358697cb0640a2adc3a9f7bff0ec2cf789770efc885cf56d2911b7e9ff6b77374e11f2de4f1062118ee52434a8831854aa5
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/lib/gloo/app/args.rb
CHANGED
@@ -12,8 +12,14 @@ module Gloo
|
|
12
12
|
module App
|
13
13
|
class Args
|
14
14
|
|
15
|
+
QUIET = 'quiet'.freeze
|
16
|
+
GLOO_ENV = 'GLOO_ENV'.freeze
|
17
|
+
|
15
18
|
attr_reader :switches, :files
|
16
19
|
|
20
|
+
#
|
21
|
+
# Create arguments and setup.
|
22
|
+
#
|
17
23
|
def initialize( params = [] )
|
18
24
|
@switches = []
|
19
25
|
@files = []
|
@@ -22,9 +28,39 @@ module Gloo
|
|
22
28
|
ARGV.each { |o| process_one_arg( o ) }
|
23
29
|
end
|
24
30
|
|
31
|
+
#
|
25
32
|
# Was the --quiet arg passed?
|
33
|
+
#
|
26
34
|
def quiet?
|
27
|
-
return @switches.include?(
|
35
|
+
return @switches.include?( QUIET )
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Is the version switch set?
|
40
|
+
#
|
41
|
+
def version?
|
42
|
+
@switches.include?( Gloo::App::Mode::VERSION.to_s )
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Is the help switch set?
|
47
|
+
#
|
48
|
+
def help?
|
49
|
+
@switches.include?( Gloo::App::Mode::HELP.to_s )
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Is the cli switch set?
|
54
|
+
#
|
55
|
+
def cli?
|
56
|
+
@switches.include?( Gloo::App::Mode::CLI.to_s )
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# Is the embed switch set?
|
61
|
+
#
|
62
|
+
def embed?
|
63
|
+
@switches.include?( Gloo::App::Mode::EMBED.to_s )
|
28
64
|
end
|
29
65
|
|
30
66
|
#
|
@@ -34,15 +70,15 @@ module Gloo
|
|
34
70
|
# Then finally use the default: embedded mode.
|
35
71
|
#
|
36
72
|
def detect_mode
|
37
|
-
mode = if ENV[
|
73
|
+
mode = if ENV[ GLOO_ENV ] == Gloo::App::Mode::TEST.to_s
|
38
74
|
Mode::TEST
|
39
|
-
elsif
|
75
|
+
elsif version?
|
40
76
|
Mode::VERSION
|
41
|
-
elsif
|
77
|
+
elsif help?
|
42
78
|
Mode::HELP
|
43
|
-
elsif
|
79
|
+
elsif cli?
|
44
80
|
Mode::CLI
|
45
|
-
elsif
|
81
|
+
elsif embed?
|
46
82
|
Mode::EMBED
|
47
83
|
elsif @files.count.positive?
|
48
84
|
Mode::SCRIPT
|
@@ -54,9 +90,15 @@ module Gloo
|
|
54
90
|
return mode
|
55
91
|
end
|
56
92
|
|
93
|
+
# ---------------------------------------------------------------------
|
94
|
+
# Private
|
95
|
+
# ---------------------------------------------------------------------
|
96
|
+
|
57
97
|
private
|
58
98
|
|
99
|
+
#
|
59
100
|
# Process one argument or parameter.
|
101
|
+
#
|
60
102
|
def process_one_arg( arg )
|
61
103
|
if arg.start_with? '--'
|
62
104
|
switches << arg[ 2..-1 ]
|
data/lib/gloo/app/engine.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
3
|
#
|
4
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.
|
5
8
|
#
|
6
9
|
|
7
10
|
require 'tty-prompt'
|
@@ -15,8 +18,11 @@ module Gloo
|
|
15
18
|
attr_reader :args, :mode, :running
|
16
19
|
attr_reader :dictionary, :parser, :heap, :factory
|
17
20
|
attr_accessor :last_cmd, :persist_man, :event_manager
|
21
|
+
attr_accessor :exec_env, :help, :converter
|
18
22
|
|
23
|
+
#
|
19
24
|
# Set up the engine with basic elements.
|
25
|
+
#
|
20
26
|
def initialize( params = [] )
|
21
27
|
$engine = self
|
22
28
|
@args = Args.new( params )
|
@@ -26,7 +32,10 @@ module Gloo
|
|
26
32
|
$log.debug 'engine intialized...'
|
27
33
|
end
|
28
34
|
|
35
|
+
#
|
29
36
|
# Start the engine.
|
37
|
+
# Load object and verb definitions and setup engine elements.
|
38
|
+
#
|
30
39
|
def start
|
31
40
|
$log.debug 'starting the engine...'
|
32
41
|
$log.debug Info.display_title
|
@@ -41,6 +50,11 @@ module Gloo
|
|
41
50
|
@persist_man = Gloo::Persist::PersistMan.new
|
42
51
|
@event_manager = Gloo::Core::EventManager.new
|
43
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'
|
44
58
|
run_mode
|
45
59
|
end
|
46
60
|
|
@@ -48,12 +62,16 @@ module Gloo
|
|
48
62
|
# Run
|
49
63
|
# ---------------------------------------------------------------------
|
50
64
|
|
51
|
-
#
|
65
|
+
#
|
66
|
+
# Run gloo in the selected mode.
|
67
|
+
#
|
52
68
|
def run_mode
|
69
|
+
$log.debug "running gloo in #{@mode} mode"
|
70
|
+
|
53
71
|
if @mode == Mode::VERSION
|
54
72
|
run_version
|
55
73
|
elsif @mode == Mode::HELP
|
56
|
-
|
74
|
+
show_help_and_quit
|
57
75
|
elsif @mode == Mode::SCRIPT
|
58
76
|
run_files
|
59
77
|
else
|
@@ -61,19 +79,20 @@ module Gloo
|
|
61
79
|
end
|
62
80
|
end
|
63
81
|
|
82
|
+
#
|
64
83
|
# Run files specified on the CLI.
|
65
84
|
# Then quit.
|
85
|
+
#
|
66
86
|
def run_files
|
67
|
-
@args.files.each
|
68
|
-
@persist_man.load( f )
|
69
|
-
end
|
70
|
-
|
87
|
+
@args.files.each { |f| @persist_man.load( f ) }
|
71
88
|
quit
|
72
89
|
end
|
73
90
|
|
74
|
-
#
|
91
|
+
#
|
92
|
+
# Run in interactive mode.
|
93
|
+
#
|
75
94
|
def run
|
76
|
-
# Open default
|
95
|
+
# Open default file(s)
|
77
96
|
self.open_start_file
|
78
97
|
|
79
98
|
# TODO: open any files specifed in args
|
@@ -86,28 +105,44 @@ module Gloo
|
|
86
105
|
quit
|
87
106
|
end
|
88
107
|
|
108
|
+
#
|
89
109
|
# Get the setting for the start_with file and open it.
|
110
|
+
#
|
90
111
|
def open_start_file
|
91
112
|
name = $settings.start_with
|
92
113
|
@persist_man.load( name ) if name
|
93
114
|
end
|
94
115
|
|
116
|
+
#
|
95
117
|
# Prompt for the next command.
|
118
|
+
#
|
96
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
|
97
127
|
dt = DateTime.now
|
98
128
|
d = dt.strftime( '%Y.%m.%d' )
|
99
129
|
t = dt.strftime( '%I:%M:%S' )
|
100
|
-
|
101
|
-
@last_cmd = $prompt.ask( "#{'gloo'.blue} #{d.yellow} #{t.white} >" )
|
130
|
+
return "#{'gloo'.blue} #{d.yellow} #{t.white} >"
|
102
131
|
end
|
103
132
|
|
133
|
+
#
|
104
134
|
# Is the last command entered blank?
|
135
|
+
#
|
105
136
|
def last_cmd_blank?
|
106
137
|
return true if @last_cmd.nil?
|
107
138
|
return true if @last_cmd.strip.empty?
|
139
|
+
|
140
|
+
return false
|
108
141
|
end
|
109
142
|
|
143
|
+
#
|
110
144
|
# Prompt, Get input, process.
|
145
|
+
#
|
111
146
|
def loop
|
112
147
|
while @running
|
113
148
|
prompt_cmd
|
@@ -115,7 +150,9 @@ module Gloo
|
|
115
150
|
end
|
116
151
|
end
|
117
152
|
|
153
|
+
#
|
118
154
|
# Process the command.
|
155
|
+
#
|
119
156
|
def process_cmd
|
120
157
|
if last_cmd_blank?
|
121
158
|
clear_screen
|
@@ -125,12 +162,16 @@ module Gloo
|
|
125
162
|
@parser.run @last_cmd
|
126
163
|
end
|
127
164
|
|
165
|
+
#
|
128
166
|
# Request the engine to stop running.
|
167
|
+
#
|
129
168
|
def stop_running
|
130
169
|
@running = false
|
131
170
|
end
|
132
171
|
|
172
|
+
#
|
133
173
|
# Do any clean up and quit.
|
174
|
+
#
|
134
175
|
def quit
|
135
176
|
$log.debug 'quitting...'
|
136
177
|
end
|
@@ -139,22 +180,25 @@ module Gloo
|
|
139
180
|
# Helpers
|
140
181
|
# ---------------------------------------------------------------------
|
141
182
|
|
183
|
+
#
|
142
184
|
# Show the version information and then quit.
|
185
|
+
#
|
143
186
|
def run_version
|
144
187
|
puts Info.display_title unless @args.quiet?
|
145
188
|
quit
|
146
189
|
end
|
147
190
|
|
191
|
+
#
|
148
192
|
# Show the help information and then quit.
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
puts out unless @args.quiet?
|
154
|
-
quit unless keep_running
|
193
|
+
#
|
194
|
+
def show_help_and_quit
|
195
|
+
@help.show_app_help
|
196
|
+
quit
|
155
197
|
end
|
156
198
|
|
199
|
+
#
|
157
200
|
# Clear the screen.
|
201
|
+
#
|
158
202
|
def clear_screen
|
159
203
|
@cursor ||= TTY::Cursor
|
160
204
|
print @cursor.clear_screen
|
@@ -181,28 +225,6 @@ module Gloo
|
|
181
225
|
self.heap.error.set_to msg
|
182
226
|
end
|
183
227
|
|
184
|
-
# ---------------------------------------------------------------------
|
185
|
-
# Convert
|
186
|
-
# ---------------------------------------------------------------------
|
187
|
-
|
188
|
-
#
|
189
|
-
# Convert the given value to the specified type,
|
190
|
-
# or if no conversion is available, revert to default.
|
191
|
-
#
|
192
|
-
def convert( value, to_type, default = nil )
|
193
|
-
begin
|
194
|
-
name = "Gloo::Convert::#{value.class}To#{to_type}"
|
195
|
-
clazz = name.split( '::' ).inject( Object ) { |o, c| o.const_get c }
|
196
|
-
o = clazz.new
|
197
|
-
return o.convert( value )
|
198
|
-
rescue => e
|
199
|
-
$log.error e.message
|
200
|
-
$engine.heap.error.set_to e.message
|
201
|
-
end
|
202
|
-
|
203
|
-
return default
|
204
|
-
end
|
205
|
-
|
206
228
|
end
|
207
229
|
end
|
208
230
|
end
|
data/lib/gloo/app/help.rb
CHANGED
@@ -4,30 +4,151 @@
|
|
4
4
|
# Help system.
|
5
5
|
#
|
6
6
|
|
7
|
+
require 'tty-markdown'
|
8
|
+
require 'tty-pager'
|
9
|
+
|
7
10
|
module Gloo
|
8
11
|
module App
|
9
12
|
class Help
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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...'
|
17
135
|
|
18
|
-
|
19
|
-
|
20
|
-
\tMore information coming soon.
|
136
|
+
pn = File.dirname( File.absolute_path( __FILE__ ) )
|
137
|
+
pn = File.dirname( pn )
|
21
138
|
|
22
|
-
|
23
|
-
|
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
|
24
144
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
29
150
|
|
30
|
-
|
151
|
+
$log.debug "Found #{@topics.count} help files"
|
31
152
|
end
|
32
153
|
|
33
154
|
end
|