class CTioga2::Commands::Documentation::Introspection

This class provides facilities to display information

Public Instance Methods

edit_command(cmd, doc) click to toggle source

Lauches an editor to edit the given command:

# File lib/ctioga2/commands/doc/introspection.rb, line 107
def edit_command(cmd, doc)
  cmd = Interpreter::command(cmd)
  if cmd
    cntx = doc ? cmd.documentation_context : cmd.context
    edit_file(*cntx)
  end
end
edit_group(group) click to toggle source

Lauches an editor to edit the given command:

# File lib/ctioga2/commands/doc/introspection.rb, line 116
def edit_group(group)
  group = Interpreter::group(group)
  if group
    edit_file(*group.context)
  end
end
edit_type(type) click to toggle source

Lauches an editor to edit the given command:

# File lib/ctioga2/commands/doc/introspection.rb, line 124
def edit_type(type)
  type = Interpreter::type(type)
  if type
    edit_file(*type.context)
  end
end
list_commands(format = :pretty) click to toggle source

Display all known commands, along with their definition place

# File lib/ctioga2/commands/doc/introspection.rb, line 27
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)
  when :spec
    for n in names
      cmd = cmds[n]
      puts "#{n}:"
      for a in cmd.arguments
        puts " - #{a.type.name}"
      end

      opts = cmd.optional_arguments.keys.sort
      for on in opts
        opt = cmd.optional_arguments[on]
        puts " * /#{on}=#{opt.type.name}"
      end
    end
  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) click to toggle source

List known groups

# File lib/ctioga2/commands/doc/introspection.rb, line 77
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_styles() click to toggle source

Lists all the stylistic things, and in particular the names of color sets, marker sets and the like.

This function will hold more data with time.

# File lib/ctioga2/commands/doc/introspection.rb, line 135
def list_styles

  puts "Available color sets:"
  sets = Graphics::Styles::CurveStyleFactory::parameters['color'].sets
  set_names = sets.keys.sort

  sets_by_prefix = Utils.group_by_prefix(set_names, /(.*?)\d+$/)


  for pref in sets_by_prefix.keys.sort
    vals = Utils.suffix_numeric_sort(sets_by_prefix[pref])
    puts " * #{vals.join(", ")} "
  end

  puts "\nAvailable marker sets:"
  sets = Graphics::Styles::CurveStyleFactory::parameters['marker'].sets
  set_names = sets.keys.sort

  sets_by_prefix = Utils.group_by_prefix(set_names, /(.*?)\d+$/)
  for pref in sets_by_prefix.keys.sort
    vals = Utils.suffix_numeric_sort(sets_by_prefix[pref])
    puts " * #{vals.join(", ")} "
  end

  puts "\nAvailable line style sets:"
  sets = Graphics::Styles::CurveStyleFactory::parameters['line_style'].sets
  set_names = sets.keys.sort

  sets_by_prefix = Utils.group_by_prefix(set_names, /(.*?)\d+$/)
  for pref in sets_by_prefix.keys.sort
    vals = Utils.suffix_numeric_sort(sets_by_prefix[pref])
    puts " * #{vals.join(", ")} "
  end


end
list_types(raw = false) click to toggle source

List known types

# File lib/ctioga2/commands/doc/introspection.rb, line 92
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

Protected Instance Methods

edit_file(file, line) click to toggle source

Launches an editor to edit the given file at the given place.

# File lib/ctioga2/commands/doc/introspection.rb, line 176
def edit_file(file, line)
  editor = ENV['EDITOR'] || 'emacs'
  if ENV['CT2_DEV_HOME']
    file = "#{ENV['CT2_DEV_HOME']}/#{file}"
  end
  system("#{editor} +#{line} #{file} &")
end