/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 | | ListModules, |
34 | | ListProperties, |
35 | | ListVariables, |
36 | | ListPolicies, |
37 | | ListGenerators, |
38 | | OneArbitrary, |
39 | | OneManual, |
40 | | OneCommand, |
41 | | OneModule, |
42 | | OneProperty, |
43 | | OneVariable, |
44 | | OnePolicy, |
45 | | OldCustomModules |
46 | | }; |
47 | | |
48 | | cmDocumentation(); |
49 | | |
50 | | /** |
51 | | * Check command line arguments for documentation options. Returns |
52 | | * true if documentation options are found, and false otherwise. |
53 | | * When true is returned, PrintRequestedDocumentation should be |
54 | | * called. exitOpt can be used for things like cmake -E, so that |
55 | | * all arguments after the -E are ignored and not searched for |
56 | | * help arguments. |
57 | | */ |
58 | | bool CheckOptions(int argc, char const* const* argv, |
59 | | char const* exitOpt = nullptr); |
60 | | |
61 | | /** |
62 | | * Print help requested on the command line. Call after |
63 | | * CheckOptions returns true. Returns true on success, and false |
64 | | * otherwise. Failure can occur when output files specified on the |
65 | | * command line cannot be written. |
66 | | */ |
67 | | bool PrintRequestedDocumentation(std::ostream& os); |
68 | | |
69 | | /** Print help of the given type. */ |
70 | | bool PrintDocumentation(Type ht, std::ostream& os); |
71 | | |
72 | 0 | void SetShowGenerators(bool showGen) { this->ShowGenerators = showGen; } |
73 | | |
74 | | /** Set the program name for standard document generation. */ |
75 | | void SetName(std::string const& name); |
76 | | |
77 | | /** Set a section of the documentation. Typical sections include Name, |
78 | | Usage, Description, Options */ |
79 | | void SetSection(char const* sectionName, cmDocumentationSection section); |
80 | | template <typename Iterable> |
81 | | void SetSection(char const* sectionName, Iterable const& docs) |
82 | | { |
83 | | cmDocumentationSection sec{ sectionName }; |
84 | | sec.Append(docs); |
85 | | this->SetSection(sectionName, std::move(sec)); |
86 | | } |
87 | | |
88 | | /** Add the documentation to the beginning/end of the section */ |
89 | | template <typename Iterable> |
90 | | void PrependSection(char const* sectionName, Iterable const& docs) |
91 | 0 | { |
92 | 0 | this->SectionAtName(sectionName).Prepend(docs); |
93 | 0 | } |
94 | | void PrependSection(char const* sectionName, cmDocumentationEntry& docs); |
95 | | template <typename Iterable> |
96 | | void AppendSection(char const* sectionName, Iterable const& docs) |
97 | 0 | { |
98 | 0 | this->SectionAtName(sectionName).Append(docs); |
99 | 0 | } |
100 | | void AppendSection(char const* sectionName, cmDocumentationEntry& docs); |
101 | | |
102 | | /** Add common (to all tools) documentation section(s) */ |
103 | | void addCommonStandardDocSections(); |
104 | | |
105 | | /** Add the CMake standard documentation section(s) */ |
106 | | void addCMakeStandardDocSections(); |
107 | | |
108 | | /** Add the CTest standard documentation section(s) */ |
109 | | void addCTestStandardDocSections(); |
110 | | |
111 | | /** Add the CPack standard documentation section(s) */ |
112 | | void addCPackStandardDocSections(); |
113 | | |
114 | | private: |
115 | | void GlobHelp(std::vector<std::string>& files, std::string const& pattern); |
116 | | void PrintNames(std::ostream& os, std::string const& pattern); |
117 | | bool PrintFiles(std::ostream& os, std::string const& pattern); |
118 | | |
119 | | bool PrintVersion(std::ostream& os); |
120 | | bool PrintVersionJson(std::ostream& os); |
121 | | bool PrintUsage(std::ostream& os); |
122 | | bool PrintHelp(std::ostream& os); |
123 | | bool PrintHelpFull(std::ostream& os); |
124 | | bool PrintHelpOneArbitrary(std::ostream& os); |
125 | | bool PrintHelpOneManual(std::ostream& os); |
126 | | bool PrintHelpOneCommand(std::ostream& os); |
127 | | bool PrintHelpOneModule(std::ostream& os); |
128 | | bool PrintHelpOnePolicy(std::ostream& os); |
129 | | bool PrintHelpOneProperty(std::ostream& os); |
130 | | bool PrintHelpOneVariable(std::ostream& os); |
131 | | bool PrintHelpListManuals(std::ostream& os); |
132 | | bool PrintHelpListCommands(std::ostream& os); |
133 | | bool PrintHelpListModules(std::ostream& os); |
134 | | bool PrintHelpListProperties(std::ostream& os); |
135 | | bool PrintHelpListVariables(std::ostream& os); |
136 | | bool PrintHelpListPolicies(std::ostream& os); |
137 | | bool PrintHelpListGenerators(std::ostream& os); |
138 | | bool PrintOldCustomModules(std::ostream& os); |
139 | | |
140 | | char const* GetNameString() const; |
141 | | |
142 | | bool ShowGenerators; |
143 | | |
144 | | std::string NameString; |
145 | | std::map<std::string, cmDocumentationSection> AllSections; |
146 | | cmDocumentationSection& SectionAtName(char const* name); |
147 | | |
148 | | std::string CurrentArgument; |
149 | | |
150 | | struct RequestedHelpItem |
151 | | { |
152 | | Type HelpType = None; |
153 | | std::string Filename; |
154 | | std::string Argument; |
155 | | }; |
156 | | |
157 | | std::vector<RequestedHelpItem> RequestedHelpItems; |
158 | | cmDocumentationFormatter Formatter; |
159 | | |
160 | | static void WarnFormFromFilename(RequestedHelpItem& request, bool& result); |
161 | | static std::string GeneralizeKeyword(std::string word); |
162 | | }; |