Class: CTioga2::Commands::Documentation::Doc

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

Overview

The base class for all documentation.

TODO: create a class that would parse a description from a group/command/type and understand some ‘markup’: lists, links to other commands/groups/types, and maybe bold or things of this kind. Then the various outputs should have a means to parse this.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDoc

Create a Doc object caring about the current state of registered commands and such.



58
59
60
61
62
63
64
65
66
67
# File 'lib/ctioga2/commands/doc/doc.rb', line 58

def initialize
  @commands = Interpreter::commands
  @groups = Interpreter::groups
  @types = Interpreter::types

  @ignore_blacklisted = ! (ENV.key?("CT2_DEV") && 
                           ! ENV["CT2_DEV"].empty?)

  @command_line_help = CommandLineHelp.new
end

Instance Attribute Details

#command_line_helpObject

The CommandLineHelp object in charge of displaying information about command-line



53
54
55
# File 'lib/ctioga2/commands/doc/doc.rb', line 53

def command_line_help
  @command_line_help
end

#commandsObject

The hash containing all the commands, as returned by Interpreter::commands.



38
39
40
# File 'lib/ctioga2/commands/doc/doc.rb', line 38

def commands
  @commands
end

#groupsObject

The hash containing all the groups, as returned by Interpreter::commands.



42
43
44
# File 'lib/ctioga2/commands/doc/doc.rb', line 42

def groups
  @groups
end

#ignore_blacklistedObject

Wether or not to ignore blacklisted commands



49
50
51
# File 'lib/ctioga2/commands/doc/doc.rb', line 49

def ignore_blacklisted
  @ignore_blacklisted
end

#typesObject

The hash containing all the types, as returned by Interpreter::commands.



46
47
48
# File 'lib/ctioga2/commands/doc/doc.rb', line 46

def types
  @types
end

Instance Method Details

#display_command_line_helpObject

Display command-line help.



90
91
92
93
# File 'lib/ctioga2/commands/doc/doc.rb', line 90

def display_command_line_help
  @command_line_help.
    print_commandline_options(*self.documented_commands)
end

#documented_commandsObject

Returns a [ cmds, groups ] hash containing the list of commands, and the groups to be documented.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ctioga2/commands/doc/doc.rb', line 71

def documented_commands
  cmds = group_commands

  groups = cmds.keys.sort do |a,b|
    if ! a
      1
    elsif ! b
      -1
    else
      a.priority <=> b.priority
    end
  end
  if @ignore_blacklisted
    groups.delete_if {|g| g && g.blacklisted }
  end
  return [cmds, groups]
end