Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

HelpCommand.cc

Go to the documentation of this file.
00001 // -*- C++ -*- 00002 00003 // HelpCommand.cc 00004 // 00005 // Copyright (C) 2003 Pascal Vincent 00006 // 00007 // Redistribution and use in source and binary forms, with or without 00008 // modification, are permitted provided that the following conditions are met: 00009 // 00010 // 1. Redistributions of source code must retain the above copyright 00011 // notice, this list of conditions and the following disclaimer. 00012 // 00013 // 2. Redistributions in binary form must reproduce the above copyright 00014 // notice, this list of conditions and the following disclaimer in the 00015 // documentation and/or other materials provided with the distribution. 00016 // 00017 // 3. The name of the authors may not be used to endorse or promote 00018 // products derived from this software without specific prior written 00019 // permission. 00020 // 00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 // 00032 // This file is part of the PLearn library. For more information on the PLearn 00033 // library, go to the PLearn Web site at www.plearn.org 00034 00035 /* ******************************************************* 00036 * $Id: HelpCommand.cc,v 1.9 2004/07/21 16:30:49 chrish42 Exp $ 00037 ******************************************************* */ 00038 00040 #include "HelpCommand.h" 00041 #include <iostream> 00042 //#include "general.h" 00043 #include <plearn/db/getDataSet.h> 00044 00045 namespace PLearn { 00046 using namespace std; 00047 00049 PLearnCommandRegistry HelpCommand::reg_(new HelpCommand); 00050 00051 void HelpCommand::helpOverview() 00052 { 00053 cout << 00054 "To run a .plearn script type: " + prgname() + " scriptfile.plearn \n" 00055 "To run a command type: " + prgname() + " command [ command arguments ] \n\n" 00056 "To get help on the script file format: " + prgname() + " help scripts \n" 00057 "To get a short description of available commands: " + prgname() + " help commands \n" 00058 "To get detailed help on a specific command: " + prgname() + " help <command_name> \n" 00059 "To get help on a specific PLearn object: " + prgname() + " help <object_type_name> \n" 00060 "To get help on datasets: " + prgname() + " help datasets \n" 00061 << endl; 00062 } 00063 00064 void HelpCommand::helpScripts() 00065 { 00066 cout << 00067 "You can run plearn with the name of a plearn script file as argument\n" 00068 "A plearn script file should have a name ending in .plearn\n\n" 00069 "A plearn script must contain at least one runnable PLearn object\n" 00070 "A typical runnable PLearn object is 'PTester' \n" 00071 "\n" 00072 "You can type '" + prgname() + " help xxx' to get a description and the list of build options\n" 00073 "for any PLearn object xxx linked with the program\n" 00074 "\n" 00075 "A plearn script can use macro variable definitions and expansion. Macro commands start by a $\n" 00076 "ex: $DEFINE{toto}{[1,2,3,4]} ${toto} $INCLUDE{otherfile.pscript} \n" 00077 "Macro variable definitions can also be provided on the command line in the form \n" 00078 "varname=varvalue with each such pair separated by a blank, thus\n" 00079 "allowing for scripts with arguments\n" 00080 "In addition, the following variables are automatically defined from the script's filepath: \n" 00081 "FILEPATH DIRPATH FILENAME FILEBASE FILEEXT \n" 00082 "Ex: if the absolute path to the script file is /home/me/foo.plearn \n" 00083 " Then we'll get: \n" 00084 "FILEPATH = /home/me/foo.plearn \n" 00085 "DIRPATH = /home/me \n" 00086 "FILENAME = foo.plearn \n" 00087 "FILEBASE = foo \n" 00088 "FILEEXT = .plearn \n" 00089 "\n" 00090 "The additional variables are also available:\n" 00091 "DATE = Date in YYYYMMDD format\n" 00092 "TIME = Time in HHMMSS format\n" 00093 "DATETIME = Date and time in YYYYMMDD:HHMMSS format\n" 00094 << endl; 00095 } 00096 00097 void HelpCommand::helpCommands() 00098 { 00099 cout << "To run a command, type:" 00100 << " % " + prgname() + " command_name command_arguments \n" << endl; 00101 00102 cout << "Available commands are: " << endl; 00103 PLearnCommandRegistry::print_command_summary(cout); 00104 cout << endl; 00105 00106 cout << "For more details on a specific command, type: \n" 00107 << " % " << prgname() << " help <command_name> \n" 00108 << endl; 00109 } 00110 00111 void HelpCommand::helpDatasets() 00112 { 00113 cout << getDataSetHelp() << endl; 00114 } 00115 00116 void HelpCommand::helpAboutScript(const string& fname) 00117 { 00118 if(!file_exists(fname)) 00119 PLERROR("Could not open script file %s", fname.c_str()); 00120 cout << 00121 "Help about a script file not yet implemented \n" 00122 << endl; 00123 } 00124 00126 void HelpCommand::run(const vector<string>& args) 00127 { 00128 if(args.size()==0) 00129 helpOverview(); 00130 else 00131 { 00132 string about = args[0]; 00133 if(extract_extension(about)==".plearn") // help is asked about a plearn script 00134 helpAboutScript(about); 00135 if(about=="scripts") 00136 helpScripts(); 00137 else if(about=="commands") 00138 helpCommands(); 00139 else if(about=="datasets") 00140 helpDatasets(); 00141 else if(PLearnCommandRegistry::is_registered(about)) 00142 PLearnCommandRegistry::help(about, cout); 00143 else 00144 displayObjectHelp(cout, about); 00145 } 00146 } 00147 00148 } // end of namespace PLearn 00149

Generated on Tue Aug 17 15:54:55 2004 for PLearn by doxygen 1.3.7