Coverage Report

Created: 2026-06-15 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmDocumentation.h
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
#pragma once
4
5
#include "cmConfigure.h" // IWYU pragma: keep
6
7
#include <iosfwd>
8
#include <map>
9
#include <string>
10
#include <utility>
11
#include <vector>
12
13
#include "cmDocumentationFormatter.h"
14
#include "cmDocumentationSection.h"
15
16
struct cmDocumentationEntry;
17
18
/** Class to generate documentation.  */
19
class cmDocumentation
20
{
21
public:
22
  /** Types of help provided.  */
23
  enum Type
24
  {
25
    None,
26
    Version,
27
    VersionJson,
28
    Usage,
29
    Help,
30
    Full,
31
    ListManuals,
32
    ListCommands,
33
    ListDiagnostics,
34
    ListModules,
35
    ListProperties,
36
    ListVariables,
37
    ListPolicies,
38
    ListGenerators,
39
    OneArbitrary,
40
    OneManual,
41
    OneCommand,
42
    OneDiagnostic,
43
    OneModule,
44
    OneProperty,
45
    OneVariable,
46
    OnePolicy,
47
    OldCustomModules
48
  };
49
50
  cmDocumentation();
51
52
  /**
53
   * Check command line arguments for documentation options.  Returns
54
   * true if documentation options are found, and false otherwise.
55
   * When true is returned, PrintRequestedDocumentation should be
56
   * called.  exitOpt can be used for things like cmake -E, so that
57
   * all arguments after the -E are ignored and not searched for
58
   * help arguments.
59
   */
60
  bool CheckOptions(int argc, char const* const* argv,
61
                    char const* exitOpt = nullptr);
62
63
  /**
64
   * Print help requested on the command line.  Call after
65
   * CheckOptions returns true.  Returns true on success, and false
66
   * otherwise.  Failure can occur when output files specified on the
67
   * command line cannot be written.
68
   */
69
  bool PrintRequestedDocumentation(std::ostream& os);
70
71
  /** Print help of the given type.  */
72
  bool PrintDocumentation(Type ht, std::ostream& os);
73
74
0
  void SetShowGenerators(bool showGen) { this->ShowGenerators = showGen; }
75
76
  /** Set the program name for standard document generation.  */
77
  void SetName(std::string const& name);
78
79
  /** Set a section of the documentation. Typical sections include Name,
80
      Usage, Description, Options */
81
  void SetSection(char const* sectionName, cmDocumentationSection section);
82
  template <typename Iterable>
83
  void SetSection(char const* sectionName, Iterable const& docs)
84
  {
85
    cmDocumentationSection sec{ sectionName };
86
    sec.Append(docs);
87
    this->SetSection(sectionName, std::move(sec));
88
  }
89
90
  /** Add the documentation to the beginning/end of the section */
91
  template <typename Iterable>
92
  void PrependSection(char const* sectionName, Iterable const& docs)
93
0
  {
94
0
    this->SectionAtName(sectionName).Prepend(docs);
95
0
  }
96
  void PrependSection(char const* sectionName, cmDocumentationEntry& docs);
97
  template <typename Iterable>
98
  void AppendSection(char const* sectionName, Iterable const& docs)
99
0
  {
100
0
    this->SectionAtName(sectionName).Append(docs);
101
0
  }
102
  void AppendSection(char const* sectionName, cmDocumentationEntry& docs);
103
104
  /** Add common (to all tools) documentation section(s) */
105
  void addCommonStandardDocSections();
106
107
  /** Add the CMake standard documentation section(s) */
108
  void addCMakeStandardDocSections();
109
110
  /** Add the CTest standard documentation section(s) */
111
  void addCTestStandardDocSections();
112
113
  /** Add the CPack standard documentation section(s) */
114
  void addCPackStandardDocSections();
115
116
private:
117
  void GlobHelp(std::vector<std::string>& files, std::string const& pattern);
118
  void PrintNames(std::ostream& os, std::string const& pattern);
119
  bool PrintFiles(std::ostream& os, std::string const& pattern);
120
121
  bool PrintVersion(std::ostream& os);
122
  bool PrintVersionJson(std::ostream& os);
123
  bool PrintUsage(std::ostream& os);
124
  bool PrintHelp(std::ostream& os);
125
  bool PrintHelpFull(std::ostream& os);
126
  bool PrintHelpOneArbitrary(std::ostream& os);
127
  bool PrintHelpOneManual(std::ostream& os);
128
  bool PrintHelpOneCommand(std::ostream& os);
129
  bool PrintHelpOneDiagnostic(std::ostream& os);
130
  bool PrintHelpOneModule(std::ostream& os);
131
  bool PrintHelpOnePolicy(std::ostream& os);
132
  bool PrintHelpOneProperty(std::ostream& os);
133
  bool PrintHelpOneVariable(std::ostream& os);
134
  bool PrintHelpListManuals(std::ostream& os);
135
  bool PrintHelpListCommands(std::ostream& os);
136
  bool PrintHelpListDiagnostics(std::ostream& os);
137
  bool PrintHelpListModules(std::ostream& os);
138
  bool PrintHelpListProperties(std::ostream& os);
139
  bool PrintHelpListVariables(std::ostream& os);
140
  bool PrintHelpListPolicies(std::ostream& os);
141
  bool PrintHelpListGenerators(std::ostream& os);
142
  bool PrintOldCustomModules(std::ostream& os);
143
144
  char const* GetNameString() const;
145
146
  bool ShowGenerators;
147
148
  std::string NameString;
149
  std::map<std::string, cmDocumentationSection> AllSections;
150
  cmDocumentationSection& SectionAtName(char const* name);
151
152
  std::string CurrentArgument;
153
154
  struct RequestedHelpItem
155
  {
156
    Type HelpType = None;
157
    std::string Filename;
158
    std::string Argument;
159
  };
160
161
  std::vector<RequestedHelpItem> RequestedHelpItems;
162
  cmDocumentationFormatter Formatter;
163
164
  static void WarnFormFromFilename(RequestedHelpItem& request, bool& result);
165
  static std::string GeneralizeKeyword(std::string word);
166
};