Class: Gloo::Verbs::Help

Inherits:
Core::Verb show all
Defined in:
lib/gloo/verbs/help.rb

Constant Summary collapse

KEYWORD =
'help'.freeze
KEYWORD_SHORT =
'?'.freeze
DEFAULT_HELP =
'default_help'.freeze
HELP_NOT_FOUND_ERR =
'Help command could not be found:'.freeze
DISPATCH =
{
  settings: 'show_settings',
  keywords: 'show_keywords',
  verb: 'show_verbs',
  verbs: 'show_verbs',
  v: 'show_verbs',
  obj: 'show_objs',
  object: 'show_objs',
  objects: 'show_objs',
  o: 'show_objs',
  topics: 'show_topics'
}.freeze

Instance Attribute Summary

Attributes inherited from Core::Verb

#params, #tokens

Attributes inherited from Core::Baseo

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core::Verb

#display_value, help, inherited, #initialize, #type_display

Methods inherited from Core::Baseo

#initialize, #type_display

Constructor Details

This class inherits a constructor from Gloo::Core::Verb

Class Method Details

.keywordObject

Get the Verb’s keyword.



112
113
114
# File 'lib/gloo/verbs/help.rb', line 112

def self.keyword
  return KEYWORD
end

.keyword_shortcutObject

Get the Verb’s keyword shortcut.



119
120
121
# File 'lib/gloo/verbs/help.rb', line 119

def self.keyword_shortcut
  return KEYWORD_SHORT
end

Instance Method Details

#get_obj_listObject

Get the text for the list of verbs.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/gloo/verbs/help.rb', line 72

def get_obj_list
  out = "Object Types:\n"
  str = ''
  objs = $engine.dictionary.get_obj_types.sort_by( &:typename )
  objs.each_with_index do |o, i|
    name = o.typename
    if o.short_typename != o.typename
      name = "#{name} (#{o.short_typename})"
    end
    str << " #{name.ljust( 30, ' ' )}"
    if ( ( i + 1 ) % 4 ).zero?
      out << "#{str}\n"
      str = ''
    end
  end

  return out
end

#get_topicsObject

Get the list of help topics.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/gloo/verbs/help.rb', line 94

def get_topics
  out = "Help Topics:\n"
  str = ''
  objs = $engine.help.topics.keys.sort
  objs.each_with_index do |o, i|
    str << " #{o.ljust( 30, ' ' )}"
    if ( ( i + 1 ) % 4 ).zero?
      out << "#{str}\n"
      str = ''
    end
  end

  return out
end

#get_verb_listObject

Get the text for the list of verbs.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/gloo/verbs/help.rb', line 46

def get_verb_list
  out = "Verbs:\n"
  str = ''
  verbs = $engine.dictionary.get_verbs.sort_by( &:keyword )
  verbs.each_with_index do |v, i|
    cut = v.keyword_shortcut.ljust( 5, ' ' )
    str << " #{cut} #{v.keyword.ljust( 20, ' ' )}"
    if ( ( i + 1 ) % 3 ).zero?
      out << "#{str}\n"
      str = ''
    end
  end

  return out
end

#lookup_opts(opts) ⇒ Object

Lookup the opts in the dispatch table.



65
66
67
# File 'lib/gloo/verbs/help.rb', line 65

def lookup_opts( opts )
  return DISPATCH[ opts.to_sym ]
end

#runObject

Run the verb.



32
33
34
35
36
37
38
39
40
41
# File 'lib/gloo/verbs/help.rb', line 32

def run
  opts = @tokens.second if @tokens
  opts = opts.strip.downcase if opts

  if opts
    dispatch opts
  else
    $engine.help.page_topic DEFAULT_HELP
  end
end