Class: CTioga2::Commands::Documentation::Introspection
- Inherits:
-
Object
- Object
- CTioga2::Commands::Documentation::Introspection
- Defined in:
- lib/ctioga2/commands/doc/introspection.rb
Overview
This class provides facilities to display information
Instance Method Summary collapse
-
#edit_command(cmd, doc) ⇒ Object
Lauches an editor to edit the given command:.
-
#edit_group(group) ⇒ Object
Lauches an editor to edit the given command:.
-
#edit_type(type) ⇒ Object
Lauches an editor to edit the given command:.
-
#list_commands(format = :pretty) ⇒ Object
Display all known commands, along with their definition place.
-
#list_groups(raw = false) ⇒ Object
List known groups.
-
#list_styles ⇒ Object
Lists all the stylistic things, and in particular the names of color sets, marker sets and the like.
-
#list_types(raw = false) ⇒ Object
List known types.
Instance Method Details
#edit_command(cmd, doc) ⇒ Object
Lauches an editor to edit the given command:
107 108 109 110 111 112 113 |
# 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) ⇒ Object
Lauches an editor to edit the given command:
116 117 118 119 120 121 |
# 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) ⇒ Object
Lauches an editor to edit the given command:
124 125 126 127 128 129 |
# 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) ⇒ Object
Display all known commands, along with their definition place
27 28 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 63 64 65 66 67 68 69 70 71 72 73 74 |
# 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) ⇒ Object
List known groups
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# 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 ⇒ Object
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.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/ctioga2/commands/doc/introspection.rb', line 135 def list_styles puts "Available color sets:" sets = Graphics::Styles::CurveStyleFactory::parameters['line_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_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) ⇒ Object
List known types
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# 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 |