00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00040
#include "HelpCommand.h"
00041
#include <iostream>
00042
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")
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 }
00149