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 "core/ActionRegister.h" 26 : #include <cstdio> 27 : #include <string> 28 : #include <iostream> 29 : 30 : namespace PLMD { 31 : namespace cltools { 32 : 33 : //+PLUMEDOC TOOLS gentemplate 34 : /* 35 : gentemplate is a tool that you can use to construct template inputs for the various actions 36 : 37 : The templates generated by this tool are primarily for use with Toni Giorgino's VMD GUI. It may be 38 : useful however to use this tool as a quick aid memoir. For example, if you want to understand the documentation 39 : for the DISTANCE command you can generate its template by using the following command 40 : 41 : ```plumed 42 : plumed gentemplate --action DISTANCE 43 : ``` 44 : 45 : */ 46 : //+ENDPLUMEDOC 47 : 48 : class GenTemplate: 49 : public CLTool { 50 : public: 51 : static void registerKeywords( Keywords& keys ); 52 : explicit GenTemplate(const CLToolOptions& co ); 53 : int main(FILE* in, FILE*out,Communicator& pc) override; 54 5 : std::string description()const override { 55 5 : return "print out a template input for a particular action"; 56 : } 57 : }; 58 : 59 16259 : PLUMED_REGISTER_CLTOOL(GenTemplate,"gentemplate") 60 : 61 5418 : void GenTemplate::registerKeywords( Keywords& keys ) { 62 5418 : CLTool::registerKeywords( keys ); 63 5418 : keys.add("optional","--action","print the template for this particular action"); 64 5418 : keys.addFlag("--list",false,"print a list of the available actions"); 65 5418 : keys.addFlag("--include-optional",false,"also print optional modifiers"); 66 5418 : } 67 : 68 5 : GenTemplate::GenTemplate(const CLToolOptions& co ): 69 5 : CLTool(co) { 70 5 : inputdata=commandline; 71 5 : } 72 : 73 0 : int GenTemplate::main(FILE* in, FILE*out,Communicator& pc) { 74 : 75 : std::string action; 76 0 : bool list_templates=false; 77 0 : parseFlag("--list",list_templates); 78 : 79 0 : if(list_templates) { 80 0 : std::cerr<<actionRegister()<<"\n"; 81 : return 0; 82 0 : } else if(parse("--action",action)) { 83 : bool include_optional; 84 0 : parseFlag("--include-optional",include_optional); 85 0 : if( !actionRegister().printTemplate(action,include_optional) ) { 86 0 : error("there is no registered action named " + action); 87 : return 1; 88 : } 89 : } else { 90 : return 1; 91 : } 92 : 93 : 94 : 95 0 : return 0; 96 : } 97 : } 98 : 99 : } // End of namespace