gloo 0.6.1 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/gloo/app/args.rb +48 -6
- data/lib/gloo/app/engine.rb +58 -39
- data/lib/gloo/app/help.rb +126 -25
- 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 +75 -68
- 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/it.rb +6 -0
- data/lib/gloo/core/literal.rb +5 -0
- data/lib/gloo/core/obj.rb +14 -0
- data/lib/gloo/core/op.rb +7 -0
- data/lib/gloo/core/parser.rb +6 -0
- data/lib/gloo/core/pn.rb +36 -0
- data/lib/gloo/core/tokens.rb +66 -22
- data/lib/gloo/core/verb.rb +4 -0
- data/lib/gloo/exec/exec_env.rb +13 -1
- 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 +48 -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 +0 -26
- 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 +4 -34
- 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 +7 -36
- 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 +56 -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 +74 -3
- data/lib/gloo/help/help.md +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86384bdaceb688e8ce21ccceea1d51795bc76f1e8db187f04caed2dcd87ec7fb
|
4
|
+
data.tar.gz: 4770f98bdbc6529e89c6a613f2aadff646210aa3574f132c84bdaea017febc65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e99639d6828f815a891d55478e494624e2306aac02e445294d39919f10570fa800da6535702f67e5c011d44e926ba08791ed4bde0876643561c3fe66e32cef7
|
7
|
+
data.tar.gz: b1c5b4580804e77c80f50814f6d5b743450007b8896c721f1f11dd2c9bc4c1375f0ea28e8a5180a7bb6d070e311dba3d4c485af4300b040b675988152e26958b
|
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,9 +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
|
18
|
-
attr_accessor :exec_env
|
21
|
+
attr_accessor :exec_env, :help, :converter
|
19
22
|
|
23
|
+
#
|
20
24
|
# Set up the engine with basic elements.
|
25
|
+
#
|
21
26
|
def initialize( params = [] )
|
22
27
|
$engine = self
|
23
28
|
@args = Args.new( params )
|
@@ -27,7 +32,10 @@ module Gloo
|
|
27
32
|
$log.debug 'engine intialized...'
|
28
33
|
end
|
29
34
|
|
35
|
+
#
|
30
36
|
# Start the engine.
|
37
|
+
# Load object and verb definitions and setup engine elements.
|
38
|
+
#
|
31
39
|
def start
|
32
40
|
$log.debug 'starting the engine...'
|
33
41
|
$log.debug Info.display_title
|
@@ -43,7 +51,10 @@ module Gloo
|
|
43
51
|
@event_manager = Gloo::Core::EventManager.new
|
44
52
|
|
45
53
|
@exec_env = Gloo::Exec::ExecEnv.new
|
54
|
+
@help = Gloo::App::Help.new
|
55
|
+
@converter = Gloo::Convert::Converter.new
|
46
56
|
|
57
|
+
$log.debug 'the engine has started'
|
47
58
|
run_mode
|
48
59
|
end
|
49
60
|
|
@@ -51,12 +62,16 @@ module Gloo
|
|
51
62
|
# Run
|
52
63
|
# ---------------------------------------------------------------------
|
53
64
|
|
54
|
-
#
|
65
|
+
#
|
66
|
+
# Run gloo in the selected mode.
|
67
|
+
#
|
55
68
|
def run_mode
|
69
|
+
$log.debug "running gloo in #{@mode} mode"
|
70
|
+
|
56
71
|
if @mode == Mode::VERSION
|
57
72
|
run_version
|
58
73
|
elsif @mode == Mode::HELP
|
59
|
-
|
74
|
+
show_help_and_quit
|
60
75
|
elsif @mode == Mode::SCRIPT
|
61
76
|
run_files
|
62
77
|
else
|
@@ -64,19 +79,20 @@ module Gloo
|
|
64
79
|
end
|
65
80
|
end
|
66
81
|
|
82
|
+
#
|
67
83
|
# Run files specified on the CLI.
|
68
84
|
# Then quit.
|
85
|
+
#
|
69
86
|
def run_files
|
70
|
-
@args.files.each
|
71
|
-
@persist_man.load( f )
|
72
|
-
end
|
73
|
-
|
87
|
+
@args.files.each { |f| @persist_man.load( f ) }
|
74
88
|
quit
|
75
89
|
end
|
76
90
|
|
77
|
-
#
|
91
|
+
#
|
92
|
+
# Run in interactive mode.
|
93
|
+
#
|
78
94
|
def run
|
79
|
-
# Open default
|
95
|
+
# Open default file(s)
|
80
96
|
self.open_start_file
|
81
97
|
|
82
98
|
# TODO: open any files specifed in args
|
@@ -89,28 +105,44 @@ module Gloo
|
|
89
105
|
quit
|
90
106
|
end
|
91
107
|
|
108
|
+
#
|
92
109
|
# Get the setting for the start_with file and open it.
|
110
|
+
#
|
93
111
|
def open_start_file
|
94
112
|
name = $settings.start_with
|
95
113
|
@persist_man.load( name ) if name
|
96
114
|
end
|
97
115
|
|
116
|
+
#
|
98
117
|
# Prompt for the next command.
|
118
|
+
#
|
99
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
|
100
127
|
dt = DateTime.now
|
101
128
|
d = dt.strftime( '%Y.%m.%d' )
|
102
129
|
t = dt.strftime( '%I:%M:%S' )
|
103
|
-
|
104
|
-
@last_cmd = $prompt.ask( "#{'gloo'.blue} #{d.yellow} #{t.white} >" )
|
130
|
+
return "#{'gloo'.blue} #{d.yellow} #{t.white} >"
|
105
131
|
end
|
106
132
|
|
133
|
+
#
|
107
134
|
# Is the last command entered blank?
|
135
|
+
#
|
108
136
|
def last_cmd_blank?
|
109
137
|
return true if @last_cmd.nil?
|
110
138
|
return true if @last_cmd.strip.empty?
|
139
|
+
|
140
|
+
return false
|
111
141
|
end
|
112
142
|
|
143
|
+
#
|
113
144
|
# Prompt, Get input, process.
|
145
|
+
#
|
114
146
|
def loop
|
115
147
|
while @running
|
116
148
|
prompt_cmd
|
@@ -118,7 +150,9 @@ module Gloo
|
|
118
150
|
end
|
119
151
|
end
|
120
152
|
|
153
|
+
#
|
121
154
|
# Process the command.
|
155
|
+
#
|
122
156
|
def process_cmd
|
123
157
|
if last_cmd_blank?
|
124
158
|
clear_screen
|
@@ -128,12 +162,16 @@ module Gloo
|
|
128
162
|
@parser.run @last_cmd
|
129
163
|
end
|
130
164
|
|
165
|
+
#
|
131
166
|
# Request the engine to stop running.
|
167
|
+
#
|
132
168
|
def stop_running
|
133
169
|
@running = false
|
134
170
|
end
|
135
171
|
|
172
|
+
#
|
136
173
|
# Do any clean up and quit.
|
174
|
+
#
|
137
175
|
def quit
|
138
176
|
$log.debug 'quitting...'
|
139
177
|
end
|
@@ -142,22 +180,25 @@ module Gloo
|
|
142
180
|
# Helpers
|
143
181
|
# ---------------------------------------------------------------------
|
144
182
|
|
183
|
+
#
|
145
184
|
# Show the version information and then quit.
|
185
|
+
#
|
146
186
|
def run_version
|
147
187
|
puts Info.display_title unless @args.quiet?
|
148
188
|
quit
|
149
189
|
end
|
150
190
|
|
191
|
+
#
|
151
192
|
# Show the help information and then quit.
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
puts out unless @args.quiet?
|
157
|
-
quit unless keep_running
|
193
|
+
#
|
194
|
+
def show_help_and_quit
|
195
|
+
@help.show_app_help
|
196
|
+
quit
|
158
197
|
end
|
159
198
|
|
199
|
+
#
|
160
200
|
# Clear the screen.
|
201
|
+
#
|
161
202
|
def clear_screen
|
162
203
|
@cursor ||= TTY::Cursor
|
163
204
|
print @cursor.clear_screen
|
@@ -184,28 +225,6 @@ module Gloo
|
|
184
225
|
self.heap.error.set_to msg
|
185
226
|
end
|
186
227
|
|
187
|
-
# ---------------------------------------------------------------------
|
188
|
-
# Convert
|
189
|
-
# ---------------------------------------------------------------------
|
190
|
-
|
191
|
-
#
|
192
|
-
# Convert the given value to the specified type,
|
193
|
-
# or if no conversion is available, revert to default.
|
194
|
-
#
|
195
|
-
def convert( value, to_type, default = nil )
|
196
|
-
begin
|
197
|
-
name = "Gloo::Convert::#{value.class}To#{to_type}"
|
198
|
-
clazz = name.split( '::' ).inject( Object ) { |o, c| o.const_get c }
|
199
|
-
o = clazz.new
|
200
|
-
return o.convert( value )
|
201
|
-
rescue => e
|
202
|
-
$log.error e.message
|
203
|
-
$engine.heap.error.set_to e.message
|
204
|
-
end
|
205
|
-
|
206
|
-
return default
|
207
|
-
end
|
208
|
-
|
209
228
|
end
|
210
229
|
end
|
211
230
|
end
|
data/lib/gloo/app/help.rb
CHANGED
@@ -11,43 +11,144 @@ module Gloo
|
|
11
11
|
module App
|
12
12
|
class Help
|
13
13
|
|
14
|
-
|
15
|
-
# in HELP mode.
|
16
|
-
def self.get_help_text
|
17
|
-
load_help_files
|
14
|
+
APPLICATION = 'application'.freeze
|
18
15
|
|
19
|
-
|
20
|
-
NAME
|
21
|
-
\tgloo
|
16
|
+
attr_accessor :topics
|
22
17
|
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
26
70
|
|
27
|
-
|
28
|
-
|
71
|
+
#
|
72
|
+
# Show a help topic.
|
73
|
+
#
|
74
|
+
def show_topic( topic )
|
75
|
+
return if $engine.args.quiet?
|
29
76
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
34
84
|
|
35
|
-
|
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
|
36
96
|
end
|
37
97
|
|
38
|
-
|
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
|
+
|
39
136
|
pn = File.dirname( File.absolute_path( __FILE__ ) )
|
40
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
|
+
|
41
145
|
root = File.join( pn, 'help', '**/*.md' )
|
42
146
|
Dir.glob( root ).each do |md_file|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
puts TTY::Markdown.parse data
|
47
|
-
# md = TTY::Markdown.parse data
|
48
|
-
# pager = TTY::Pager.new
|
49
|
-
# pager.page( md )
|
147
|
+
key = File.basename( md_file, '.md' )
|
148
|
+
@topics[ key ] = md_file
|
50
149
|
end
|
150
|
+
|
151
|
+
$log.debug "Found #{@topics.count} help files"
|
51
152
|
end
|
52
153
|
|
53
154
|
end
|