gloo 0.6.1 → 0.7.4

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.
Files changed (172) 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 +126 -25
  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 +48 -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 +7 -36
  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 -3
  172. data/lib/gloo/help/help.md +0 -16
@@ -11,35 +11,27 @@ module Gloo
11
11
  KEYWORD = 'alert'.freeze
12
12
  KEYWORD_SHORT = '!'.freeze
13
13
 
14
+ MISSING_EXPR_ERR = 'Missing Expression!'.freeze
15
+ NO_RESULT_ERR = 'Expression evaluated with no result!'.freeze
16
+
14
17
  #
15
18
  # Run the verb.
16
19
  #
17
20
  def run
18
- return unless @tokens.token_count > 1
21
+ unless @tokens.token_count > 1
22
+ $engine.err MISSING_EXPR_ERR
23
+ return
24
+ end
19
25
 
20
26
  expr = Gloo::Expr::Expression.new( @tokens.params )
21
27
  result = expr.evaluate
22
- $engine.heap.it.set_to result
23
- self.post_alert result
24
- end
25
-
26
- #
27
- # Post the alert for the specific platform.
28
- # Notice is not posted if we're in quiet mode.
29
- #
30
- def post_alert( msg )
31
- return if $engine.args.quiet?
32
28
 
33
- post_osx msg
34
- end
35
-
36
- #
37
- # Post the alert on the Mac OSX.
38
- #
39
- def post_osx( msg )
40
- cmd1 = '/usr/bin/osascript -e "display notification \"'
41
- cmd2 = '\" with title \"Gloo\" "'
42
- system( cmd1 + msg.to_s + cmd2 )
29
+ if result
30
+ $engine.heap.it.set_to result
31
+ post_alert result
32
+ else
33
+ $engine.err NO_RESULT_ERR
34
+ end
43
35
  end
44
36
 
45
37
  #
@@ -57,35 +49,29 @@ module Gloo
57
49
  end
58
50
 
59
51
  # ---------------------------------------------------------------------
60
- # Help
52
+ # Private functions
61
53
  # ---------------------------------------------------------------------
62
54
 
55
+ private
56
+
63
57
  #
64
- # Get help for this verb.
58
+ # Post the alert for the specific platform.
59
+ # Notice is not posted if we're in quiet mode.
65
60
  #
66
- def self.help
67
- return <<~TEXT
68
- ALERT VERB
69
- NAME: alert
70
- SHORTCUT: !
71
-
72
- DESCRIPTION
73
- Show a pop-up notification.
74
- This has only been implemented for the Mac OSX as of yet.
75
-
76
- SYNTAX
77
- alert <messsage>
78
-
79
- PARAMETERS
80
- messsage - The message that will be displayed in the alert.
61
+ def post_alert( msg )
62
+ $log.info msg
63
+ return if $engine.args.quiet?
81
64
 
82
- RESULT
83
- On the Mac, a notification will popup on screen.
84
- <it> will be set to the message.
65
+ post_osx msg
66
+ end
85
67
 
86
- ERRORS
87
- None
88
- TEXT
68
+ #
69
+ # Post the alert on the Mac OSX.
70
+ #
71
+ def post_osx( msg )
72
+ cmd1 = '/usr/bin/osascript -e "display notification \"'
73
+ cmd2 = '\" with title \"Gloo\" "'
74
+ system( cmd1 + msg.to_s + cmd2 )
89
75
  end
90
76
 
91
77
  end
@@ -35,36 +35,6 @@ module Gloo
35
35
  return KEYWORD_SHORT
36
36
  end
37
37
 
38
- # ---------------------------------------------------------------------
39
- # Help
40
- # ---------------------------------------------------------------------
41
-
42
- #
43
- # Get help for this verb.
44
- #
45
- def self.help
46
- return <<~TEXT
47
- BEEP VERB
48
- NAME: beep
49
- SHORTCUT: b
50
-
51
- DESCRIPTION
52
- Play a standard system beep sound.
53
-
54
- SYNTAX
55
- beep
56
-
57
- PARAMETERS
58
- None
59
-
60
- RESULT
61
- None
62
-
63
- ERRORS
64
- None
65
- TEXT
66
- end
67
-
68
38
  end
69
39
  end
70
40
  end
@@ -32,36 +32,6 @@ module Gloo
32
32
  return KEYWORD_SHORT
33
33
  end
34
34
 
35
- # ---------------------------------------------------------------------
36
- # Help
37
- # ---------------------------------------------------------------------
38
-
39
- #
40
- # Get help for this verb.
41
- #
42
- def self.help
43
- return <<~TEXT
44
- CLS VERB
45
- NAME: cls
46
- SHORTCUT: cls
47
-
48
- DESCRIPTION
49
- Clear the console screen.
50
-
51
- SYNTAX
52
- cls
53
-
54
- PARAMETERS
55
- None
56
-
57
- RESULT
58
- The screen is cleared and cursor set to the top.
59
-
60
- ERRORS
61
- None
62
- TEXT
63
- end
64
-
65
35
  end
66
36
  end
67
37
  end
@@ -20,16 +20,6 @@ module Gloo
20
20
  show_context
21
21
  end
22
22
 
23
- #
24
- # Set the context to the given path.
25
- #
26
- def set_context
27
- path = @tokens.second
28
- $engine.heap.context.set_to path
29
- $engine.heap.it.set_to path
30
- $log.debug "Context set to #{$engine.heap.context}"
31
- end
32
-
33
23
  #
34
24
  # Show the current context.
35
25
  #
@@ -52,39 +42,19 @@ module Gloo
52
42
  end
53
43
 
54
44
  # ---------------------------------------------------------------------
55
- # Help
45
+ # Private functions
56
46
  # ---------------------------------------------------------------------
57
47
 
48
+ private
49
+
58
50
  #
59
- # Get help for this verb.
51
+ # Set the context to the given path.
60
52
  #
61
- def self.help
62
- return <<~TEXT
63
- CONTEXT VERB
64
- NAME: context
65
- SHORTCUT: @
66
-
67
- DESCRIPTION
68
- Get or set the current context.
69
- When no parameter is provided, the context will be shown.
70
- Whe the optional path paramter is provided, the context will
71
- be set to that path.
72
- Use 'context root' to set the context back to the root level.
73
-
74
- SYNTAX
75
- context <path.to.new.context>
76
-
77
- PARAMETERS
78
- path.to.new.context - Optional. The path to the new context.
79
-
80
- RESULT
81
- Context is optionally set.
82
- <it> will be set to the new context path when we are changing context.
83
- Context is show in either case.
84
-
85
- ERRORS
86
- None
87
- TEXT
53
+ def set_context
54
+ path = @tokens.second
55
+ $engine.heap.context.set_to path
56
+ $engine.heap.it.set_to path
57
+ $log.debug "Context set to #{$engine.heap.context}"
88
58
  end
89
59
 
90
60
  end
@@ -12,6 +12,7 @@ module Gloo
12
12
  KEYWORD_SHORT = '`'.freeze
13
13
  AS = 'as'.freeze
14
14
  VAL = ':'.freeze
15
+ NO_NAME_ERR = 'Object name is missing!'.freeze
15
16
 
16
17
  #
17
18
  # Run the verb.
@@ -21,13 +22,11 @@ module Gloo
21
22
  type = @tokens.after_token( AS )
22
23
  value = @tokens.after_token( VAL )
23
24
 
24
- if Gloo::Expr::LString.string?( value )
25
- value = Gloo::Expr::LString.strip_quotes( value )
25
+ unless name
26
+ $engine.err NO_NAME_ERR
27
+ return
26
28
  end
27
- obj = $engine.factory.create( { name: name, type: type, value: value } )
28
-
29
- obj.add_default_children if obj&.add_children_on_create?
30
- $engine.heap.it.set_to value
29
+ create name, type, value
31
30
  end
32
31
 
33
32
  #
@@ -45,37 +44,23 @@ module Gloo
45
44
  end
46
45
 
47
46
  # ---------------------------------------------------------------------
48
- # Help
47
+ # Private functions
49
48
  # ---------------------------------------------------------------------
50
49
 
50
+ private
51
+
51
52
  #
52
- # Get help for this verb.
53
+ # Create an object with given name of given type with
54
+ # the given initial value.
53
55
  #
54
- def self.help
55
- return <<~TEXT
56
- CREATE VERB
57
- NAME: create
58
- SHORTCUT: `
59
-
60
- DESCRIPTION
61
- Create a new object of given type with given value.
62
- Both type and value are optional when creating an object.
63
-
64
- SYNTAX
65
- create <new.object.path> as <type> : <value>
66
-
67
- PARAMETERS
68
- new.object.path - The path and name of the new object
69
- type - The type of the new object
70
- value - The initial value for the new object
71
-
72
- RESULT
73
- The new object will be created and added to the object heap.
74
- <it> will be set to the new object's intitial value.
56
+ def create( name, type, value )
57
+ if Gloo::Expr::LString.string?( value )
58
+ value = Gloo::Expr::LString.strip_quotes( value )
59
+ end
60
+ obj = $engine.factory.create( { name: name, type: type, value: value } )
75
61
 
76
- ERRORS
77
- None
78
- TEXT
62
+ obj.add_default_children if obj&.add_children_on_create?
63
+ $engine.heap.it.set_to value
79
64
  end
80
65
 
81
66
  end
@@ -0,0 +1,56 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Execute a shell command.
5
+ #
6
+
7
+ module Gloo
8
+ module Verbs
9
+ class Execute < Gloo::Core::Verb
10
+
11
+ KEYWORD = 'execute'.freeze
12
+ KEYWORD_SHORT = 'exec'.freeze
13
+ MISSING_EXPR_ERR = 'Missing Expression!'.freeze
14
+
15
+ #
16
+ # Run the verb.
17
+ #
18
+ def run
19
+ if @tokens.token_count < 2
20
+ $engine.err MISSING_EXPR_ERR
21
+ return
22
+ end
23
+
24
+ expr = Gloo::Expr::Expression.new( @tokens.params )
25
+ cmd = expr.evaluate
26
+ $log.debug "starting cmd: #{cmd}"
27
+
28
+ pid = fork { exec( cmd ) }
29
+ Process.wait pid
30
+
31
+ # pid = spawn cmd
32
+ # Process.wait pid
33
+ $log.debug "done executing cmd: #{cmd}"
34
+
35
+ # system expr.evaluate #, chdir: Dir.pwd
36
+ # `#{expr.evaluate}`
37
+ # exec expr.evaluate
38
+ end
39
+
40
+ #
41
+ # Get the Verb's keyword.
42
+ #
43
+ def self.keyword
44
+ return KEYWORD
45
+ end
46
+
47
+ #
48
+ # Get the Verb's keyword shortcut.
49
+ #
50
+ def self.keyword_shortcut
51
+ return KEYWORD_SHORT
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -10,16 +10,20 @@ module Gloo
10
10
 
11
11
  KEYWORD = 'help'.freeze
12
12
  KEYWORD_SHORT = '?'.freeze
13
+ DEFAULT_HELP = 'default_help'.freeze
14
+ HELP_NOT_FOUND_ERR = 'Help command could not be found:'.freeze
13
15
 
14
16
  DISPATCH = {
15
17
  settings: 'show_settings',
18
+ keywords: 'show_keywords',
16
19
  verb: 'show_verbs',
17
20
  verbs: 'show_verbs',
18
21
  v: 'show_verbs',
19
22
  obj: 'show_objs',
20
23
  object: 'show_objs',
21
24
  objects: 'show_objs',
22
- o: 'show_objs'
25
+ o: 'show_objs',
26
+ topics: 'show_topics'
23
27
  }.freeze
24
28
 
25
29
  #
@@ -30,26 +34,161 @@ module Gloo
30
34
  opts = opts.strip.downcase if opts
31
35
 
32
36
  if opts
33
- self.dispatch opts
37
+ dispatch opts
34
38
  else
35
- show_default
39
+ $engine.help.page_topic DEFAULT_HELP
36
40
  end
37
41
  end
38
42
 
43
+ #
44
+ # Get the text for the list of verbs.
45
+ #
46
+ def get_verb_list
47
+ out = "Verbs:\n"
48
+ str = ''
49
+ verbs = $engine.dictionary.get_verbs.sort_by( &:keyword )
50
+ verbs.each_with_index do |v, i|
51
+ cut = v.keyword_shortcut.ljust( 5, ' ' )
52
+ str << " #{cut} #{v.keyword.ljust( 20, ' ' )}"
53
+ if ( ( i + 1 ) % 3 ).zero?
54
+ out << "#{str}\n"
55
+ str = ''
56
+ end
57
+ end
58
+
59
+ return out
60
+ end
61
+
62
+ #
63
+ # Lookup the opts in the dispatch table.
64
+ #
65
+ def lookup_opts( opts )
66
+ return DISPATCH[ opts.to_sym ]
67
+ end
68
+
69
+ #
70
+ # Get the text for the list of verbs.
71
+ #
72
+ def get_obj_list
73
+ out = "Object Types:\n"
74
+ str = ''
75
+ objs = $engine.dictionary.get_obj_types.sort_by( &:typename )
76
+ objs.each_with_index do |o, i|
77
+ name = o.typename
78
+ if o.short_typename != o.typename
79
+ name = "#{name} (#{o.short_typename})"
80
+ end
81
+ str << " #{name.ljust( 30, ' ' )}"
82
+ if ( ( i + 1 ) % 4 ).zero?
83
+ out << "#{str}\n"
84
+ str = ''
85
+ end
86
+ end
87
+
88
+ return out
89
+ end
90
+
91
+ #
92
+ # Get the list of help topics.
93
+ #
94
+ def get_topics
95
+ out = "Help Topics:\n"
96
+ str = ''
97
+ objs = $engine.help.topics.keys.sort
98
+ objs.each_with_index do |o, i|
99
+ str << " #{o.ljust( 30, ' ' )}"
100
+ if ( ( i + 1 ) % 4 ).zero?
101
+ out << "#{str}\n"
102
+ str = ''
103
+ end
104
+ end
105
+
106
+ return out
107
+ end
108
+
109
+ #
110
+ # Get the Verb's keyword.
111
+ #
112
+ def self.keyword
113
+ return KEYWORD
114
+ end
115
+
116
+ #
117
+ # Get the Verb's keyword shortcut.
118
+ #
119
+ def self.keyword_shortcut
120
+ return KEYWORD_SHORT
121
+ end
122
+
123
+ # ---------------------------------------------------------------------
124
+ # Private functions
125
+ # ---------------------------------------------------------------------
126
+
127
+ private
128
+
129
+ #
130
+ # Report an error with the inline help.
131
+ #
132
+ def report_help_error( opts )
133
+ $engine.err "#{HELP_NOT_FOUND_ERR} '#{opts}'"
134
+ end
135
+
39
136
  #
40
137
  # Dispatch the help to the right place.
41
138
  #
42
139
  def dispatch( opts )
140
+ return if dispatch_help_page( opts )
141
+
142
+ $log.debug 'looking for built in help topic'
43
143
  cmd = DISPATCH[ opts.to_sym ]
44
144
  if cmd
145
+ $log.debug 'found help index'
45
146
  send cmd
46
147
  else
148
+ $log.debug 'looking for entity help'
47
149
  entity_help opts
48
150
  end
49
151
  rescue
50
152
  report_help_error opts
51
153
  end
52
154
 
155
+ #
156
+ # Dispatch to a help page if we can find one.
157
+ #
158
+ def dispatch_help_page( opts )
159
+ if $engine.help.topic? opts
160
+ $log.debug 'found expanded help topic'
161
+ $engine.help.page_topic opts
162
+ return true
163
+ end
164
+
165
+ key = $engine.dictionary.lookup_keyword opts
166
+ if $engine.help.topic? key
167
+ $log.debug 'found expanded help topic'
168
+ $engine.help.page_topic key
169
+ return true
170
+ end
171
+
172
+ return false
173
+ end
174
+
175
+ #
176
+ # Write output to it and show it unless we are in
177
+ # silent mode.
178
+ #
179
+ def show_output( out )
180
+ $engine.heap.it.set_to out
181
+ puts out unless $engine.args.quiet?
182
+ end
183
+
184
+ #
185
+ # List all help topics (articles)
186
+ #
187
+ def show_topics
188
+ out = self.get_topics
189
+ show_output out
190
+ end
191
+
53
192
  #
54
193
  # Dispatch the help command to a verb or object
55
194
  # if we can find one matching the request.
@@ -69,7 +208,7 @@ module Gloo
69
208
  if $engine.dictionary.verb?( opts )
70
209
  t = $engine.dictionary.find_verb( opts )
71
210
  out = t.send 'help'
72
- self.show_output out
211
+ show_output out
73
212
  return true
74
213
  end
75
214
 
@@ -84,36 +223,13 @@ module Gloo
84
223
  if $engine.dictionary.obj?( opts )
85
224
  t = $engine.dictionary.find_obj( opts )
86
225
  out = t.send 'help'
87
- self.show_output out
226
+ show_output out
88
227
  return true
89
228
  end
90
229
 
91
230
  return false
92
231
  end
93
232
 
94
- #
95
- # Lookup the opts in the dispatch table.
96
- #
97
- def lookup_opts( opts )
98
- return DISPATCH[ opts.to_sym ]
99
- end
100
-
101
- #
102
- # Report an error with the inline help.
103
- #
104
- def report_help_error( opts )
105
- msg = "Help command '#{opts}' could not be found"
106
- $log.warn msg
107
- $engine.heap.error.set_to msg
108
- end
109
-
110
- #
111
- # If no parameter is given, show the default help page.
112
- #
113
- def show_default
114
- $engine.run_help( true )
115
- end
116
-
117
233
  #
118
234
  # Show application settings.
119
235
  #
@@ -122,22 +238,17 @@ module Gloo
122
238
  end
123
239
 
124
240
  #
125
- # List the verbs
241
+ # Show all keywords: verbs and objects.
126
242
  #
127
- def show_verbs
128
- out = self.get_verb_list
129
- self.show_output out
243
+ def show_keywords
244
+ $engine.dictionary.show_keywords
130
245
  end
131
246
 
132
247
  #
133
- # Get the text for the list of verbs.
248
+ # List the verbs
134
249
  #
135
- def get_verb_list
136
- out = "Verbs:\n"
137
- $engine.dictionary.get_verbs.each do |v|
138
- out << " #{v.keyword_shortcut} - #{v.keyword}\n"
139
- end
140
- return out
250
+ def show_verbs
251
+ show_output get_verb_list
141
252
  end
142
253
 
143
254
  #
@@ -145,82 +256,7 @@ module Gloo
145
256
  #
146
257
  def show_objs
147
258
  out = self.get_obj_list
148
- self.show_output out
149
- end
150
-
151
- #
152
- # Get the text for the list of verbs.
153
- #
154
- def get_obj_list
155
- out = "Object Types:\n"
156
- $engine.dictionary.get_obj_types.each do |v|
157
- out << " #{v.short_typename} - #{v.typename}\n"
158
- end
159
- return out
160
- end
161
-
162
- #
163
- # Write output to it and show it unless we are in
164
- # silent mode.
165
- #
166
- def show_output( out )
167
- $engine.heap.it.set_to out
168
- puts out unless $engine.args.quiet?
169
- end
170
-
171
- #
172
- # Get the Verb's keyword.
173
- #
174
- def self.keyword
175
- return KEYWORD
176
- end
177
-
178
- #
179
- # Get the Verb's keyword shortcut.
180
- #
181
- def self.keyword_shortcut
182
- return KEYWORD_SHORT
183
- end
184
-
185
- # ---------------------------------------------------------------------
186
- # Help
187
- # ---------------------------------------------------------------------
188
-
189
- #
190
- # Get help for this verb.
191
- #
192
- def self.help
193
- return <<~TEXT
194
- HELP VERB
195
- NAME: helps
196
- SHORTCUT: ?
197
-
198
- DESCRIPTION
199
- Show information about the application.
200
- The help command can also be used to show a list of objects,
201
- verbs, or to show detail about a single object or a
202
- single verb.
203
-
204
- SYNTAX
205
- help <about>
206
-
207
- PARAMETERS
208
- about - Optional parameter.
209
- If no parameter is given, shows the default help screen
210
- settings - Show application settings
211
- verbs - List available verbs
212
- objects - List available objects
213
- <verb> - Look up detail about a verb
214
- <object> - Look up detail about an object
215
-
216
- RESULT
217
- The help screen will be shown with relevant information.
218
- <it> will also contain the help text.
219
-
220
- ERRORS
221
- Trying to access a help topic that does not exist will result
222
- in an error.
223
- TEXT
259
+ show_output out
224
260
  end
225
261
 
226
262
  end