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 "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 4 : std::string description()const override {
56 4 : return "provide informations about plumed";
57 : }
58 : };
59 :
60 15709 : PLUMED_REGISTER_CLTOOL(Info,"info")
61 :
62 4595 : void Info::registerKeywords( Keywords& keys ) {
63 4595 : CLTool::registerKeywords( keys );
64 9190 : keys.addFlag("--configuration",false,"prints the configuration file");
65 9190 : keys.addFlag("--root",false,"print the location of the root directory for the plumed source");
66 9190 : keys.addFlag("--user-doc",false,"print the location of user manual (html)");
67 9190 : keys.addFlag("--developer-doc",false,"print the location of user manual (html)");
68 9190 : keys.addFlag("--version",false,"print the version number");
69 9190 : keys.addFlag("--long-version",false,"print the version number (long version)");
70 9190 : keys.addFlag("--git-version",false,"print the version number (git version, if available)");
71 9190 : keys.addFlag("--include-dir",false,"print the location of the include dir");
72 9190 : keys.addFlag("--soext",false,"print the extension of shared libraries (so or dylib)");
73 4595 : }
74 :
75 1924 : Info::Info(const CLToolOptions& co ):
76 1924 : CLTool(co) {
77 1924 : inputdata=commandline;
78 1924 : }
79 :
80 1920 : int Info::main(FILE* in, FILE*out,Communicator& pc) {
81 :
82 : bool printconfiguration;
83 1920 : parseFlag("--configuration",printconfiguration);
84 : bool printroot;
85 1920 : parseFlag("--root",printroot);
86 : bool printuserdoc;
87 1920 : parseFlag("--user-doc",printuserdoc);
88 : bool printdeveloperdoc;
89 1920 : parseFlag("--developer-doc",printdeveloperdoc);
90 : bool printversion;
91 1920 : parseFlag("--version",printversion);
92 : bool printlongversion;
93 1920 : parseFlag("--long-version",printlongversion);
94 : bool printgitversion;
95 1920 : parseFlag("--git-version",printgitversion);
96 : bool printincludedir;
97 1920 : parseFlag("--include-dir",printincludedir);
98 : bool printsoext;
99 1920 : parseFlag("--soext",printsoext);
100 1920 : if(printroot) {
101 1260 : std::fprintf(out,"%s\n",config::getPlumedRoot().c_str());
102 : }
103 1920 : if(printconfiguration) {
104 64 : std::fprintf(out,"%s",config::getMakefile().c_str());
105 : }
106 1920 : if(printincludedir) {
107 0 : std::fprintf(out,"%s\n",config::getPlumedIncludedir().c_str());
108 : }
109 1920 : 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 1920 : 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 1920 : if(printversion) {
132 0 : std::fprintf(out,"%s\n",config::getVersion().c_str());
133 : }
134 1920 : if(printlongversion) {
135 0 : std::fprintf(out,"%s\n",config::getVersionLong().c_str());
136 : }
137 1920 : if(printgitversion) {
138 0 : std::fprintf(out,"%s\n",config::getVersionGit().c_str());
139 : }
140 1920 : if(printsoext) {
141 2516 : std::fprintf(out,"%s\n",config::getSoExt().c_str());
142 : }
143 :
144 1920 : return 0;
145 : }
146 :
147 :
148 :
149 : }
150 : }
|