Class: CTioga2::Commands::Documentation::Introspection

Inherits:
Object
  • Object
show all
Defined in:
lib/ctioga2/commands/doc/introspection.rb

Overview

This class provides facilities to display information

Instance Method Summary collapse

Instance Method Details

#edit_command(cmd) ⇒ Object

Lauches an editor to edit the given command:



95
96
97
98
99
100
# File 'lib/ctioga2/commands/doc/introspection.rb', line 95

def edit_command(cmd)
  cmd = Interpreter::command(cmd)
  if cmd
    edit_file(*cmd.context)
  end
end

#edit_group(group) ⇒ Object

Lauches an editor to edit the given command:



103
104
105
106
107
108
# File 'lib/ctioga2/commands/doc/introspection.rb', line 103

def edit_group(group)
  group = Interpreter::group(group)
  if group
    edit_file(*group.context)
  end
end

#edit_type(type) ⇒ Object

Lauches an editor to edit the given command:



111
112
113
114
115
116
# File 'lib/ctioga2/commands/doc/introspection.rb', line 111

def edit_type(type)
  type = Interpreter::type(type)
  if type
    edit_file(*type.context)
  end
end

#list_commands(format = :pretty) ⇒ Object

Display all known commands, along with their definition place



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ctioga2/commands/doc/introspection.rb', line 29

def list_commands(format = :pretty)
  cmds = Interpreter::commands
  names = cmds.keys.sort
  case format
  when :list
    puts names
  when :yaml
    require 'yaml'
    commands = {}
    for n in names
      cmd = cmds[n]
      command = {}
      command['name'] = n
      f,l = cmd.context
      command['file'] = f
      command['line'] = l.to_i
      command['long_option'] = cmd.long_option
      command['short_option'] = cmd.short_option
      command['short_description'] = cmd.short_description
      command['long_description'] = cmd.long_description
      commands[n] = command
    end
    puts YAML.dump(commands)
  else
    puts "Known commands:" 
    max = names.inject(0) {|m,x| [m,x.size].max}
    max2 = names.inject(0) {|m,x| [m,cmds[x].long_option.size].max}
    for n in names
      f,l = cmds[n].context
      puts "\t%-#{max}s\t--%-#{max2}s\t(#{f}: #{l})" % 
        [n, cmds[n].long_option ]
    end
  end
end

#list_groups(raw = false) ⇒ Object

List known groups



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/ctioga2/commands/doc/introspection.rb', line 65

def list_groups(raw = false)
  puts "Known groups:" unless raw
  groups = Interpreter::groups
  names = groups.keys.sort
  if raw
    puts names
  else
    for n in names
      f,l = groups[n].context
      puts "\t#{n}\t(#{f}: #{l})"
    end
  end
end

#list_types(raw = false) ⇒ Object

List known types



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/ctioga2/commands/doc/introspection.rb', line 80

def list_types(raw = false)
  puts "Known types:" unless raw
  types = Interpreter::types
  names = types.keys.sort
  if raw
    puts names
  else
    for n in names
      f,l = types[n].context
      puts "\t#{n}\t(#{f}: #{l})"
    end
  end
end