1
# doc.rb: a class holding all informations
2
# copyright (c) 2009 by Vincent Fourmond
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details (in the COPYING file).
14
require 'ctioga2/utils'
15
require 'ctioga2/commands/commands'
16
require 'ctioga2/commands/doc/markup'
20
Version::register_svn_info('$Revision: 138 $', '$Date: 2010-01-21 22:39:55 +0100 (Thu, 21 Jan 2010) $')
24
# The base of the 'self-documentation' of CTioga2
27
# The base class for all documentation.
30
# The hash containing all the commands, as returned
31
# by Interpreter::commands.
32
attr_accessor :commands
34
# The hash containing all the groups, as returned
35
# by Interpreter::commands.
38
# The hash containing all the types, as returned
39
# by Interpreter::commands.
42
# The hash containing all the backends, as returned by
43
# Data::Backends::Backend::list_backends
44
attr_accessor :backends
46
# Wether or not to ignore blacklisted commands
47
attr_accessor :ignore_blacklisted
49
# Create a Doc object caring about the current state of
50
# registered commands and such.
52
@commands = Interpreter::commands
53
@groups = Interpreter::groups
54
@types = Interpreter::types
55
@backends = Data::Backends::Backend::list_backends
57
@ignore_blacklisted = ! (ENV.key?("CT2_DEV") &&
58
! ENV["CT2_DEV"].empty?)
61
# Returns a [ cmds, groups ] hash containing the list of
62
# commands, and the groups to be documented.
63
def documented_commands
66
groups = cmds.keys.sort do |a,b|
72
if a.priority == b.priority
75
a.priority <=> b.priority
79
if @ignore_blacklisted
80
groups.delete_if {|g| g && g.blacklisted }
85
# Display command-line help.
86
def display_command_line_help(options)
87
CommandLineHelp.new(options).
88
print_commandline_options(*self.documented_commands)
94
# Groups Command by CommandGroup, _nil_ being a proper value,
95
# and return the corresponding hash.
98
for name, cmd in @commands
100
if ret_val.key?(group)
101
ret_val[group] << cmd
103
ret_val[group] = [cmd]