- 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:
Paul Beckingham 2011-05-14 12:18:39 -04:00
parent 02c2023dc4
commit 557440db0c
13 changed files with 215 additions and 141 deletions

View file

@ -5,6 +5,7 @@ include_directories (${CMAKE_SOURCE_DIR}/src
${TASK_INCLUDE_DIRS})
set (commands_SRCS Command.cpp Command.h
CmdExec.cpp CmdExec.h
CmdInstall.cpp CmdInstall.h
CmdLogo.cpp CmdLogo.h)

58
src/commands/CmdExec.cpp Normal file
View 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
View 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
////////////////////////////////////////////////////////////////////////////////

View file

@ -33,61 +33,18 @@ extern Context context;
////////////////////////////////////////////////////////////////////////////////
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 ()
{
}
////////////////////////////////////////////////////////////////////////////////
bool CmdInstall::read_only () const
{
return false;
}
////////////////////////////////////////////////////////////////////////////////
bool CmdInstall::implements (const std::string& command_line) const
{
std::cout << "# CmdInstall::implements\n";
return false;
}
@ -97,9 +54,10 @@ bool CmdInstall::implements (const std::string& command_line) const
// Generate UUID
// Call the "install" function once, store results in rc:
// 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;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -34,14 +34,10 @@ class CmdInstall : public Command
{
public:
CmdInstall ();
CmdInstall (const CmdInstall&);
CmdInstall& operator= (const CmdInstall&);
bool operator== (const CmdInstall&) const; // TODO Is this necessary?
~CmdInstall ();
bool read_only () const;
bool implements (const std::string&) const;
std::string execute (const std::string&);
int execute (const std::string&, std::string&);
private:
};

View file

@ -28,52 +28,15 @@
#include <iostream>
#include <CmdLogo.h>
#include <Context.h>
#include <text.h>
extern Context context;
////////////////////////////////////////////////////////////////////////////////
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 ()
{
@ -82,12 +45,16 @@ CmdLogo::~CmdLogo ()
////////////////////////////////////////////////////////////////////////////////
bool CmdLogo::read_only () const
{
return false;
return true;
}
////////////////////////////////////////////////////////////////////////////////
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;
}
@ -97,7 +64,7 @@ bool CmdLogo::implements (const std::string& command_line) const
// Generate UUID
// Call the "install" function once, store results in rc:
// extension.<uuid>=<JSON>
std::string CmdLogo::execute (const std::string&)
int CmdLogo::execute (const std::string& commandLine, std::string& output)
{
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 c = 0; c < 14; ++c)
{
int value = (int) data[line][c];
@ -163,9 +130,13 @@ std::string CmdLogo::execute (const std::string&)
output += block;
}
}
output += "\n";
}
return output;
output += optionalBlankLine ();
return 0;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -34,14 +34,11 @@ class CmdLogo : public Command
{
public:
CmdLogo ();
CmdLogo (const CmdLogo&);
CmdLogo& operator= (const CmdLogo&);
bool operator== (const CmdLogo&) const; // TODO Is this necessary?
~CmdLogo ();
bool read_only () const;
bool implements (const std::string&) const;
std::string execute (const std::string&);
int execute (const std::string&, std::string&);
private:
};

View file

@ -27,6 +27,7 @@
#include <iostream>
#include <Command.h>
#include <CmdExec.h>
#include <CmdInstall.h>
#include <CmdLogo.h>
#include <Context.h>
@ -37,10 +38,13 @@ extern Context context;
Command* Command::factory (const std::string& name)
{
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
throw std::string ("Unrecognized command '") + name + "'";
throw std::string ("Unrecognized command object '") + name + "'";
// TODO Initialize command object.
return command;
}
@ -71,12 +75,6 @@ Command& Command::operator= (const Command& other)
return *this;
}
////////////////////////////////////////////////////////////////////////////////
bool Command::read_only () const
{
return false;
}
////////////////////////////////////////////////////////////////////////////////
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;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -42,7 +42,7 @@ public:
virtual bool read_only () const;
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:
};