gloo 0.6.0 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/gloo/app/args.rb +48 -6
  4. data/lib/gloo/app/engine.rb +58 -39
  5. data/lib/gloo/app/help.rb +137 -16
  6. data/lib/gloo/app/info.rb +3 -1
  7. data/lib/gloo/app/log.rb +23 -0
  8. data/lib/gloo/app/mode.rb +2 -0
  9. data/lib/gloo/app/settings.rb +75 -68
  10. data/lib/gloo/convert/converter.rb +35 -0
  11. data/lib/gloo/convert/string_to_datetime.rb +1 -1
  12. data/lib/gloo/convert/string_to_decimal.rb +1 -1
  13. data/lib/gloo/convert/string_to_integer.rb +1 -1
  14. data/lib/gloo/core/dictionary.rb +99 -22
  15. data/lib/gloo/core/error.rb +19 -8
  16. data/lib/gloo/core/event_manager.rb +4 -0
  17. data/lib/gloo/core/factory.rb +11 -0
  18. data/lib/gloo/core/gloo_system.rb +1 -1
  19. data/lib/gloo/core/heap.rb +11 -3
  20. data/lib/gloo/core/it.rb +6 -0
  21. data/lib/gloo/core/literal.rb +5 -0
  22. data/lib/gloo/core/obj.rb +14 -0
  23. data/lib/gloo/core/op.rb +7 -0
  24. data/lib/gloo/core/parser.rb +6 -0
  25. data/lib/gloo/core/pn.rb +36 -0
  26. data/lib/gloo/core/tokens.rb +66 -22
  27. data/lib/gloo/core/verb.rb +4 -0
  28. data/lib/gloo/exec/exec_env.rb +13 -1
  29. data/lib/gloo/expr/expression.rb +26 -4
  30. data/lib/gloo/expr/l_boolean.rb +6 -0
  31. data/lib/gloo/expr/l_decimal.rb +5 -0
  32. data/lib/gloo/expr/l_integer.rb +7 -0
  33. data/lib/gloo/expr/l_string.rb +7 -0
  34. data/lib/gloo/expr/op_div.rb +2 -0
  35. data/lib/gloo/expr/op_minus.rb +2 -0
  36. data/lib/gloo/expr/op_mult.rb +2 -0
  37. data/lib/gloo/expr/op_plus.rb +2 -0
  38. data/lib/gloo/help/app/application.txt +22 -0
  39. data/lib/gloo/help/app/configuration.txt +7 -0
  40. data/lib/gloo/help/app/default_help.txt +14 -0
  41. data/lib/gloo/help/app/logging.txt +16 -0
  42. data/lib/gloo/help/core/color.txt +31 -0
  43. data/lib/gloo/help/core/error.txt +33 -0
  44. data/lib/gloo/help/core/events.txt +21 -0
  45. data/lib/gloo/help/core/gloo_system.txt +54 -0
  46. data/lib/gloo/help/core/here.txt +30 -0
  47. data/lib/gloo/help/core/it.txt +23 -0
  48. data/lib/gloo/help/core/ops.txt +16 -0
  49. data/lib/gloo/help/core/pathname.txt +29 -0
  50. data/lib/gloo/help/objs/basic/alias.txt +36 -0
  51. data/lib/gloo/help/objs/basic/boolean.txt +28 -0
  52. data/lib/gloo/help/objs/basic/container.txt +33 -0
  53. data/lib/gloo/help/objs/basic/decimal.txt +28 -0
  54. data/lib/gloo/help/objs/basic/integer.txt +27 -0
  55. data/lib/gloo/help/objs/basic/script.txt +29 -0
  56. data/lib/gloo/help/objs/basic/string.txt +28 -0
  57. data/lib/gloo/help/objs/basic/text.txt +27 -0
  58. data/lib/gloo/help/objs/basic/untyped.txt +22 -0
  59. data/lib/gloo/help/objs/cli/banner.txt +49 -0
  60. data/lib/gloo/help/objs/cli/bar.txt +34 -0
  61. data/lib/gloo/help/objs/cli/colorize.txt +33 -0
  62. data/lib/gloo/help/objs/cli/confirm.txt +26 -0
  63. data/lib/gloo/help/objs/cli/menu.txt +44 -0
  64. data/lib/gloo/help/objs/cli/menu_item.txt +26 -0
  65. data/lib/gloo/help/objs/cli/pastel.txt +43 -0
  66. data/lib/gloo/help/objs/cli/prompt.txt +27 -0
  67. data/lib/gloo/help/objs/cli/select.txt +34 -0
  68. data/lib/gloo/help/objs/ctrl/each.txt +48 -0
  69. data/lib/gloo/help/objs/ctrl/repeat.txt +38 -0
  70. data/lib/gloo/help/objs/data/markdown.txt +25 -0
  71. data/lib/gloo/help/objs/data/table.txt +46 -0
  72. data/lib/gloo/help/objs/dev/git_repo.txt +35 -0
  73. data/lib/gloo/help/objs/dt/date.txt +23 -0
  74. data/lib/gloo/help/objs/dt/datetime.txt +24 -0
  75. data/lib/gloo/help/objs/dt/time.txt +23 -0
  76. data/lib/gloo/help/objs/ror/erb.txt +37 -0
  77. data/lib/gloo/help/objs/ror/eval.txt +24 -0
  78. data/lib/gloo/help/objs/snd/play.txt +23 -0
  79. data/lib/gloo/help/objs/snd/say.txt +28 -0
  80. data/lib/gloo/help/objs/system/file.txt +41 -0
  81. data/lib/gloo/help/objs/system/system.txt +32 -0
  82. data/lib/gloo/help/objs/web/http_get.txt +35 -0
  83. data/lib/gloo/help/objs/web/http_post.txt +32 -0
  84. data/lib/gloo/help/objs/web/json.txt +34 -0
  85. data/lib/gloo/help/objs/web/slack.txt +33 -0
  86. data/lib/gloo/help/objs/web/teams.txt +30 -0
  87. data/lib/gloo/help/objs/web/uri.txt +37 -0
  88. data/lib/gloo/help/verbs/alert.txt +33 -0
  89. data/lib/gloo/help/verbs/beep.txt +25 -0
  90. data/lib/gloo/help/verbs/cls.txt +24 -0
  91. data/lib/gloo/help/verbs/context.txt +43 -0
  92. data/lib/gloo/help/verbs/create.txt +33 -0
  93. data/lib/gloo/help/verbs/execute.txt +27 -0
  94. data/lib/gloo/help/verbs/help.txt +34 -0
  95. data/lib/gloo/help/verbs/if.txt +37 -0
  96. data/lib/gloo/help/verbs/list.txt +34 -0
  97. data/lib/gloo/help/verbs/load.txt +38 -0
  98. data/lib/gloo/help/verbs/move.txt +42 -0
  99. data/lib/gloo/help/verbs/put.txt +38 -0
  100. data/lib/gloo/help/verbs/quit.txt +25 -0
  101. data/lib/gloo/help/verbs/run.txt +41 -0
  102. data/lib/gloo/help/verbs/save.txt +26 -0
  103. data/lib/gloo/help/verbs/show.txt +30 -0
  104. data/lib/gloo/help/verbs/tell.txt +34 -0
  105. data/lib/gloo/help/verbs/unless.txt +38 -0
  106. data/lib/gloo/help/verbs/version.txt +32 -0
  107. data/lib/gloo/help/verbs/wait.txt +29 -0
  108. data/lib/gloo/objs/basic/alias.rb +0 -33
  109. data/lib/gloo/objs/basic/boolean.rb +6 -27
  110. data/lib/gloo/objs/basic/container.rb +0 -33
  111. data/lib/gloo/objs/basic/decimal.rb +8 -28
  112. data/lib/gloo/objs/basic/integer.rb +5 -26
  113. data/lib/gloo/objs/basic/script.rb +0 -26
  114. data/lib/gloo/objs/basic/string.rb +6 -26
  115. data/lib/gloo/objs/basic/text.rb +0 -25
  116. data/lib/gloo/objs/basic/untyped.rb +0 -26
  117. data/lib/gloo/objs/cli/banner.rb +0 -29
  118. data/lib/gloo/objs/cli/bar.rb +0 -29
  119. data/lib/gloo/objs/cli/colorize.rb +4 -34
  120. data/lib/gloo/objs/cli/confirm.rb +6 -36
  121. data/lib/gloo/objs/cli/menu.rb +4 -34
  122. data/lib/gloo/objs/cli/menu_item.rb +0 -33
  123. data/lib/gloo/objs/cli/pastel.rb +4 -27
  124. data/lib/gloo/objs/cli/prompt.rb +4 -28
  125. data/lib/gloo/objs/cli/select.rb +4 -31
  126. data/lib/gloo/objs/ctrl/each.rb +33 -33
  127. data/lib/gloo/objs/ctrl/repeat.rb +8 -29
  128. data/lib/gloo/objs/data/markdown.rb +0 -25
  129. data/lib/gloo/objs/data/table.rb +4 -32
  130. data/lib/gloo/objs/dev/git.rb +12 -30
  131. data/lib/gloo/objs/dt/date.rb +3 -25
  132. data/lib/gloo/objs/dt/datetime.rb +4 -26
  133. data/lib/gloo/objs/dt/time.rb +3 -25
  134. data/lib/gloo/objs/ror/erb.rb +11 -45
  135. data/lib/gloo/objs/ror/eval.rb +11 -38
  136. data/lib/gloo/objs/snd/play.rb +2 -25
  137. data/lib/gloo/objs/snd/say.rb +9 -31
  138. data/lib/gloo/objs/system/file_handle.rb +0 -38
  139. data/lib/gloo/objs/system/system.rb +16 -46
  140. data/lib/gloo/objs/web/http_get.rb +57 -83
  141. data/lib/gloo/objs/web/http_post.rb +8 -31
  142. data/lib/gloo/objs/web/json.rb +11 -31
  143. data/lib/gloo/objs/web/slack.rb +7 -34
  144. data/lib/gloo/objs/web/teams.rb +13 -48
  145. data/lib/gloo/objs/web/uri.rb +0 -29
  146. data/lib/gloo/persist/file_loader.rb +8 -0
  147. data/lib/gloo/persist/file_saver.rb +6 -0
  148. data/lib/gloo/persist/file_storage.rb +2 -0
  149. data/lib/gloo/persist/line_splitter.rb +2 -0
  150. data/lib/gloo/persist/persist_man.rb +6 -0
  151. data/lib/gloo/verbs/alert.rb +30 -44
  152. data/lib/gloo/verbs/beep.rb +0 -30
  153. data/lib/gloo/verbs/cls.rb +0 -30
  154. data/lib/gloo/verbs/context.rb +9 -39
  155. data/lib/gloo/verbs/create.rb +17 -32
  156. data/lib/gloo/verbs/execute.rb +56 -0
  157. data/lib/gloo/verbs/help.rb +151 -115
  158. data/lib/gloo/verbs/if.rb +46 -44
  159. data/lib/gloo/verbs/list.rb +36 -54
  160. data/lib/gloo/verbs/load.rb +8 -37
  161. data/lib/gloo/verbs/move.rb +12 -51
  162. data/lib/gloo/verbs/put.rb +28 -52
  163. data/lib/gloo/verbs/quit.rb +0 -31
  164. data/lib/gloo/verbs/run.rb +23 -39
  165. data/lib/gloo/verbs/save.rb +0 -33
  166. data/lib/gloo/verbs/show.rb +6 -31
  167. data/lib/gloo/verbs/tell.rb +31 -31
  168. data/lib/gloo/verbs/unless.rb +47 -46
  169. data/lib/gloo/verbs/version.rb +0 -30
  170. data/lib/gloo/verbs/wait.rb +0 -31
  171. metadata +74 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d78e3893a4d68e8c47bfa5eadaf88b540eb1370eba87883cdb4280bc2b707af3
4
- data.tar.gz: a4eca4c6ab8df0554b17b5ccedd2efb62357be12c03abe3e3301a993a0599847
3
+ metadata.gz: 2bde3abf2469d93630317c5741886d95ac5fb4f3e8443a69759ca94da0763da6
4
+ data.tar.gz: 1d55662af6bfc582bea4a0e33fd33a6bdab36d65220f0287d6924e09b5907197
5
5
  SHA512:
6
- metadata.gz: 649c9ae168c9933cf139cb6526697b6960f37570edc027840e9a40c51f5e3995d87f575812af918f2463965caa878825c6c554011f969063407ee8cf96fd73d7
7
- data.tar.gz: 7c2ba8c60a18b36425b8cc436b3fcf40fa6e3a3da437559669e56efc73e3ca891731405bb5e53a672be5fc7ceeff2b22b4db2062dfb03e766264e53d4417d959
6
+ metadata.gz: 6ba7c772993cce30e4a854eb8d296e7017105ef6f2e64f7db2ba03ecadfd4ef5b5d2adb8e9f47658f6821b98ce4f3525e812d648f815b51fee8d6f0a7c4bd188
7
+ data.tar.gz: ad4edc2a464229f86566c35fe64c26f35ee057f043a83f5cb65e24a0672d5686e0842e8b4ac04cda5e30e14a116abc97c7435385e585c76fbff6395d783a67ef
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gloo (0.5.4)
4
+ gloo (0.7.2)
5
5
  activesupport (~> 5.2, >= 5.2.4.3)
6
6
  chronic (~> 0.10, >= 0.10.2)
7
7
  colorize (~> 0.8, >= 0.8.1)
@@ -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?( 'quiet' )
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[ 'GLOO_ENV' ] == 'test'
73
+ mode = if ENV[ GLOO_ENV ] == Gloo::App::Mode::TEST.to_s
38
74
  Mode::TEST
39
- elsif @switches.include?( 'version' )
75
+ elsif version?
40
76
  Mode::VERSION
41
- elsif @switches.include?( 'help' )
77
+ elsif help?
42
78
  Mode::HELP
43
- elsif @switches.include?( 'cli' )
79
+ elsif cli?
44
80
  Mode::CLI
45
- elsif @switches.include?( 'embed' )
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 ]
@@ -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
- # Run the selected mode.
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
- run_help
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 do |f|
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
- # Run
91
+ #
92
+ # Run in interactive mode.
93
+ #
78
94
  def run
79
- # Open default files
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
- def run_help( keep_running = false )
153
- out = "#{Info.display_title}\n"
154
- out << Help.get_help_text
155
- $engine.heap.it.set_to out
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
@@ -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
- # Get text to display when the application is run
12
- # in HELP mode.
13
- def self.get_help_text
14
- return <<~TEXT
15
- NAME
16
- \tgloo
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
- DESCRIPTION
19
- \tGloo scripting language. A scripting language built on ruby.
20
- \tMore information coming soon.
136
+ pn = File.dirname( File.absolute_path( __FILE__ ) )
137
+ pn = File.dirname( pn )
21
138
 
22
- SYNOPSIS
23
- \tgloo [global option] [file]
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
- GLOBAL OPTIONS
26
- \t--cli \t\t - Run in CLI mode
27
- \t--version \t - Show application version
28
- \t--help \t\t - Show this help page
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
- TEXT
151
+ $log.debug "Found #{@topics.count} help files"
31
152
  end
32
153
 
33
154
  end