Class: Gloo::Docs::HelpShell

Inherits:
Shell::Runner show all
Defined in:
lib/gloo/docs/help_shell.rb

Constant Summary collapse

PROMPT =
'help>'.freeze
NO_DOC_YET =
'No documentation available yet for'.freeze
VERB_NAMES =
:verb_names
OBJECT_NAMES =
:object_names
DOC_NAMES =
:doc_names
LIBRARY_NAMES =
:library_names
EXTENSION_NAMES =
:extension_names
DOCS_DIR =
File.expand_path( '../../../docs', __dir__ ).freeze
README_GLOB =
'README*'.freeze
NO_README_YET =
'No README found for library'.freeze

Constants inherited from Shell::Runner

Shell::Runner::DEFAULT_PROMPT, Shell::Runner::QUIT_DESCRIPTION, Shell::Runner::QUIT_METHOD, Shell::Runner::QUIT_NAME, Shell::Runner::UNKNOWN_COMMAND

Instance Method Summary collapse

Methods inherited from Shell::Runner

#add_command_node, #build_node_from_data, #cmd_quit, #execute_command, #execute_once, #handle_empty_command, #handle_unknown_command, #prompt, #repl, #run_after_action, #run_before_action, #run_on_error, #set_context, #setup_completion, #start, #stop, #traverse

Constructor Details

#initialize(engine) ⇒ HelpShell

Initialize the help shell for the given engine.



30
31
32
33
34
# File 'lib/gloo/docs/help_shell.rb', line 30

def initialize( engine )
  super( engine, prompt: PROMPT, include_quit: true )
  populate_context
  build_commands
end

Instance Method Details

#cmd_show_doc_detail(obj, _context) ⇒ Object

Show one narrative doc page (dev/gloo/docs/name.md).



187
188
189
190
191
192
# File 'lib/gloo/docs/help_shell.rb', line 187

def cmd_show_doc_detail( obj, _context )
  path = File.join( DOCS_DIR, "#{obj}.md" )
  return @engine.log.show "#{NO_DOC_YET} '#{obj}'." unless File.exist?( path )

  page_markdown( File.read( path ) )
end

#cmd_show_docs(_obj, _context) ⇒ Object

List all narrative doc pages (dev/gloo/docs/*.md).



149
150
151
152
153
154
155
156
157
# File 'lib/gloo/docs/help_shell.rb', line 149

def cmd_show_docs( _obj, _context )
  theme = @engine.theme
  data = "\n"
  data << theme.heading( " Docs\n" )
  doc_page_names.each do |name|
    data << "   #{theme.emphasis( name )}\n"
  end
  @engine.log.show "#{data}\n"
end

#cmd_show_extension_detail(obj, _context) ⇒ Object

Show the README for one loaded user extension (from the root of its extension folder, e.g. ~/gloo/extensions/name). Only loaded extensions are tab-completable here - see cmd_show_extensions.



214
215
216
217
218
219
220
221
222
# File 'lib/gloo/docs/help_shell.rb', line 214

def cmd_show_extension_detail( obj, _context )
  start_file = @engine.ext_manager.loaded_extensions[ obj ]
  return @engine.log.show "#{NO_DOC_YET} '#{obj}'." unless start_file

  readme_path = find_extension_readme( start_file )
  return @engine.log.show "#{NO_README_YET} '#{obj}'." unless readme_path

  page_markdown( File.read( readme_path ) )
end

#cmd_show_extensions(_obj, _context) ⇒ Object

List loaded extensions.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/gloo/docs/help_shell.rb', line 105

def cmd_show_extensions( _obj, _context )
  theme = @engine.theme
  data = "\n"
  data << theme.heading( " Extensions\n" )
  data << theme.muted(
    "   Use `load ext {name}` to load a User Extension, \n" \
    "   then `object {name}` / `verb {name}` / `extension {name}` here to see what it adds. \n" \
    "   Only loaded extensions are listed below.\n\n" )
  loaded = @engine.ext_manager.loaded_extensions
  if loaded.empty?
    data << theme.muted( "   (none loaded)\n" )
  else
    loaded.sort.each do |name, _ext|
      data << "   #{theme.emphasis( name )} \n"
    end
  end
  @engine.log.show "#{data}\n"
end

#cmd_show_libraries(_obj, _context) ⇒ Object

List loaded libraries.



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/gloo/docs/help_shell.rb', line 127

def cmd_show_libraries( _obj, _context )
  theme = @engine.theme
  data = "\n"
  data << theme.heading( " Libraries\n" )
  data << theme.muted(
    "   Use `load lib {name}` to load a core library, \n" \
    "   then `object {name}` / `verb {name}` here to see what it adds. \n" \
    "   Only loaded libraries are listed below.\n\n" )
  loaded = @engine.lib_manager.loaded_libraries
  if loaded.empty?
    data << theme.muted( "   (none loaded)\n" )
  else
    loaded.sort.each do |name, _lib|
      data << "   #{theme.emphasis( name )} \n"
    end
  end
  @engine.log.show "#{data}\n"
end

#cmd_show_library_detail(obj, _context) ⇒ Object

Show the README for one loaded core library (from the root of its installed gem). Only loaded libraries are tab-completable here - see cmd_show_libraries.



199
200
201
202
203
204
205
206
207
# File 'lib/gloo/docs/help_shell.rb', line 199

def cmd_show_library_detail( obj, _context )
  gem_name = @engine.lib_manager.loaded_libraries[ obj ]
  return @engine.log.show "#{NO_DOC_YET} '#{obj}'." unless gem_name

  readme_path = find_readme( gem_name )
  return @engine.log.show "#{NO_README_YET} '#{obj}' (#{gem_name})." unless readme_path

  page_markdown( File.read( readme_path ) )
end

#cmd_show_object_detail(obj, _context) ⇒ Object

Show detailed help for one object type.



177
178
179
180
181
182
# File 'lib/gloo/docs/help_shell.rb', line 177

def cmd_show_object_detail( obj, _context )
  obj_class = @engine.dictionary.find_obj( obj )
  return @engine.log.show "#{NO_DOC_YET} '#{obj}'." unless obj_class.respond_to?( :doc_data )

  page_markdown( Gloo::Docs::DocData.new( obj_class.doc_data ).render )
end

#cmd_show_objects(_obj, _context) ⇒ Object

List all object types.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/gloo/docs/help_shell.rb', line 58

def cmd_show_objects( _obj, _context )
  theme = @engine.theme
  data = "\n"
  data << theme.heading( " Objects \n" )
  @engine.dictionary.get_obj_types.sort_by( &:typename ).each do |o|
    if o.short_typename != o.typename
      short = theme.accent( "(#{o.short_typename})" )
      name = "#{theme.emphasis( o.typename )}  #{short}"
    else
      name = theme.emphasis( o.typename )
    end
    data << "   #{name.ljust( 30, ' ' )}\n"
  end
  @engine.log.show "#{data}\n"
end

#cmd_show_settings(_obj, _context) ⇒ Object

Show application settings.



77
78
79
# File 'lib/gloo/docs/help_shell.rb', line 77

def cmd_show_settings( _obj, _context )
  @engine.settings.show
end

#cmd_show_theme(_obj, _context) ⇒ Object

Show the current theme, how to change it, and a color preview of both palettes - handy for checking how they actually render in whatever terminal you're sitting in.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/gloo/docs/help_shell.rb', line 86

def cmd_show_theme( _obj, _context )
  theme = @engine.theme
  settings = @engine.settings
  config_file = File.join( settings.config_path, 'gloo.yml' )

  data = "\n"
  data << theme.heading( " Theme\n" )
  data << "   Current theme:  #{theme.emphasis( settings.theme )}\n\n"
  data << theme.muted( "   Change it in #{config_file}:\n" )
  data << theme.muted( "     theme: dark   (or: light)\n\n" )
  data << theme_preview( ' Dark palette', Gloo::App::Theme.new( 'dark' ) )
  data << "\n"
  data << theme_preview( ' Light palette', Gloo::App::Theme.new( 'light' ) )
  @engine.log.show "#{data}\n"
end

#cmd_show_verb_detail(obj, _context) ⇒ Object

Show detailed help for one verb.



167
168
169
170
171
172
# File 'lib/gloo/docs/help_shell.rb', line 167

def cmd_show_verb_detail( obj, _context )
  verb_class = @engine.dictionary.find_verb( obj )
  return @engine.log.show "#{NO_DOC_YET} '#{obj}'." unless verb_class.respond_to?( :doc_data )

  page_markdown( Gloo::Docs::DocData.new( verb_class.doc_data ).render )
end

#cmd_show_verbs(_obj, _context) ⇒ Object

List all verbs.



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/gloo/docs/help_shell.rb', line 43

def cmd_show_verbs( _obj, _context )
  theme = @engine.theme
  data = "\n"
  data << theme.heading( " Verbs (shortcut, name)\n" )
  @engine.dictionary.get_verbs.sort_by( &:keyword ).each do |v|
    cut = theme.accent( v.keyword_shortcut.ljust( 5, ' ' ) )
    name = theme.emphasis( v.keyword.ljust( 20, ' ' ) )
    data << "   #{cut}  #{name} \n"
  end
  @engine.log.show "#{data}\n"
end