Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2012-2023 The plumed team
3 : (see the PEOPLE file at the root of the distribution for a list of names)
4 :
5 : See http://www.plumed.org for more information.
6 :
7 : This file is part of plumed, version 2.
8 :
9 : plumed is free software: you can redistribute it and/or modify
10 : it under the terms of the GNU Lesser General Public License as published by
11 : the Free Software Foundation, either version 3 of the License, or
12 : (at your option) any later version.
13 :
14 : plumed is distributed in the hope that it will be useful,
15 : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : GNU Lesser General Public License for more details.
18 :
19 : You should have received a copy of the GNU Lesser General Public License
20 : along with plumed. If not, see <http://www.gnu.org/licenses/>.
21 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
22 : #include "CLTool.h"
23 : #include "core/CLToolRegister.h"
24 : #include "tools/Tools.h"
25 : #include "config/Config.h"
26 : #include <cstdio>
27 : #include <string>
28 :
29 : namespace PLMD {
30 : namespace cltools {
31 :
32 : //+PLUMEDOC TOOLS info
33 : /*
34 : This tool allows you to obtain information about your plumed version
35 :
36 : You can specify the information you require using the following command line
37 : arguments
38 :
39 : \par Examples
40 :
41 : The following command returns the root directory for your plumed distribution.
42 : \verbatim
43 : plumed info --root
44 : \endverbatim
45 :
46 : */
47 : //+ENDPLUMEDOC
48 :
49 : class Info:
50 : public CLTool {
51 : public:
52 : static void registerKeywords( Keywords& keys );
53 : explicit Info(const CLToolOptions& co );
54 : int main(FILE* in, FILE*out,Communicator& pc) override;
55 5 : std::string description()const override {
56 5 : return "provide informations about plumed";
57 : }
58 : };
59 :
60 18615 : PLUMED_REGISTER_CLTOOL(Info,"info")
61 :
62 5418 : void Info::registerKeywords( Keywords& keys ) {
63 5418 : CLTool::registerKeywords( keys );
64 5418 : keys.addFlag("--configuration",false,"prints the configuration file");
65 5418 : keys.addFlag("--root",false,"print the location of the root directory for the plumed source");
66 5418 : keys.addFlag("--user-doc",false,"print the location of user manual (html)");
67 5418 : keys.addFlag("--developer-doc",false,"print the location of user manual (html)");
68 5418 : keys.addFlag("--version",false,"print the version number");
69 5418 : keys.addFlag("--long-version",false,"print the version number (long version)");
70 5418 : keys.addFlag("--git-version",false,"print the version number (git version, if available)");
71 5418 : keys.addFlag("--include-dir",false,"print the location of the include dir");
72 5418 : keys.addFlag("--soext",false,"print the extension of shared libraries (so or dylib)");
73 5418 : }
74 :
75 2361 : Info::Info(const CLToolOptions& co ):
76 2361 : CLTool(co) {
77 2361 : inputdata=commandline;
78 2361 : }
79 :
80 2356 : int Info::main(FILE* in, FILE*out,Communicator& pc) {
81 :
82 : bool printconfiguration;
83 2356 : parseFlag("--configuration",printconfiguration);
84 : bool printroot;
85 2356 : parseFlag("--root",printroot);
86 : bool printuserdoc;
87 2356 : parseFlag("--user-doc",printuserdoc);
88 : bool printdeveloperdoc;
89 2356 : parseFlag("--developer-doc",printdeveloperdoc);
90 : bool printversion;
91 2356 : parseFlag("--version",printversion);
92 : bool printlongversion;
93 2356 : parseFlag("--long-version",printlongversion);
94 : bool printgitversion;
95 2356 : parseFlag("--git-version",printgitversion);
96 : bool printincludedir;
97 2356 : parseFlag("--include-dir",printincludedir);
98 : bool printsoext;
99 2356 : parseFlag("--soext",printsoext);
100 2356 : if(printroot) {
101 1546 : std::fprintf(out,"%s\n",config::getPlumedRoot().c_str());
102 : }
103 2356 : if(printconfiguration) {
104 82 : std::fprintf(out,"%s",config::getMakefile().c_str());
105 : }
106 2356 : if(printincludedir) {
107 0 : std::fprintf(out,"%s\n",config::getPlumedIncludedir().c_str());
108 : }
109 2356 : if(printuserdoc) {
110 0 : std::string userdoc=config::getPlumedHtmldir()+"/user-doc/html/index.html";
111 0 : FILE *ff=std::fopen(userdoc.c_str(),"r");
112 : // no exception here
113 0 : if(ff) {
114 0 : std::fclose(ff);
115 : } else {
116 0 : userdoc="http://www.plumed.org/doc-v" + config::getVersion() + "/user-doc/html/index.html";
117 : }
118 : std::fprintf(out,"%s\n",userdoc.c_str());
119 : }
120 2356 : if(printdeveloperdoc) {
121 0 : std::string developerdoc=config::getPlumedHtmldir()+"/developer-doc/html/index.html";
122 0 : FILE *ff=std::fopen(developerdoc.c_str(),"r");
123 : // no exception here
124 0 : if(ff) {
125 0 : std::fclose(ff);
126 : } else {
127 0 : developerdoc="http://www.plumed.org/doc-v" + config::getVersion() + "/developer-doc/html/index.html";
128 : }
129 : std::fprintf(out,"%s\n",developerdoc.c_str());
130 : }
131 2356 : if(printversion) {
132 0 : std::fprintf(out,"%s\n",config::getVersion().c_str());
133 : }
134 2356 : if(printlongversion) {
135 0 : std::fprintf(out,"%s\n",config::getVersionLong().c_str());
136 : }
137 2356 : if(printgitversion) {
138 0 : std::fprintf(out,"%s\n",config::getVersionGit().c_str());
139 : }
140 2356 : if(printsoext) {
141 3084 : std::fprintf(out,"%s\n",config::getSoExt().c_str());
142 : }
143 :
144 2356 : return 0;
145 : }
146 :
147 :
148 :
149 : }
150 : }
|