Commands
- Implemented the ability to iterate over installed Command objects, to augment the '_commands' command. - Renamed verbosity tokens, to de-pluralize them.
This commit is contained in:
@@ -119,9 +119,9 @@ void Context::initialize2 (int argc, char** argv)
|
|||||||
// TODO Load relevant rc file.
|
// TODO Load relevant rc file.
|
||||||
|
|
||||||
// Instantiate built-in command objects.
|
// Instantiate built-in command objects.
|
||||||
commands.push_back (Command::factory ("exec"));
|
commands["exec"] = Command::factory ("exec");
|
||||||
commands.push_back (Command::factory ("install"));
|
commands["install"] = Command::factory ("install");
|
||||||
commands.push_back (Command::factory ("_logo"));
|
commands["logo"] = Command::factory ("_logo");
|
||||||
|
|
||||||
// TODO Instantiate extension command objects.
|
// TODO Instantiate extension command objects.
|
||||||
// TODO Instantiate default command object.
|
// TODO Instantiate default command object.
|
||||||
@@ -248,15 +248,15 @@ int Context::dispatch2 (std::string &out)
|
|||||||
|
|
||||||
updateXtermTitle ();
|
updateXtermTitle ();
|
||||||
|
|
||||||
std::vector <Command*>::iterator c;
|
std::map <std::string, Command*>::iterator c;
|
||||||
for (c = commands.begin (); c != commands.end (); ++c)
|
for (c = commands.begin (); c != commands.end (); ++c)
|
||||||
{
|
{
|
||||||
if ((*c)->implements (commandLine))
|
if (c->second->implements (commandLine))
|
||||||
{
|
{
|
||||||
if (! (*c)->read_only ())
|
if (! c->second->read_only ())
|
||||||
tdb.gc ();
|
tdb.gc ();
|
||||||
|
|
||||||
return (*c)->execute (commandLine, out);
|
return c->second->execute (commandLine, out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,37 +85,37 @@ private:
|
|||||||
void updateXtermTitle ();
|
void updateXtermTitle ();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Config config;
|
Config config;
|
||||||
Filter filter;
|
Filter filter;
|
||||||
Sequence sequence;
|
Sequence sequence;
|
||||||
Subst subst;
|
Subst subst;
|
||||||
Task task;
|
Task task;
|
||||||
TDB tdb; // TODO Obsolete
|
TDB tdb; // TODO Obsolete
|
||||||
TDB2 tdb2;
|
TDB2 tdb2;
|
||||||
std::string program;
|
std::string program;
|
||||||
std::vector <std::string> args;
|
std::vector <std::string> args;
|
||||||
std::string commandLine;
|
std::string commandLine;
|
||||||
std::string file_override;
|
std::string file_override;
|
||||||
std::string var_overrides;
|
std::string var_overrides;
|
||||||
Cmd cmd; // TODO Obsolete
|
Cmd cmd; // TODO Obsolete
|
||||||
std::map <std::string, std::string> aliases;
|
std::map <std::string, std::string> aliases;
|
||||||
std::vector <std::string> tagAdditions;
|
std::vector <std::string> tagAdditions;
|
||||||
std::vector <std::string> tagRemovals;
|
std::vector <std::string> tagRemovals;
|
||||||
Hooks hooks;
|
Hooks hooks;
|
||||||
DOM dom;
|
DOM dom;
|
||||||
bool use_color;
|
bool use_color;
|
||||||
|
|
||||||
bool verbosity_legacy;
|
bool verbosity_legacy;
|
||||||
std::vector <std::string> verbosity;
|
std::vector <std::string> verbosity;
|
||||||
std::vector <std::string> headers;
|
std::vector <std::string> headers;
|
||||||
std::vector <std::string> footnotes;
|
std::vector <std::string> footnotes;
|
||||||
std::vector <std::string> debugMessages;
|
std::vector <std::string> debugMessages;
|
||||||
bool inShadow;
|
bool inShadow;
|
||||||
|
|
||||||
std::vector <Command*> commands;
|
std::map <std::string, Command*> commands;
|
||||||
|
|
||||||
int terminal_width;
|
int terminal_width;
|
||||||
int terminal_height;
|
int terminal_height;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -453,6 +453,10 @@ int handleCompletionCommands (std::string& outs)
|
|||||||
std::vector <std::string> commands;
|
std::vector <std::string> commands;
|
||||||
context.cmd.allCommands (commands);
|
context.cmd.allCommands (commands);
|
||||||
|
|
||||||
|
std::map <std::string, Command*>::iterator i;
|
||||||
|
for (i = context.commands.begin (); i != context.commands.end (); ++i)
|
||||||
|
commands.push_back (i->first);
|
||||||
|
|
||||||
// Sort alphabetically.
|
// Sort alphabetically.
|
||||||
std::sort (commands.begin (), commands.end ());
|
std::sort (commands.begin (), commands.end ());
|
||||||
|
|
||||||
|
|||||||
@@ -99,10 +99,16 @@ int CmdLogo::execute (const std::string& commandLine, std::string& output)
|
|||||||
""
|
""
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!context.color ())
|
||||||
|
throw std::string ("The _logo command requires that color support is enabled.");
|
||||||
|
|
||||||
|
std::string indent (context.config.getInteger ("indent.report"), ' ');
|
||||||
output += optionalBlankLine ();
|
output += optionalBlankLine ();
|
||||||
|
|
||||||
for (int line = 0; data[line][0]; ++line)
|
for (int line = 0; data[line][0]; ++line)
|
||||||
{
|
{
|
||||||
|
output += indent;
|
||||||
|
|
||||||
for (int c = 0; c < 14; ++c)
|
for (int c = 0; c < 14; ++c)
|
||||||
{
|
{
|
||||||
int value = (int) data[line][c];
|
int value = (int) data[line][c];
|
||||||
|
|||||||
@@ -57,9 +57,7 @@ Command::Command ()
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
Command::Command (const Command& other)
|
Command::Command (const Command& other)
|
||||||
{
|
{
|
||||||
/*
|
// _all = other._all;
|
||||||
_minimum = other._minimum;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -67,9 +65,7 @@ Command& Command::operator= (const Command& other)
|
|||||||
{
|
{
|
||||||
if (this != &other)
|
if (this != &other)
|
||||||
{
|
{
|
||||||
/*
|
// _all = other._all;
|
||||||
_name = other._name;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@@ -78,15 +74,8 @@ Command& Command::operator= (const Command& other)
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool Command::operator== (const Command& other) const
|
bool Command::operator== (const Command& other) const
|
||||||
{
|
{
|
||||||
|
// return _all == other._all;
|
||||||
return false;
|
return false;
|
||||||
/*
|
|
||||||
return _name == other._name &&
|
|
||||||
_minimum == other._minimum &&
|
|
||||||
_maximum == other._maximum &&
|
|
||||||
_wrap == other._wrap &&
|
|
||||||
_just == other._just &&
|
|
||||||
_sizing == other._sizing;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -43,8 +43,6 @@ public:
|
|||||||
virtual bool read_only () const;
|
virtual bool read_only () const;
|
||||||
virtual bool implements (const std::string&) const = 0;
|
virtual bool implements (const std::string&) const = 0;
|
||||||
virtual int execute (const std::string&, std::string&) = 0;
|
virtual int execute (const std::string&, std::string&) = 0;
|
||||||
|
|
||||||
private:
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ int handleCustomReport (const std::string& report, std::string& outs)
|
|||||||
|
|
||||||
// Adjust for fluff in the output.
|
// Adjust for fluff in the output.
|
||||||
if (maxlines)
|
if (maxlines)
|
||||||
maxlines -= (context.verbose ("blanklines") ? 1 : 0)
|
maxlines -= (context.verbose ("blank") ? 1 : 0)
|
||||||
+ table_header
|
+ table_header
|
||||||
+ context.headers.size ()
|
+ context.headers.size ()
|
||||||
+ context.footnotes.size ();
|
+ context.footnotes.size ();
|
||||||
|
|||||||
@@ -402,7 +402,7 @@ std::string ucFirst (const std::string& input)
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
const char* optionalBlankLine ()
|
const char* optionalBlankLine ()
|
||||||
{
|
{
|
||||||
return context.verbose ("blanklines") ? newline : noline;
|
return context.verbose ("blank") ? newline : noline;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user