HelpAction.cpp
Go to the documentation of this file.
/* Frobby: Software for monomial ideal computations.
Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
*/
#include "frobby.h"
#include "stdinc.h"
#include "HelpAction.h"
#include "Parameter.h"
#include "IOHandler.h"
#include "DataType.h"
#include "error.h"
#include "display.h"
#include "FrobbyStringStream.h"
#include "ColumnPrinter.h"
#include <algorithm>
HelpAction::HelpAction():
Action
(staticGetName(),
"Display this help screen.",
"Typing `frobby help' displays a list of the available actions.\n"
"Typing `frobby help ACTION' displays a detailed description of that "
"action.\n\n"
"As an example, typing `frobby help irrdecom' will yield detailed "
"information\n"
"about the irrdecom action.",
true) {
}
void HelpAction::obtainParameters(vector<Parameter*>& parameters) {
}
void HelpAction::processNonParameter(const char* str) {
_topic = str;
}
namespace {
// Helper function for displayActionHelp().
bool paramCmp(Parameter* a, Parameter* b) {
ASSERT(a != 0);
ASSERT(b != 0);
return string(a->getName()) < b->getName();
}
}
void HelpAction::displayActionHelp(Action& action) {
FrobbyStringStream out;
out << "Displaying information on action: " << action.getName() << "\n\n";
out << action.getDescription() << "\n";
vector<Parameter*> parameters;
action.obtainParameters(parameters);
sort(parameters.begin(), parameters.end(), paramCmp);
display(out);
if (!parameters.empty()) {
fprintf(stderr, "\nThe parameters accepted by %s are as follows.\n",
action.getName());
typedef vector<Parameter*>::const_iterator cit;
for (cit it = parameters.begin(); it != parameters.end(); ++it) {
string defaultValue = (*it)->getValueAsString();
fprintf(stderr, "\n -%s %s (default is %s)\n",
(*it)->getName().c_str(),
(*it)->getArgumentType().c_str(),
(*it)->getValueAsString().c_str());
display((*it)->getDescription(), " ");
}
}
}
void HelpAction::displayIOHelp() {
display
("Displaying information on topic: io\n"
"\n"
"Frobby understands several file formats. These are not documented, "
"but they are simple enough that seeing an example should be enough "
"to figure them out. Getting an example is as simple as making "
"Frobby produce output in that format. "
"\n\n"
"It is true of all the formats that white-space is insignificant, "
"but other than that Frobby is quite fuzzy about how the input "
"must look. E.g. a Macaulay 2 file containing a monomial ideal "
"must start with \"R = \", so writing \"r = \" with a lower-case r "
"is an error. To help with this, Frobby tries to say what is wrong "
"if there is an error."
"\n\n"
"If no input format is specified, Frobby will guess at the format, "
"and it will guess correctly if there are no errors in the input. "
"If no output format is specified, Frobby will use the same format "
"for output as for input. If you want to force Frobby to use a "
"specific format, use the -iformat and -oformat options. Using "
"these with the transform action allows translation between formats. "
"\n\n"
"The formats available in Frobby and the types of data they "
"support are as follows. "
"\n");
vector<string> names;
getIOHandlerNames(names);
for (vector<string>::const_iterator name = names.begin();
name != names.end(); ++name) {
unique_ptr<IOHandler> handler = createIOHandler(*name);
ASSERT(handler.get() != 0);
fprintf(stderr, "\n* The format %s: %s\n",
handler->getName(),
handler->getDescription());
vector<const DataType*> types = DataType::getTypes();
for (vector<const DataType*>::const_iterator typeIt = types.begin();
typeIt != types.end(); ++typeIt) {
const DataType& type = **typeIt;
bool input = handler->supportsInput(type);
bool output = handler->supportsOutput(type);
const char* formatStr = "";
if (input && output)
formatStr = " - supports input and output of %s.\n";
else if (input)
formatStr = " - supports input of %s.\n";
else if (output)
formatStr = " - supports output of %s.\n";
fprintf(stderr, formatStr, type.getName());
}
}
}
void HelpAction::perform() {
if (_topic != "") {
if (_topic == "io")
displayIOHelp();
else
displayActionHelp(*Action::createActionWithPrefix(_topic));
return;
}
FrobbyStringStream out;
out << "Frobby version " << frobby_version
<< " Copyright (C) 2007 Bjarke Hammersholt Roune\n";
out <<
"Frobby performs a number of computations related to monomial "
"ideals.\nYou run it by typing `frobby ACTION', where ACTION is "
"one of the following. "
"\n\n";
ColumnPrinter printer;
printer.addColumn(false, " ");
printer.addColumn(true, " - ");
vector<string> names;
Action::getActionNames(names);
for (vector<string>::const_iterator it = names.begin();
it != names.end(); ++it) {
unique_ptr<Action> action(Action::createActionWithPrefix(*it));
if (action->displayAction()) {
printer[0] << action->getName() << '\n';
printer[1] << action->getShortDescription() << '\n';
}
}
printer.print(out);
out <<
"\nType 'frobby help ACTION' to get more details on a specific action.\n"
"Note that all input and output is done via the standard streams.\n"
"Type 'frobby help io' for more information on input and output formats.\n"
"See www.broune.com for further information and new versions of Frobby.\n"
"\n"
"Frobby is free software and you are welcome to redistribute it under certain "
"conditions. Frobby comes with ABSOLUTELY NO WARRANTY. See the GNU General "
"Public License version 2.0 in the file COPYING for details.\n";
display(out);
}
const char* HelpAction::staticGetName() {
return "help";
}
bool HelpAction::displayAction() const {
return false;
}
ColumnPrinter.h
DataType.h
FrobbyStringStream.h
HelpAction.h
getIOHandlerNames
void getIOHandlerNames(vector< string > &names)
Add the name of each fomat to names.
Definition IOHandler.cpp:156
createIOHandler
unique_ptr< IOHandler > createIOHandler(const string &prefix)
Returns an IOHandler for the format whose name has the given prefix.
Definition IOHandler.cpp:145
IOHandler.h
Parameter.h
Action::getName
const char * getName() const
Definition Action.cpp:113
Action::Action
Action(const char *name, const char *shortDescription, const char *description, bool acceptsNonParameter)
Definition Action.cpp:46
Action::getDescription
const char * getDescription() const
Definition Action.cpp:121
Action::obtainParameters
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition Action.cpp:133
Action::getActionNames
static void getActionNames(vector< string > &names)
Definition Action.cpp:105
Action::createActionWithPrefix
static unique_ptr< Action > createActionWithPrefix(const string &prefix)
Definition Action.cpp:109
ColumnPrinter
Definition ColumnPrinter.h:27
ColumnPrinter::print
void print(ostream &out) const
Definition ColumnPrinter.cpp:70
ColumnPrinter::addColumn
void addColumn(bool flushLeft=true, const string &prefix=" ", const string &suffix="")
Definition ColumnPrinter.cpp:51
DataType
The intention of this class is to describe the different kinds of mathematical structures that Frobby...
Definition DataType.h:29
DataType::getName
const char * getName() const
Returns the name of the structure.
Definition DataType.cpp:24
DataType::getTypes
static vector< const DataType * > getTypes()
Returns a vector of all types except null.
Definition DataType.cpp:64
FrobbyStringStream
A replacement for stringstream.
Definition FrobbyStringStream.h:26
HelpAction::processNonParameter
virtual void processNonParameter(const char *str)
Definition HelpAction.cpp:47
HelpAction::HelpAction
HelpAction()
Definition HelpAction.cpp:31
HelpAction::displayAction
virtual bool displayAction() const
Returns whether this action should be shown to the user by the help action.
Definition HelpAction.cpp:199
HelpAction::_topic
string _topic
Definition HelpAction.h:40
HelpAction::perform
virtual void perform()
Definition HelpAction.cpp:147
HelpAction::staticGetName
static const char * staticGetName()
Definition HelpAction.cpp:195
HelpAction::obtainParameters
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition HelpAction.cpp:44
HelpAction::displayIOHelp
void displayIOHelp()
Definition HelpAction.cpp:87
HelpAction::displayActionHelp
void displayActionHelp(Action &action)
Definition HelpAction.cpp:60
Parameter
Definition Parameter.h:24
Parameter::getName
const string & getName() const
Definition Parameter.h:29
display
void display(const string &msg, const string &prepend)
Display msg to standard error with automatic line breaking.
Definition display.cpp:131
display.h
This file contains functions for printing strings to standard error.
error.h
frobby_version
const char *const frobby_version
Definition frobby.cpp:36
frobby.h
stdinc.h
This header file includes common definitions and is included as the first line of code in every imple...
ASSERT
#define ASSERT(X)
Definition stdinc.h:86