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).



159
160
161
162
163
164
# File 'lib/gloo/docs/help_shell.rb', line 159

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).



122
123
124
125
126
127
128
129
# File 'lib/gloo/docs/help_shell.rb', line 122

def cmd_show_docs( _obj, _context )
  data = "\n"
  data << " Docs\n".blue
  doc_page_names.each do |name|
    data << "   #{name.white}\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.



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

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.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/gloo/docs/help_shell.rb', line 82

def cmd_show_extensions( _obj, _context )
  data = "\n"
  data << " Extensions\n".blue
  data << "   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".light_black
  loaded = @engine.ext_manager.loaded_extensions
  if loaded.empty?
    data << "   (none loaded)\n".light_black
  else
    loaded.sort.each do |name, _ext|
      data << "   #{name.white} \n"
    end
  end
  @engine.log.show "#{data}\n"
end

#cmd_show_libraries(_obj, _context) ⇒ Object

List loaded libraries.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/gloo/docs/help_shell.rb', line 102

def cmd_show_libraries( _obj, _context )
  data = "\n"
  data << " Libraries\n".blue
  data << "   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".light_black
  loaded = @engine.lib_manager.loaded_libraries
  if loaded.empty?
    data << "   (none loaded)\n".light_black
  else
    loaded.sort.each do |name, _lib|
      data << "   #{name.white} \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.



171
172
173
174
175
176
177
178
179
# File 'lib/gloo/docs/help_shell.rb', line 171

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.



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

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.



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

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

#cmd_show_settings(_obj, _context) ⇒ Object

Show application settings.



75
76
77
# File 'lib/gloo/docs/help_shell.rb', line 75

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

#cmd_show_verb_detail(obj, _context) ⇒ Object

Show detailed help for one verb.



139
140
141
142
143
144
# File 'lib/gloo/docs/help_shell.rb', line 139

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
# File 'lib/gloo/docs/help_shell.rb', line 43

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