mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-26 06:37:20 +02:00
Commands
- Implemented stubbed Context::initialize2. - Implemented combined command line. - Migrated some code from Context::initialize to ::initialize2. - Integrated ::initialize2 into the startup sequence. - Implemented Context::dispatch2. - Integrated ::dispatch2 into the run sequence. - Implemented Context::updateXtermTitle. - Added debug messages to new Command objects. - Implemented CmdLogo, which implements the _logo command, for fun. - Removed unnecessary base class overrides from Cmd* objects.
This commit is contained in:
parent
02c2023dc4
commit
557440db0c
13 changed files with 215 additions and 141 deletions
101
src/Context.cpp
101
src/Context.cpp
|
@ -53,6 +53,7 @@ Context::Context ()
|
||||||
, tdb ()
|
, tdb ()
|
||||||
, tdb2 ()
|
, tdb2 ()
|
||||||
, program ("")
|
, program ("")
|
||||||
|
, commandLine ("")
|
||||||
, file_override ("")
|
, file_override ("")
|
||||||
, var_overrides ("")
|
, var_overrides ("")
|
||||||
, cmd ()
|
, cmd ()
|
||||||
|
@ -73,27 +74,8 @@ Context::~Context ()
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Context::initialize2 (int argc, char** argv)
|
void Context::initialize2 (int argc, char** argv)
|
||||||
{
|
{
|
||||||
// TODO Capture the args.
|
Timer t ("Context::initialize2");
|
||||||
// TODO Capture any stdin args.
|
|
||||||
// TODO Scan for rc:<file> overrides --> apply.
|
|
||||||
// TODO Combine command line into one string.
|
|
||||||
// TODO Load relevant rc file.
|
|
||||||
|
|
||||||
// TODO Instantiate built-in command objects.
|
|
||||||
commands.push_back (Command::factory ("install"));
|
|
||||||
|
|
||||||
// TODO Instantiate extension command objects.
|
|
||||||
// TODO Instantiate default command object.
|
|
||||||
// TODO Instantiate column objects.
|
|
||||||
// TODO Instantiate UDA objects.
|
|
||||||
// TODO Instantiate format objects.
|
|
||||||
// TODO Instantiate extension format objects.
|
|
||||||
// TODO Hook: on-launch
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
void Context::initialize (int argc, char** argv)
|
|
||||||
{
|
|
||||||
// Capture the args.
|
// Capture the args.
|
||||||
for (int i = 0; i < argc; ++i)
|
for (int i = 0; i < argc; ++i)
|
||||||
{
|
{
|
||||||
|
@ -129,6 +111,34 @@ void Context::initialize (int argc, char** argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO Scan for rc:<file> overrides --> apply.
|
||||||
|
|
||||||
|
// Combine command line into one string.
|
||||||
|
join (commandLine, " ", args);
|
||||||
|
|
||||||
|
// TODO Load relevant rc file.
|
||||||
|
|
||||||
|
// Instantiate built-in command objects.
|
||||||
|
commands.push_back (Command::factory ("exec"));
|
||||||
|
commands.push_back (Command::factory ("install"));
|
||||||
|
commands.push_back (Command::factory ("_logo"));
|
||||||
|
|
||||||
|
// TODO Instantiate extension command objects.
|
||||||
|
// TODO Instantiate default command object.
|
||||||
|
// TODO Instantiate extension UDA objects.
|
||||||
|
// TODO Instantiate extension format objects.
|
||||||
|
// TODO Hook: on-launch
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void Context::initialize (int argc, char** argv)
|
||||||
|
{
|
||||||
|
// Capture the args.
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// Capture any stdin args.
|
||||||
|
// ...
|
||||||
|
|
||||||
initialize ();
|
initialize ();
|
||||||
|
|
||||||
// Hook system init, plus post-start event occurring at the first possible
|
// Hook system init, plus post-start event occurring at the first possible
|
||||||
|
@ -183,7 +193,9 @@ int Context::run ()
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
parse (); // Parse command line.
|
parse (); // Parse command line.
|
||||||
rc = dispatch (output); // Dispatch to command handlers.
|
rc = dispatch2 (output); // Dispatch to new command handlers.
|
||||||
|
if (rc)
|
||||||
|
rc = dispatch (output); // Dispatch to old command handlers.
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (const std::string& error)
|
catch (const std::string& error)
|
||||||
|
@ -229,6 +241,28 @@ int Context::run ()
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
int Context::dispatch2 (std::string &out)
|
||||||
|
{
|
||||||
|
Timer t ("Context::dispatch2");
|
||||||
|
|
||||||
|
updateXtermTitle ();
|
||||||
|
|
||||||
|
std::vector <Command*>::iterator c;
|
||||||
|
for (c = commands.begin (); c != commands.end (); ++c)
|
||||||
|
{
|
||||||
|
if ((*c)->implements (commandLine))
|
||||||
|
{
|
||||||
|
if (! (*c)->read_only ())
|
||||||
|
tdb.gc ();
|
||||||
|
|
||||||
|
return (*c)->execute (commandLine, out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int Context::dispatch (std::string &out)
|
int Context::dispatch (std::string &out)
|
||||||
{
|
{
|
||||||
|
@ -236,16 +270,7 @@ int Context::dispatch (std::string &out)
|
||||||
|
|
||||||
Timer t ("Context::dispatch");
|
Timer t ("Context::dispatch");
|
||||||
|
|
||||||
// For read-only commands, optionally update the xterm window title.
|
updateXtermTitle ();
|
||||||
// Why just the read-only commands? Because this capability is to answer the
|
|
||||||
// question of 'what did I just do to generate this outout?'.
|
|
||||||
if (config.getBoolean ("xterm.title") &&
|
|
||||||
cmd.isReadOnlyCommand ())
|
|
||||||
{
|
|
||||||
std::string title;
|
|
||||||
join (title, " ", args);
|
|
||||||
std::cout << "]0;task " << title << "" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO Chain-of-command pattern dispatch.
|
// TODO Chain-of-command pattern dispatch.
|
||||||
|
|
||||||
|
@ -881,6 +906,7 @@ void Context::clear ()
|
||||||
tdb.clear (); // TODO Obsolete
|
tdb.clear (); // TODO Obsolete
|
||||||
// tdb2.clear ();
|
// tdb2.clear ();
|
||||||
program = "";
|
program = "";
|
||||||
|
commandLine = "";
|
||||||
args.clear ();
|
args.clear ();
|
||||||
file_override = "";
|
file_override = "";
|
||||||
var_overrides = "";
|
var_overrides = "";
|
||||||
|
@ -998,6 +1024,19 @@ void Context::autoFilter (Filter& f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// This capability is to answer the question of 'what did I just do to generate
|
||||||
|
// this output?'.
|
||||||
|
void Context::updateXtermTitle ()
|
||||||
|
{
|
||||||
|
if (config.getBoolean ("xterm.title"))
|
||||||
|
{
|
||||||
|
std::string title;
|
||||||
|
join (title, " ", args);
|
||||||
|
std::cout << "]0;task " << title << "" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Context::header (const std::string& input)
|
void Context::header (const std::string& input)
|
||||||
{
|
{
|
||||||
|
|
|
@ -53,6 +53,7 @@ public:
|
||||||
void initialize2 (int, char**); // all startup
|
void initialize2 (int, char**); // all startup
|
||||||
void initialize (); // for reinitializing
|
void initialize (); // for reinitializing
|
||||||
int run (); // task classic
|
int run (); // task classic
|
||||||
|
int dispatch2 (std::string&); // command handler dispatch
|
||||||
int dispatch (std::string&); // command handler dispatch
|
int dispatch (std::string&); // command handler dispatch
|
||||||
void shadow (); // shadow file update
|
void shadow (); // shadow file update
|
||||||
|
|
||||||
|
@ -81,6 +82,7 @@ private:
|
||||||
void loadAliases ();
|
void loadAliases ();
|
||||||
void autoFilter (Att&, Filter&);
|
void autoFilter (Att&, Filter&);
|
||||||
void autoFilter (Filter&);
|
void autoFilter (Filter&);
|
||||||
|
void updateXtermTitle ();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Config config;
|
Config config;
|
||||||
|
@ -92,6 +94,7 @@ public:
|
||||||
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 file_override;
|
std::string file_override;
|
||||||
std::string var_overrides;
|
std::string var_overrides;
|
||||||
Cmd cmd; // TODO Obsolete
|
Cmd cmd; // TODO Obsolete
|
||||||
|
@ -109,7 +112,6 @@ public:
|
||||||
std::vector <std::string> debugMessages;
|
std::vector <std::string> debugMessages;
|
||||||
bool inShadow;
|
bool inShadow;
|
||||||
|
|
||||||
std::vector <Column*> columns;
|
|
||||||
std::vector <Command*> commands;
|
std::vector <Command*> commands;
|
||||||
|
|
||||||
int terminal_width;
|
int terminal_width;
|
||||||
|
|
|
@ -5,6 +5,7 @@ include_directories (${CMAKE_SOURCE_DIR}/src
|
||||||
${TASK_INCLUDE_DIRS})
|
${TASK_INCLUDE_DIRS})
|
||||||
|
|
||||||
set (commands_SRCS Command.cpp Command.h
|
set (commands_SRCS Command.cpp Command.h
|
||||||
|
CmdExec.cpp CmdExec.h
|
||||||
CmdInstall.cpp CmdInstall.h
|
CmdInstall.cpp CmdInstall.h
|
||||||
CmdLogo.cpp CmdLogo.h)
|
CmdLogo.cpp CmdLogo.h)
|
||||||
|
|
||||||
|
|
58
src/commands/CmdExec.cpp
Normal file
58
src/commands/CmdExec.cpp
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// taskwarrior - a command line task list manager.
|
||||||
|
//
|
||||||
|
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// 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, write to the
|
||||||
|
//
|
||||||
|
// Free Software Foundation, Inc.,
|
||||||
|
// 51 Franklin Street, Fifth Floor,
|
||||||
|
// Boston, MA
|
||||||
|
// 02110-1301
|
||||||
|
// USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <CmdExec.h>
|
||||||
|
#include <Context.h>
|
||||||
|
|
||||||
|
extern Context context;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
CmdExec::CmdExec ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
CmdExec::~CmdExec ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool CmdExec::implements (const std::string& command_line) const
|
||||||
|
{
|
||||||
|
std::cout << "# CmdExec::implements\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
int CmdExec::execute (const std::string& commandLine, std::string& output)
|
||||||
|
{
|
||||||
|
std::cout << "# CmdExec::execute\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
46
src/commands/CmdExec.h
Normal file
46
src/commands/CmdExec.h
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// taskwarrior - a command line task list manager.
|
||||||
|
//
|
||||||
|
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// 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, write to the
|
||||||
|
//
|
||||||
|
// Free Software Foundation, Inc.,
|
||||||
|
// 51 Franklin Street, Fifth Floor,
|
||||||
|
// Boston, MA
|
||||||
|
// 02110-1301
|
||||||
|
// USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
#ifndef INCLUDED_CMDEXEC
|
||||||
|
#define INCLUDED_CMDEXEC
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <Command.h>
|
||||||
|
|
||||||
|
class CmdExec : public Command
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CmdExec ();
|
||||||
|
~CmdExec ();
|
||||||
|
|
||||||
|
bool implements (const std::string&) const;
|
||||||
|
int execute (const std::string&, std::string&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
|
@ -33,61 +33,18 @@ extern Context context;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CmdInstall::CmdInstall ()
|
CmdInstall::CmdInstall ()
|
||||||
/*
|
|
||||||
: _name ("")
|
|
||||||
*/
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
CmdInstall::CmdInstall (const CmdInstall& other)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
_minimum = other._minimum;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
CmdInstall& CmdInstall::operator= (const CmdInstall& other)
|
|
||||||
{
|
|
||||||
if (this != &other)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
_name = other._name;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool CmdInstall::operator== (const CmdInstall& other) const
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
/*
|
|
||||||
return _name == other._name &&
|
|
||||||
_minimum == other._minimum &&
|
|
||||||
_maximum == other._maximum &&
|
|
||||||
_wrap == other._wrap &&
|
|
||||||
_just == other._just &&
|
|
||||||
_sizing == other._sizing;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CmdInstall::~CmdInstall ()
|
CmdInstall::~CmdInstall ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool CmdInstall::read_only () const
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool CmdInstall::implements (const std::string& command_line) const
|
bool CmdInstall::implements (const std::string& command_line) const
|
||||||
{
|
{
|
||||||
|
std::cout << "# CmdInstall::implements\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,9 +54,10 @@ bool CmdInstall::implements (const std::string& command_line) const
|
||||||
// Generate UUID
|
// Generate UUID
|
||||||
// Call the "install" function once, store results in rc:
|
// Call the "install" function once, store results in rc:
|
||||||
// extension.<uuid>=<JSON>
|
// extension.<uuid>=<JSON>
|
||||||
std::string CmdInstall::execute (const std::string&)
|
int CmdInstall::execute (const std::string& commandLine, std::string& output)
|
||||||
{
|
{
|
||||||
return "output";
|
std::cout << "# CmdInstall::execute\n";
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -34,14 +34,10 @@ class CmdInstall : public Command
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CmdInstall ();
|
CmdInstall ();
|
||||||
CmdInstall (const CmdInstall&);
|
|
||||||
CmdInstall& operator= (const CmdInstall&);
|
|
||||||
bool operator== (const CmdInstall&) const; // TODO Is this necessary?
|
|
||||||
~CmdInstall ();
|
~CmdInstall ();
|
||||||
|
|
||||||
bool read_only () const;
|
|
||||||
bool implements (const std::string&) const;
|
bool implements (const std::string&) const;
|
||||||
std::string execute (const std::string&);
|
int execute (const std::string&, std::string&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,52 +28,15 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <CmdLogo.h>
|
#include <CmdLogo.h>
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
|
#include <text.h>
|
||||||
|
|
||||||
extern Context context;
|
extern Context context;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CmdLogo::CmdLogo ()
|
CmdLogo::CmdLogo ()
|
||||||
/*
|
|
||||||
: _name ("")
|
|
||||||
*/
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
CmdLogo::CmdLogo (const CmdLogo& other)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
_minimum = other._minimum;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
CmdLogo& CmdLogo::operator= (const CmdLogo& other)
|
|
||||||
{
|
|
||||||
if (this != &other)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
_name = other._name;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool CmdLogo::operator== (const CmdLogo& other) const
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
/*
|
|
||||||
return _name == other._name &&
|
|
||||||
_minimum == other._minimum &&
|
|
||||||
_maximum == other._maximum &&
|
|
||||||
_wrap == other._wrap &&
|
|
||||||
_just == other._just &&
|
|
||||||
_sizing == other._sizing;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CmdLogo::~CmdLogo ()
|
CmdLogo::~CmdLogo ()
|
||||||
{
|
{
|
||||||
|
@ -82,12 +45,16 @@ CmdLogo::~CmdLogo ()
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool CmdLogo::read_only () const
|
bool CmdLogo::read_only () const
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool CmdLogo::implements (const std::string& command_line) const
|
bool CmdLogo::implements (const std::string& command_line) const
|
||||||
{
|
{
|
||||||
|
// TODO Upgrade to a parsed value.
|
||||||
|
if (command_line.find ("_logo") != std::string::npos)
|
||||||
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +64,7 @@ bool CmdLogo::implements (const std::string& command_line) const
|
||||||
// Generate UUID
|
// Generate UUID
|
||||||
// Call the "install" function once, store results in rc:
|
// Call the "install" function once, store results in rc:
|
||||||
// extension.<uuid>=<JSON>
|
// extension.<uuid>=<JSON>
|
||||||
std::string CmdLogo::execute (const std::string&)
|
int CmdLogo::execute (const std::string& commandLine, std::string& output)
|
||||||
{
|
{
|
||||||
static const char* data[] =
|
static const char* data[] =
|
||||||
{
|
{
|
||||||
|
@ -132,10 +99,10 @@ std::string CmdLogo::execute (const std::string&)
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string output;
|
output += optionalBlankLine ();
|
||||||
|
|
||||||
for (int line = 0; data[line][0]; ++line)
|
for (int line = 0; data[line][0]; ++line)
|
||||||
{
|
{
|
||||||
|
|
||||||
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];
|
||||||
|
@ -163,9 +130,13 @@ std::string CmdLogo::execute (const std::string&)
|
||||||
output += block;
|
output += block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output += "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
output += optionalBlankLine ();
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -34,14 +34,11 @@ class CmdLogo : public Command
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CmdLogo ();
|
CmdLogo ();
|
||||||
CmdLogo (const CmdLogo&);
|
|
||||||
CmdLogo& operator= (const CmdLogo&);
|
|
||||||
bool operator== (const CmdLogo&) const; // TODO Is this necessary?
|
|
||||||
~CmdLogo ();
|
~CmdLogo ();
|
||||||
|
|
||||||
bool read_only () const;
|
bool read_only () const;
|
||||||
bool implements (const std::string&) const;
|
bool implements (const std::string&) const;
|
||||||
std::string execute (const std::string&);
|
int execute (const std::string&, std::string&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <Command.h>
|
#include <Command.h>
|
||||||
|
#include <CmdExec.h>
|
||||||
#include <CmdInstall.h>
|
#include <CmdInstall.h>
|
||||||
#include <CmdLogo.h>
|
#include <CmdLogo.h>
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
|
@ -37,10 +38,13 @@ extern Context context;
|
||||||
Command* Command::factory (const std::string& name)
|
Command* Command::factory (const std::string& name)
|
||||||
{
|
{
|
||||||
Command* command;
|
Command* command;
|
||||||
if (name == "install") command = new CmdInstall ();
|
if (name == "exec") command = new CmdExec ();
|
||||||
|
else if (name == "install") command = new CmdInstall ();
|
||||||
else if (name == "_logo") command = new CmdLogo ();
|
else if (name == "_logo") command = new CmdLogo ();
|
||||||
else
|
else
|
||||||
throw std::string ("Unrecognized command '") + name + "'";
|
throw std::string ("Unrecognized command object '") + name + "'";
|
||||||
|
|
||||||
|
// TODO Initialize command object.
|
||||||
|
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
@ -71,12 +75,6 @@ Command& Command::operator= (const Command& other)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool Command::read_only () const
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool Command::operator== (const Command& other) const
|
bool Command::operator== (const Command& other) const
|
||||||
{
|
{
|
||||||
|
@ -97,3 +95,10 @@ Command::~Command ()
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool Command::read_only () const
|
||||||
|
{
|
||||||
|
std::cout << "# Command::read_only\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -42,7 +42,7 @@ 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 std::string execute (const std::string&) = 0;
|
virtual int execute (const std::string&, std::string&) = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
|
@ -55,7 +55,7 @@ int Context::getWidth ()
|
||||||
terminal_width = buff[1];
|
terminal_width = buff[1];
|
||||||
|
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
out << "Context::getWidth: determined width of " << width << " characters";
|
out << "Context::getWidth: determined width of " << terminal_width << " characters";
|
||||||
debug (out.str ());
|
debug (out.str ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,7 @@ int main (int argc, char** argv)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
context.initialize2 (argc, argv);
|
||||||
context.initialize (argc, argv);
|
context.initialize (argc, argv);
|
||||||
status = context.run ();
|
status = context.run ();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue