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:



78
79
80
81
82
83
# File 'lib/ctioga2/commands/doc/introspection.rb', line 78

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:



86
87
88
89
90
91
# File 'lib/ctioga2/commands/doc/introspection.rb', line 86

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:



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

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

#list_commands(raw = false) ⇒ Object

Display all known commands, along with their definition place



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ctioga2/commands/doc/introspection.rb', line 30

def list_commands(raw = false)
  puts "Known commands:" unless raw
  cmds = Interpreter::commands
  names = cmds.keys.sort
  if raw
    puts names
  else
    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



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ctioga2/commands/doc/introspection.rb', line 48

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



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

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