mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-25 21:27:19 +02:00
Code Cleanup
- Eliminated obsolete Arguments.h, Arguments.cpp.
This commit is contained in:
parent
ab8a6d9e88
commit
0c08b29e48
24 changed files with 74 additions and 1976 deletions
|
@ -56,8 +56,7 @@ int CmdAdd::execute (std::string& output)
|
|||
task.set ("uuid", uuid ());
|
||||
|
||||
// Apply the command line modifications to the new task.
|
||||
Arguments modifications = context.args.extract_modifications (true);
|
||||
modify_task_description_replace (task, modifications);
|
||||
modify_task_description_replace (task, context.a3.extract_modifications ());
|
||||
apply_defaults (task);
|
||||
|
||||
// Only valid tasks can be added.
|
||||
|
|
|
@ -69,7 +69,7 @@ int CmdAnnotate::execute (std::string& output)
|
|||
}
|
||||
|
||||
// Apply the command line modifications to the completed task.
|
||||
Arguments modifications = context.args.extract_modifications ();
|
||||
A3 modifications = context.a3.extract_modifications ();
|
||||
if (!modifications.size ())
|
||||
throw std::string (STRING_CMD_XPEND_NEED_TEXT);
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ int CmdAppend::execute (std::string& output)
|
|||
}
|
||||
|
||||
// Apply the command line modifications to the started task.
|
||||
Arguments modifications = context.args.extract_modifications ();
|
||||
A3 modifications = context.a3.extract_modifications ();
|
||||
if (!modifications.size ())
|
||||
throw std::string (STRING_CMD_XPEND_NEED_TEXT);
|
||||
|
||||
|
|
|
@ -998,10 +998,10 @@ int CmdBurndownMonthly::execute (std::string& output)
|
|||
Chart chart ('M');
|
||||
|
||||
// Use any filter as a title.
|
||||
if (context.args.size () > 2)
|
||||
if (context.a3.size () > 2)
|
||||
{
|
||||
std::string combined = "("
|
||||
+ context.args.extract_read_only_filter ().combine ()
|
||||
+ context.a3.extract_filter ().combine ()
|
||||
+ ")";
|
||||
chart.description (combined);
|
||||
}
|
||||
|
@ -1042,10 +1042,10 @@ int CmdBurndownWeekly::execute (std::string& output)
|
|||
Chart chart ('W');
|
||||
|
||||
// Use any filter as a title.
|
||||
if (context.args.size () > 2)
|
||||
if (context.a3.size () > 2)
|
||||
{
|
||||
std::string combined = "("
|
||||
+ context.args.extract_read_only_filter ().combine ()
|
||||
+ context.a3.extract_filter ().combine ()
|
||||
+ ")";
|
||||
chart.description (combined);
|
||||
}
|
||||
|
@ -1086,10 +1086,10 @@ int CmdBurndownDaily::execute (std::string& output)
|
|||
Chart chart ('D');
|
||||
|
||||
// Use any filter as a title.
|
||||
if (context.args.size () > 2)
|
||||
if (context.a3.size () > 2)
|
||||
{
|
||||
std::string combined = "("
|
||||
+ context.args.extract_read_only_filter ().combine ()
|
||||
+ context.a3.extract_filter ().combine ()
|
||||
+ ")";
|
||||
chart.description (combined);
|
||||
}
|
||||
|
|
|
@ -86,10 +86,7 @@ int CmdCustom::execute (std::string& output)
|
|||
split (filterArgs, reportFilter, ' ');
|
||||
std::vector <std::string>::iterator arg;
|
||||
for (arg = filterArgs.begin (); arg != filterArgs.end (); ++ arg)
|
||||
{
|
||||
context.args.capture_first (*arg);
|
||||
context.a3.capture_first (*arg);
|
||||
}
|
||||
|
||||
context.a3.categorize ();
|
||||
context.a3.dump ("CmdCustom::execute");
|
||||
|
@ -290,7 +287,7 @@ void CmdCustom::getLimits (const std::string& report, int& rows, int& lines)
|
|||
|
||||
// If the custom report has a defined limit, then allow a numeric override.
|
||||
// This is an integer specified as a filter (limit:10).
|
||||
std::string limit = context.args.find_limit ();
|
||||
std::string limit = context.a3.find_limit ();
|
||||
if (limit != "")
|
||||
{
|
||||
if (limit == "page")
|
||||
|
|
|
@ -70,7 +70,7 @@ int CmdDelete::execute (std::string& output)
|
|||
}
|
||||
|
||||
// Apply the command line modifications to the new task.
|
||||
Arguments modifications = context.args.extract_modifications ();
|
||||
A3 modifications = context.a3.extract_modifications ();
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
|
|
|
@ -69,7 +69,7 @@ int CmdDone::execute (std::string& output)
|
|||
}
|
||||
|
||||
// Apply the command line modifications to the completed task.
|
||||
Arguments modifications = context.args.extract_modifications ();
|
||||
A3 modifications = context.a3.extract_modifications ();
|
||||
|
||||
Permission permission;
|
||||
if (filtered.size () > (size_t) context.config.getInteger ("bulk"))
|
||||
|
|
|
@ -69,7 +69,7 @@ int CmdDuplicate::execute (std::string& output)
|
|||
}
|
||||
|
||||
// Apply the command line modifications to the completed task.
|
||||
Arguments modifications = context.args.extract_modifications ();
|
||||
A3 modifications = context.a3.extract_modifications ();
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
|
|
|
@ -48,12 +48,12 @@ CmdExec::CmdExec ()
|
|||
int CmdExec::execute (std::string& output)
|
||||
{
|
||||
std::string command_line;
|
||||
std::vector <Triple>::iterator arg;
|
||||
for (arg = context.args.begin (); arg != context.args.end (); ++arg)
|
||||
std::vector <Arg>::iterator arg;
|
||||
for (arg = context.a3.begin (); arg != context.a3.end (); ++arg)
|
||||
{
|
||||
if (arg != context.args.begin () &&
|
||||
arg->_first != "execute")
|
||||
command_line += arg->_first;
|
||||
if (arg != context.a3.begin () &&
|
||||
arg->_raw != "execute")
|
||||
command_line += arg->_raw;
|
||||
}
|
||||
|
||||
return system (command_line.c_str ());
|
||||
|
|
|
@ -56,7 +56,7 @@ int CmdLog::execute (std::string& output)
|
|||
task.set ("uuid", uuid ());
|
||||
|
||||
// Apply the command line modifications to the new task.
|
||||
Arguments modifications = context.args.extract_modifications ();
|
||||
A3 modifications = context.a3.extract_modifications ();
|
||||
modify_task_description_replace (task, modifications);
|
||||
apply_defaults (task);
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ int CmdModify::execute (std::string& output)
|
|||
}
|
||||
|
||||
// Apply the command line modifications to the new task.
|
||||
Arguments modifications = context.args.extract_modifications ();
|
||||
A3 modifications = context.a3.extract_modifications ();
|
||||
|
||||
Permission permission;
|
||||
if (filtered.size () > (size_t) context.config.getInteger ("bulk"))
|
||||
|
|
|
@ -69,7 +69,7 @@ int CmdPrepend::execute (std::string& output)
|
|||
}
|
||||
|
||||
// Apply the command line modifications to the started task.
|
||||
Arguments modifications = context.args.extract_modifications ();
|
||||
A3 modifications = context.a3.extract_modifications ();
|
||||
if (!modifications.size ())
|
||||
throw std::string (STRING_CMD_XPEND_NEED_TEXT);
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ int CmdShow::execute (std::string& output)
|
|||
|
||||
// Obtain the arguments from the description. That way, things like '--'
|
||||
// have already been handled.
|
||||
if (context.args.size () > 2)
|
||||
if (context.a3.size () > 2)
|
||||
throw std::string (STRING_CMD_SHOW_ARGS);
|
||||
|
||||
int width = context.getWidth ();
|
||||
|
|
|
@ -69,7 +69,7 @@ int CmdStart::execute (std::string& output)
|
|||
}
|
||||
|
||||
// Apply the command line modifications to the started task.
|
||||
Arguments modifications = context.args.extract_modifications ();
|
||||
A3 modifications = context.a3.extract_modifications ();
|
||||
|
||||
Permission permission;
|
||||
if (filtered.size () > (size_t) context.config.getInteger ("bulk"))
|
||||
|
|
|
@ -69,7 +69,7 @@ int CmdStop::execute (std::string& output)
|
|||
}
|
||||
|
||||
// Apply the command line modifications to the stopped task.
|
||||
Arguments modifications = context.args.extract_modifications ();
|
||||
A3 modifications = context.a3.extract_modifications ();
|
||||
|
||||
Permission permission;
|
||||
if (filtered.size () > (size_t) context.config.getInteger ("bulk"))
|
||||
|
|
|
@ -271,13 +271,7 @@ void Command::filter (std::vector <Task>& input, std::vector <Task>& output)
|
|||
A3 filt = context.a3.extract_filter ();
|
||||
filt.dump ("extract_filter");
|
||||
|
||||
Arguments f;
|
||||
if (read_only ())
|
||||
f = context.args.extract_read_only_filter ();
|
||||
else
|
||||
f = context.args.extract_write_filter ();
|
||||
|
||||
if (f.size ())
|
||||
if (filt.size ())
|
||||
{
|
||||
E9 e (filt);
|
||||
|
||||
|
@ -299,13 +293,7 @@ void Command::filter (std::vector <Task>& output)
|
|||
A3 filt = context.a3.extract_filter ();
|
||||
filt.dump ("extract_filter");
|
||||
|
||||
Arguments f;
|
||||
if (read_only ())
|
||||
f = context.args.extract_read_only_filter ();
|
||||
else
|
||||
f = context.args.extract_write_filter ();
|
||||
|
||||
if (f.size ())
|
||||
if (filt.size ())
|
||||
{
|
||||
const std::vector <Task>& pending = context.tdb2.pending.get_tasks ();
|
||||
E9 e (filt);
|
||||
|
@ -316,7 +304,7 @@ void Command::filter (std::vector <Task>& output)
|
|||
if (e.evalFilter (*task))
|
||||
output.push_back (*task);
|
||||
|
||||
if (! filter_shortcut (f))
|
||||
if (! filter_shortcut (filt))
|
||||
{
|
||||
const std::vector <Task>& completed = context.tdb2.completed.get_tasks (); // TODO Optional
|
||||
for (task = completed.begin (); task != completed.end (); ++task)
|
||||
|
@ -343,23 +331,23 @@ void Command::filter (std::vector <Task>& output)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// If the filter contains the restriction "status:pending", as the first filter
|
||||
// term, then completed.data does not need to be loaded.
|
||||
bool Command::filter_shortcut (const Arguments& filter)
|
||||
bool Command::filter_shortcut (const A3& filter)
|
||||
{
|
||||
/**/
|
||||
if (filter.size () >= 3)
|
||||
{
|
||||
std::cout << "# filter[0] " << filter[0]._first << "\n"
|
||||
<< "# filter[1] " << filter[1]._first << "\n"
|
||||
<< "# filter[2] " << filter[2]._first << "\n";
|
||||
std::cout << "# filter[0] " << filter[0]._raw << "\n"
|
||||
<< "# filter[1] " << filter[1]._raw << "\n"
|
||||
<< "# filter[2] " << filter[2]._raw << "\n";
|
||||
}
|
||||
/**/
|
||||
|
||||
// Postfix: <status> <"pending"> <=>
|
||||
// 0 1 2
|
||||
if (filter.size () >= 3 &&
|
||||
filter[0]._first == "status" &&
|
||||
filter[1]._first.find ("pending") != std::string::npos &&
|
||||
filter[2]._first == "=")
|
||||
if (filter.size () >= 3 &&
|
||||
filter[0]._raw == "status" &&
|
||||
filter[1]._raw.find ("pending") != std::string::npos &&
|
||||
filter[2]._raw == "=")
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -367,7 +355,7 @@ bool Command::filter_shortcut (const Arguments& filter)
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Apply the modifications in arguments to the task.
|
||||
void Command::modify_task_description_replace (Task& task, Arguments& arguments)
|
||||
void Command::modify_task_description_replace (Task& task, const A3& arguments)
|
||||
{
|
||||
std::string description;
|
||||
modify_task (task, arguments, description);
|
||||
|
@ -377,7 +365,7 @@ void Command::modify_task_description_replace (Task& task, Arguments& arguments)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Command::modify_task_description_prepend (Task& task, Arguments& arguments)
|
||||
void Command::modify_task_description_prepend (Task& task, const A3& arguments)
|
||||
{
|
||||
std::string description;
|
||||
modify_task (task, arguments, description);
|
||||
|
@ -387,7 +375,7 @@ void Command::modify_task_description_prepend (Task& task, Arguments& arguments)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Command::modify_task_description_append (Task& task, Arguments& arguments)
|
||||
void Command::modify_task_description_append (Task& task, const A3& arguments)
|
||||
{
|
||||
std::string description;
|
||||
modify_task (task, arguments, description);
|
||||
|
@ -397,7 +385,7 @@ void Command::modify_task_description_append (Task& task, Arguments& arguments)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Command::modify_task_annotate (Task& task, Arguments& arguments)
|
||||
void Command::modify_task_annotate (Task& task, const A3& arguments)
|
||||
{
|
||||
std::string description;
|
||||
modify_task (task, arguments, description);
|
||||
|
@ -410,20 +398,20 @@ void Command::modify_task_annotate (Task& task, Arguments& arguments)
|
|||
// Worker function that does all the updates, but never overwrites description.
|
||||
void Command::modify_task (
|
||||
Task& task,
|
||||
Arguments& arguments,
|
||||
const A3& arguments,
|
||||
std::string& description)
|
||||
{
|
||||
std::vector <Triple>::iterator arg;
|
||||
std::vector <Arg>::const_iterator arg;
|
||||
for (arg = arguments.begin (); arg != arguments.end (); ++arg)
|
||||
{
|
||||
// Attributes are essentially name:value pairs, and correspond directly
|
||||
// to stored attributes.
|
||||
if (arg->_third == "attr")
|
||||
if (arg->_category == "attr")
|
||||
{
|
||||
std::string name;
|
||||
std::string value;
|
||||
Arguments::extract_attr (arg->_first, name, value);
|
||||
if (Arguments::is_attribute (name, name)) // Canonicalize
|
||||
A3::extract_attr (arg->_raw, name, value);
|
||||
if (A3::is_attribute (name, name)) // Canonicalize
|
||||
{
|
||||
// All values must be eval'd first.
|
||||
A3 fragment;
|
||||
|
@ -462,11 +450,11 @@ void Command::modify_task (
|
|||
// Tags need special handling because they are essentially a vector stored
|
||||
// in a single string, therefore Task::{add,remove}Tag must be called as
|
||||
// appropriate.
|
||||
else if (arg->_third == "tag")
|
||||
else if (arg->_category == "tag")
|
||||
{
|
||||
char type;
|
||||
std::string value;
|
||||
Arguments::extract_tag (arg->_first, type, value);
|
||||
A3::extract_tag (arg->_raw, type, value);
|
||||
|
||||
if (type == '+')
|
||||
task.addTag (value);
|
||||
|
@ -475,29 +463,29 @@ void Command::modify_task (
|
|||
}
|
||||
|
||||
// Words and operators are aggregated into a description.
|
||||
else if (arg->_third == "word" ||
|
||||
arg->_third == "op")
|
||||
else if (arg->_category == "word" ||
|
||||
arg->_category == "op")
|
||||
{
|
||||
if (description.length ())
|
||||
description += " ";
|
||||
|
||||
description += arg->_first;
|
||||
description += arg->_raw;
|
||||
}
|
||||
|
||||
// Substitutions.
|
||||
else if (arg->_third == "subst")
|
||||
else if (arg->_category == "subst")
|
||||
{
|
||||
std::string from;
|
||||
std::string to;
|
||||
bool global;
|
||||
Arguments::extract_subst (arg->_first, from, to, global);
|
||||
A3::extract_subst (arg->_raw, from, to, global);
|
||||
task.substitute (from, to, global);
|
||||
}
|
||||
|
||||
// Any additional argument types are indicative of a failure in
|
||||
// Arguments::extract_modifications.
|
||||
// A3::extract_modifications.
|
||||
else
|
||||
throw format (STRING_CMD_MOD_UNEXPECTED, arg->_first);
|
||||
throw format (STRING_CMD_MOD_UNEXPECTED, arg->_raw);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
#include <Task.h>
|
||||
#include <Arguments.h>
|
||||
#include <A3.h>
|
||||
|
||||
class Command
|
||||
{
|
||||
|
@ -55,13 +55,13 @@ public:
|
|||
protected:
|
||||
void filter (std::vector <Task>&, std::vector <Task>&);
|
||||
void filter (std::vector <Task>&);
|
||||
bool filter_shortcut (const Arguments&);
|
||||
bool filter_shortcut (const A3&);
|
||||
|
||||
void modify_task_description_replace (Task&, Arguments&);
|
||||
void modify_task_description_prepend (Task&, Arguments&);
|
||||
void modify_task_description_append (Task&, Arguments&);
|
||||
void modify_task_annotate (Task&, Arguments&);
|
||||
void modify_task (Task&, Arguments&, std::string&);
|
||||
void modify_task_description_replace (Task&, const A3&);
|
||||
void modify_task_description_prepend (Task&, const A3&);
|
||||
void modify_task_description_append (Task&, const A3&);
|
||||
void modify_task_annotate (Task&, const A3&);
|
||||
void modify_task (Task&, const A3&, std::string&);
|
||||
void apply_defaults (Task&);
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue