LCOV - code coverage report
Current view: top level - cltools - Info.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 54 56 96.4 %
Date: 2026-11-05 10:19:04 Functions: 7 7 100.0 %

          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 use this command to get information about the PLUMED version you have installed.  For example if you want to find out the root
      37             : directory for your plumed distribution you can use the following command.
      38             : 
      39             : ```plumed
      40             : plumed info --root
      41             : ```
      42             : 
      43             : */
      44             : //+ENDPLUMEDOC
      45             : 
      46             : class Info:
      47             :   public CLTool {
      48             : public:
      49             :   static void registerKeywords( Keywords& keys );
      50             :   explicit Info(const CLToolOptions& co );
      51             :   int main(FILE* in, FILE*out,Communicator& pc) override;
      52           7 :   std::string description()const override {
      53           7 :     return "provide information about plumed";
      54             :   }
      55             : };
      56             : 
      57       25152 : PLUMED_REGISTER_CLTOOL(Info,"info")
      58             : 
      59        7321 : void Info::registerKeywords( Keywords& keys ) {
      60        7321 :   CLTool::registerKeywords( keys );
      61        7321 :   keys.addFlag("--configuration",false,"prints the configuration file");
      62        7321 :   keys.addFlag("--root",false,"print the location of the root directory for the plumed source");
      63        7321 :   keys.addFlag("--user-doc",false,"print the location of user manual (html)");
      64        7321 :   keys.addFlag("--developer-doc",false,"print the location of user manual (html)");
      65        7321 :   keys.addFlag("--version",false,"print the version number");
      66        7321 :   keys.addFlag("--long-version",false,"print the version number (long version)");
      67        7321 :   keys.addFlag("--git-version",false,"print the version number (git version, if available)");
      68        7321 :   keys.addFlag("--include-dir",false,"print the location of the include dir");
      69        7321 :   keys.addFlag("--soext",false,"print the extension of shared libraries (so or dylib)");
      70        7321 : }
      71             : 
      72        3189 : Info::Info(const CLToolOptions& co ):
      73        3189 :   CLTool(co) {
      74        3189 :   inputdata=inputType::commandline;
      75        3189 : }
      76             : 
      77        3182 : int Info::main(FILE* in, FILE*out,Communicator& pc) {
      78             : 
      79             :   bool printconfiguration;
      80        3182 :   parseFlag("--configuration",printconfiguration);
      81             :   bool printroot;
      82        3182 :   parseFlag("--root",printroot);
      83             :   bool printuserdoc;
      84        3182 :   parseFlag("--user-doc",printuserdoc);
      85             :   bool printdeveloperdoc;
      86        3182 :   parseFlag("--developer-doc",printdeveloperdoc);
      87             :   bool printversion;
      88        3182 :   parseFlag("--version",printversion);
      89             :   bool printlongversion;
      90        3182 :   parseFlag("--long-version",printlongversion);
      91             :   bool printgitversion;
      92        3182 :   parseFlag("--git-version",printgitversion);
      93             :   bool printincludedir;
      94        3182 :   parseFlag("--include-dir",printincludedir);
      95             :   bool printsoext;
      96        3182 :   parseFlag("--soext",printsoext);
      97        3182 :   if(printroot) {
      98        2056 :     std::fprintf(out,"%s\n",config::getPlumedRoot().c_str());
      99             :   }
     100        3182 :   if(printconfiguration) {
     101         194 :     std::fprintf(out,"%s",config::getMakefile().c_str());
     102             :   }
     103        3182 :   if(printincludedir) {
     104           2 :     std::fprintf(out,"%s\n",config::getPlumedIncludedir().c_str());
     105             :   }
     106        3182 :   if(printuserdoc) {
     107           2 :     std::string userdoc=config::getPlumedHtmldir()+"/user-doc/html/index.html";
     108           1 :     FILE *ff=std::fopen(userdoc.c_str(),"r");
     109             :     // no exception here
     110           1 :     if(ff) {
     111           0 :       std::fclose(ff);
     112             :     } else {
     113           3 :       userdoc="https://www.plumed.org/doc-v" + config::getVersion() + "/user-doc/html/index.html";
     114             :     }
     115             :     std::fprintf(out,"%s\n",userdoc.c_str());
     116             :   }
     117        3182 :   if(printdeveloperdoc) {
     118           2 :     std::string developerdoc=config::getPlumedHtmldir()+"/developer-doc/html/index.html";
     119           1 :     FILE *ff=std::fopen(developerdoc.c_str(),"r");
     120             :     // no exception here
     121           1 :     if(ff) {
     122           0 :       std::fclose(ff);
     123             :     } else {
     124           3 :       developerdoc="https://www.plumed.org/doc-v" + config::getVersion() + "/developer-doc/html/index.html";
     125             :     }
     126             :     std::fprintf(out,"%s\n",developerdoc.c_str());
     127             :   }
     128        3182 :   if(printversion) {
     129           2 :     std::fprintf(out,"%s\n",config::getVersion().c_str());
     130             :   }
     131        3182 :   if(printlongversion) {
     132           2 :     std::fprintf(out,"%s\n",config::getVersionLong().c_str());
     133             :   }
     134        3182 :   if(printgitversion) {
     135           2 :     std::fprintf(out,"%s\n",config::getVersionGit().c_str());
     136             :   }
     137        3182 :   if(printsoext) {
     138        4102 :     std::fprintf(out,"%s\n",config::getSoExt().c_str());
     139             :   }
     140             : 
     141        3182 :   return 0;
     142             : }
     143             : 
     144             : 
     145             : 
     146             : }
     147             : }

Generated by: LCOV version 1.16