mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-26 06:37:20 +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
14
src/A3.cpp
14
src/A3.cpp
|
@ -836,7 +836,7 @@ const A3 A3::expand (const A3& input) const
|
||||||
std::string mod;
|
std::string mod;
|
||||||
std::string value;
|
std::string value;
|
||||||
std::string sense;
|
std::string sense;
|
||||||
Arguments::extract_attmod (arg->_raw, name, mod, value, sense);
|
extract_attmod (arg->_raw, name, mod, value, sense);
|
||||||
|
|
||||||
// name.before:value --> name < value
|
// name.before:value --> name < value
|
||||||
if (mod == "before" || mod == "under" || mod == "below")
|
if (mod == "before" || mod == "under" || mod == "below")
|
||||||
|
@ -942,7 +942,7 @@ const A3 A3::expand (const A3& input) const
|
||||||
{
|
{
|
||||||
char type;
|
char type;
|
||||||
std::string value;
|
std::string value;
|
||||||
A3::extract_tag (arg->_raw, type, value);
|
extract_tag (arg->_raw, type, value);
|
||||||
|
|
||||||
expanded.push_back (Arg ("tags", "dom"));
|
expanded.push_back (Arg ("tags", "dom"));
|
||||||
expanded.push_back (Arg (type == '+' ? "~" : "!~", "op"));
|
expanded.push_back (Arg (type == '+' ? "~" : "!~", "op"));
|
||||||
|
@ -961,7 +961,7 @@ const A3 A3::expand (const A3& input) const
|
||||||
else if (arg->_category == "pattern")
|
else if (arg->_category == "pattern")
|
||||||
{
|
{
|
||||||
std::string value;
|
std::string value;
|
||||||
A3::extract_pattern (arg->_raw, value);
|
extract_pattern (arg->_raw, value);
|
||||||
|
|
||||||
expanded.push_back (Arg ("description", "dom"));
|
expanded.push_back (Arg ("description", "dom"));
|
||||||
expanded.push_back (Arg ("~", "op"));
|
expanded.push_back (Arg ("~", "op"));
|
||||||
|
@ -990,10 +990,10 @@ const A3 A3::sequence (const A3& input) const
|
||||||
for (arg = input.begin (); arg != input.end (); ++arg)
|
for (arg = input.begin (); arg != input.end (); ++arg)
|
||||||
{
|
{
|
||||||
if (arg->_category == "id")
|
if (arg->_category == "id")
|
||||||
A3::extract_id (arg->_raw, ids);
|
extract_id (arg->_raw, ids);
|
||||||
|
|
||||||
else if (arg->_category == "uuid")
|
else if (arg->_category == "uuid")
|
||||||
A3::extract_uuid (arg->_raw, uuids);
|
extract_uuid (arg->_raw, uuids);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is no sequence, we're done.
|
// If there is no sequence, we're done.
|
||||||
|
@ -1109,13 +1109,13 @@ const A3 A3::postfix (const A3& input) const
|
||||||
else
|
else
|
||||||
throw std::string ("Mismatched parentheses in expression");
|
throw std::string ("Mismatched parentheses in expression");
|
||||||
}
|
}
|
||||||
else if (A3::is_operator (arg->_raw, type, precedence, associativity))
|
else if (is_operator (arg->_raw, type, precedence, associativity))
|
||||||
{
|
{
|
||||||
char type2;
|
char type2;
|
||||||
int precedence2;
|
int precedence2;
|
||||||
char associativity2;
|
char associativity2;
|
||||||
while (op_stack.size () > 0 &&
|
while (op_stack.size () > 0 &&
|
||||||
A3::is_operator (op_stack.back ()._raw, type2, precedence2, associativity2) &&
|
is_operator (op_stack.back ()._raw, type2, precedence2, associativity2) &&
|
||||||
((associativity == 'l' && precedence <= precedence2) ||
|
((associativity == 'l' && precedence <= precedence2) ||
|
||||||
(associativity == 'r' && precedence < precedence2)))
|
(associativity == 'r' && precedence < precedence2)))
|
||||||
{
|
{
|
||||||
|
|
1734
src/Arguments.cpp
1734
src/Arguments.cpp
File diff suppressed because it is too large
Load diff
143
src/Arguments.h
143
src/Arguments.h
|
@ -1,143 +0,0 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// 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_ARGUMENTS
|
|
||||||
#define INCLUDED_ARGUMENTS
|
|
||||||
#define L10N // Localization complete.
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <File.h>
|
|
||||||
|
|
||||||
#define ARGUMENTS_SEQUENCE_MAX_RANGE 1000
|
|
||||||
|
|
||||||
class Triple
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Triple (
|
|
||||||
const std::string& one,
|
|
||||||
const std::string& two,
|
|
||||||
const std::string& three)
|
|
||||||
: _first (one)
|
|
||||||
, _second (two)
|
|
||||||
, _third (three)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Triple (const Triple& other)
|
|
||||||
{
|
|
||||||
_first = other._first;
|
|
||||||
_second = other._second;
|
|
||||||
_third = other._third;
|
|
||||||
}
|
|
||||||
|
|
||||||
Triple& operator= (const Triple& other)
|
|
||||||
{
|
|
||||||
if (this != &other)
|
|
||||||
{
|
|
||||||
_first = other._first;
|
|
||||||
_second = other._second;
|
|
||||||
_third = other._third;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator== (const Triple& other) const
|
|
||||||
{
|
|
||||||
return _first == other._first &&
|
|
||||||
_second == other._second &&
|
|
||||||
_third == other._third;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
std::string _first; // Represents token to be evaluated
|
|
||||||
std::string _second; // Represents progressive token type
|
|
||||||
std::string _third; // Represent original category
|
|
||||||
};
|
|
||||||
|
|
||||||
class Arguments : public std::vector <Triple>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Arguments ();
|
|
||||||
~Arguments ();
|
|
||||||
|
|
||||||
void capture (int, const char**);
|
|
||||||
void capture (const std::string&);
|
|
||||||
void capture_first (const std::string&);
|
|
||||||
void categorize ();
|
|
||||||
|
|
||||||
void append_stdin ();
|
|
||||||
void rc_override (std::string&, File&);
|
|
||||||
void get_data_location (std::string&);
|
|
||||||
void apply_overrides ();
|
|
||||||
void resolve_aliases ();
|
|
||||||
void inject_defaults ();
|
|
||||||
|
|
||||||
std::vector <std::string> list ();
|
|
||||||
static std::vector <std::string> operator_list ();
|
|
||||||
std::string combine ();
|
|
||||||
|
|
||||||
bool find_command (std::string&);
|
|
||||||
std::string find_limit ();
|
|
||||||
|
|
||||||
static bool is_multipart (const std::string&, std::vector <std::string>&);
|
|
||||||
static bool is_command (const std::vector <std::string>&, std::string&);
|
|
||||||
static bool is_attr (const std::string&);
|
|
||||||
static bool is_attmod (const std::string&);
|
|
||||||
static bool is_subst (const std::string&);
|
|
||||||
static bool is_pattern (const std::string&);
|
|
||||||
static bool is_id (const std::string&);
|
|
||||||
static bool is_uuid (const std::string&);
|
|
||||||
static bool is_tag (const std::string&);
|
|
||||||
static bool is_operator (const std::string&);
|
|
||||||
static bool is_operator (const std::string&, char&, int&, char&);
|
|
||||||
static bool is_symbol_operator (const std::string&);
|
|
||||||
static bool is_attribute (const std::string&, std::string&);
|
|
||||||
static bool is_modifier (const std::string&);
|
|
||||||
static bool is_expression (const std::string&);
|
|
||||||
|
|
||||||
static bool extract_attr (const std::string&, std::string&, std::string&);
|
|
||||||
static bool extract_attmod (const std::string&, std::string&, std::string&, std::string&, std::string&);
|
|
||||||
static bool extract_subst (const std::string&, std::string&, std::string&, bool&);
|
|
||||||
static bool extract_pattern (const std::string&, std::string&);
|
|
||||||
static bool extract_id (const std::string&, std::vector <int>&);
|
|
||||||
static bool extract_uuid (const std::string&, std::vector <std::string>&);
|
|
||||||
static bool extract_tag (const std::string&, char&, std::string&);
|
|
||||||
static bool extract_operator (const std::string&, std::string&);
|
|
||||||
|
|
||||||
Arguments extract_read_only_filter ();
|
|
||||||
Arguments extract_write_filter ();
|
|
||||||
Arguments extract_modifications (bool include_seq = false);
|
|
||||||
Arguments extract_simple_words ();
|
|
||||||
|
|
||||||
static bool valid_modifier (const std::string&);
|
|
||||||
|
|
||||||
void dump (const std::string&);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
|
@ -7,7 +7,6 @@ include_directories (${CMAKE_SOURCE_DIR}
|
||||||
|
|
||||||
set (task_SRCS A3.cpp A3.h
|
set (task_SRCS A3.cpp A3.h
|
||||||
API.cpp API.h
|
API.cpp API.h
|
||||||
Arguments.cpp Arguments.h
|
|
||||||
Att.cpp Att.h
|
Att.cpp Att.h
|
||||||
Color.cpp Color.h
|
Color.cpp Color.h
|
||||||
Config.cpp Config.h
|
Config.cpp Config.h
|
||||||
|
|
|
@ -72,21 +72,18 @@ int Context::initialize (int argc, const char** argv)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// char** argv --> std::vector <std::string> Context::args.
|
// char** argv --> std::vector <std::string> Context::a3.
|
||||||
args.capture (argc, argv);
|
|
||||||
a3.capture (argc, argv);
|
a3.capture (argc, argv);
|
||||||
|
|
||||||
// echo one two -- three | task zero --> task zero one two
|
// echo one two -- three | task zero --> task zero one two
|
||||||
// 'three' is left in the input buffer.
|
// 'three' is left in the input buffer.
|
||||||
args.append_stdin ();
|
|
||||||
a3.append_stdin ();
|
a3.append_stdin ();
|
||||||
|
|
||||||
// Assume default .taskrc and .task locations.
|
// Assume default .taskrc and .task locations.
|
||||||
assumeLocations ();
|
assumeLocations ();
|
||||||
|
|
||||||
// Process 'rc:<file>' command line override, and remove the argument from the
|
// Process 'rc:<file>' command line override, and remove the argument from the
|
||||||
// Context::args.
|
// Context::a3.
|
||||||
args.rc_override (home_dir, rc_file);
|
|
||||||
a3.categorize ();
|
a3.categorize ();
|
||||||
a3.rc_override (home_dir, rc_file);
|
a3.rc_override (home_dir, rc_file);
|
||||||
|
|
||||||
|
@ -107,7 +104,6 @@ int Context::initialize (int argc, const char** argv)
|
||||||
|
|
||||||
// Handle Aliases.
|
// Handle Aliases.
|
||||||
loadAliases ();
|
loadAliases ();
|
||||||
args.resolve_aliases ();
|
|
||||||
a3.resolve_aliases ();
|
a3.resolve_aliases ();
|
||||||
|
|
||||||
// Apply rc overrides to Context::config, capturing raw args for later use.
|
// Apply rc overrides to Context::config, capturing raw args for later use.
|
||||||
|
@ -124,11 +120,9 @@ int Context::initialize (int argc, const char** argv)
|
||||||
Column::factory (columns);
|
Column::factory (columns);
|
||||||
|
|
||||||
// Categorize all arguments one more time. THIS IS NECESSARY.
|
// Categorize all arguments one more time. THIS IS NECESSARY.
|
||||||
args.categorize ();
|
|
||||||
a3.categorize ();
|
a3.categorize ();
|
||||||
|
|
||||||
// Handle default command and assumed 'info' command.
|
// Handle default command and assumed 'info' command.
|
||||||
args.inject_defaults ();
|
|
||||||
a3.inject_defaults ();
|
a3.inject_defaults ();
|
||||||
a3.dump ("Context::initialize"); // TODO Remove.
|
a3.dump ("Context::initialize"); // TODO Remove.
|
||||||
|
|
||||||
|
@ -526,7 +520,7 @@ void Context::clear ()
|
||||||
{
|
{
|
||||||
tdb.clear (); // TODO Obsolete
|
tdb.clear (); // TODO Obsolete
|
||||||
// tdb2.clear ();
|
// tdb2.clear ();
|
||||||
args.clear ();
|
a3.clear ();
|
||||||
|
|
||||||
clearMessages ();
|
clearMessages ();
|
||||||
}
|
}
|
||||||
|
@ -539,7 +533,7 @@ void Context::updateXtermTitle ()
|
||||||
if (config.getBoolean ("xterm.title"))
|
if (config.getBoolean ("xterm.title"))
|
||||||
{
|
{
|
||||||
std::string command;
|
std::string command;
|
||||||
args.find_command (command);
|
a3.find_command (command);
|
||||||
|
|
||||||
std::string title;
|
std::string title;
|
||||||
join (title, " ", a3.list ());
|
join (title, " ", a3.list ());
|
||||||
|
|
|
@ -39,7 +39,6 @@
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
#include <Arguments.h>
|
|
||||||
#include <A3.h>
|
#include <A3.h>
|
||||||
|
|
||||||
class Context
|
class Context
|
||||||
|
@ -82,7 +81,6 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string program;
|
std::string program;
|
||||||
Arguments args;
|
|
||||||
A3 a3;
|
A3 a3;
|
||||||
std::string home_dir;
|
std::string home_dir;
|
||||||
File rc_file;
|
File rc_file;
|
||||||
|
|
|
@ -115,11 +115,11 @@ const std::string DOM::get (const std::string& name)
|
||||||
name.substr (0, 8) == "context.")
|
name.substr (0, 8) == "context.")
|
||||||
{
|
{
|
||||||
if (name == "context.program")
|
if (name == "context.program")
|
||||||
return /*_cache[name] =*/ context.args[0]._first;
|
return /*_cache[name] =*/ context.a3[0]._raw;
|
||||||
|
|
||||||
else if (name == "context.args")
|
else if (name == "context.args")
|
||||||
{
|
{
|
||||||
return /*_cache[name] =*/ context.args.combine ();
|
return /*_cache[name] =*/ context.a3.combine ();
|
||||||
}
|
}
|
||||||
else if (name == "context.width")
|
else if (name == "context.width")
|
||||||
{
|
{
|
||||||
|
@ -238,7 +238,7 @@ const std::string DOM::get (const std::string& name, const Task& task)
|
||||||
return /*_cache[name] =*/ copy_name;
|
return /*_cache[name] =*/ copy_name;
|
||||||
|
|
||||||
// <attr>
|
// <attr>
|
||||||
else if (Arguments::is_attribute (name, canonical))
|
else if (A3::is_attribute (name, canonical))
|
||||||
return task.get (canonical);
|
return task.get (canonical);
|
||||||
|
|
||||||
// <id>.<name>
|
// <id>.<name>
|
||||||
|
|
|
@ -56,8 +56,7 @@ int CmdAdd::execute (std::string& output)
|
||||||
task.set ("uuid", uuid ());
|
task.set ("uuid", uuid ());
|
||||||
|
|
||||||
// Apply the command line modifications to the new task.
|
// Apply the command line modifications to the new task.
|
||||||
Arguments modifications = context.args.extract_modifications (true);
|
modify_task_description_replace (task, context.a3.extract_modifications ());
|
||||||
modify_task_description_replace (task, modifications);
|
|
||||||
apply_defaults (task);
|
apply_defaults (task);
|
||||||
|
|
||||||
// Only valid tasks can be added.
|
// 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.
|
// Apply the command line modifications to the completed task.
|
||||||
Arguments modifications = context.args.extract_modifications ();
|
A3 modifications = context.a3.extract_modifications ();
|
||||||
if (!modifications.size ())
|
if (!modifications.size ())
|
||||||
throw std::string (STRING_CMD_XPEND_NEED_TEXT);
|
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.
|
// Apply the command line modifications to the started task.
|
||||||
Arguments modifications = context.args.extract_modifications ();
|
A3 modifications = context.a3.extract_modifications ();
|
||||||
if (!modifications.size ())
|
if (!modifications.size ())
|
||||||
throw std::string (STRING_CMD_XPEND_NEED_TEXT);
|
throw std::string (STRING_CMD_XPEND_NEED_TEXT);
|
||||||
|
|
||||||
|
|
|
@ -998,10 +998,10 @@ int CmdBurndownMonthly::execute (std::string& output)
|
||||||
Chart chart ('M');
|
Chart chart ('M');
|
||||||
|
|
||||||
// Use any filter as a title.
|
// Use any filter as a title.
|
||||||
if (context.args.size () > 2)
|
if (context.a3.size () > 2)
|
||||||
{
|
{
|
||||||
std::string combined = "("
|
std::string combined = "("
|
||||||
+ context.args.extract_read_only_filter ().combine ()
|
+ context.a3.extract_filter ().combine ()
|
||||||
+ ")";
|
+ ")";
|
||||||
chart.description (combined);
|
chart.description (combined);
|
||||||
}
|
}
|
||||||
|
@ -1042,10 +1042,10 @@ int CmdBurndownWeekly::execute (std::string& output)
|
||||||
Chart chart ('W');
|
Chart chart ('W');
|
||||||
|
|
||||||
// Use any filter as a title.
|
// Use any filter as a title.
|
||||||
if (context.args.size () > 2)
|
if (context.a3.size () > 2)
|
||||||
{
|
{
|
||||||
std::string combined = "("
|
std::string combined = "("
|
||||||
+ context.args.extract_read_only_filter ().combine ()
|
+ context.a3.extract_filter ().combine ()
|
||||||
+ ")";
|
+ ")";
|
||||||
chart.description (combined);
|
chart.description (combined);
|
||||||
}
|
}
|
||||||
|
@ -1086,10 +1086,10 @@ int CmdBurndownDaily::execute (std::string& output)
|
||||||
Chart chart ('D');
|
Chart chart ('D');
|
||||||
|
|
||||||
// Use any filter as a title.
|
// Use any filter as a title.
|
||||||
if (context.args.size () > 2)
|
if (context.a3.size () > 2)
|
||||||
{
|
{
|
||||||
std::string combined = "("
|
std::string combined = "("
|
||||||
+ context.args.extract_read_only_filter ().combine ()
|
+ context.a3.extract_filter ().combine ()
|
||||||
+ ")";
|
+ ")";
|
||||||
chart.description (combined);
|
chart.description (combined);
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,10 +86,7 @@ int CmdCustom::execute (std::string& output)
|
||||||
split (filterArgs, reportFilter, ' ');
|
split (filterArgs, reportFilter, ' ');
|
||||||
std::vector <std::string>::iterator arg;
|
std::vector <std::string>::iterator arg;
|
||||||
for (arg = filterArgs.begin (); arg != filterArgs.end (); ++ arg)
|
for (arg = filterArgs.begin (); arg != filterArgs.end (); ++ arg)
|
||||||
{
|
|
||||||
context.args.capture_first (*arg);
|
|
||||||
context.a3.capture_first (*arg);
|
context.a3.capture_first (*arg);
|
||||||
}
|
|
||||||
|
|
||||||
context.a3.categorize ();
|
context.a3.categorize ();
|
||||||
context.a3.dump ("CmdCustom::execute");
|
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.
|
// If the custom report has a defined limit, then allow a numeric override.
|
||||||
// This is an integer specified as a filter (limit:10).
|
// 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 != "")
|
||||||
{
|
{
|
||||||
if (limit == "page")
|
if (limit == "page")
|
||||||
|
|
|
@ -70,7 +70,7 @@ int CmdDelete::execute (std::string& output)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply the command line modifications to the new task.
|
// 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;
|
std::vector <Task>::iterator task;
|
||||||
for (task = filtered.begin (); task != filtered.end (); ++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.
|
// Apply the command line modifications to the completed task.
|
||||||
Arguments modifications = context.args.extract_modifications ();
|
A3 modifications = context.a3.extract_modifications ();
|
||||||
|
|
||||||
Permission permission;
|
Permission permission;
|
||||||
if (filtered.size () > (size_t) context.config.getInteger ("bulk"))
|
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.
|
// 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;
|
std::vector <Task>::iterator task;
|
||||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||||
|
|
|
@ -48,12 +48,12 @@ CmdExec::CmdExec ()
|
||||||
int CmdExec::execute (std::string& output)
|
int CmdExec::execute (std::string& output)
|
||||||
{
|
{
|
||||||
std::string command_line;
|
std::string command_line;
|
||||||
std::vector <Triple>::iterator arg;
|
std::vector <Arg>::iterator arg;
|
||||||
for (arg = context.args.begin (); arg != context.args.end (); ++arg)
|
for (arg = context.a3.begin (); arg != context.a3.end (); ++arg)
|
||||||
{
|
{
|
||||||
if (arg != context.args.begin () &&
|
if (arg != context.a3.begin () &&
|
||||||
arg->_first != "execute")
|
arg->_raw != "execute")
|
||||||
command_line += arg->_first;
|
command_line += arg->_raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
return system (command_line.c_str ());
|
return system (command_line.c_str ());
|
||||||
|
|
|
@ -56,7 +56,7 @@ int CmdLog::execute (std::string& output)
|
||||||
task.set ("uuid", uuid ());
|
task.set ("uuid", uuid ());
|
||||||
|
|
||||||
// Apply the command line modifications to the new task.
|
// 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);
|
modify_task_description_replace (task, modifications);
|
||||||
apply_defaults (task);
|
apply_defaults (task);
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ int CmdModify::execute (std::string& output)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply the command line modifications to the new task.
|
// Apply the command line modifications to the new task.
|
||||||
Arguments modifications = context.args.extract_modifications ();
|
A3 modifications = context.a3.extract_modifications ();
|
||||||
|
|
||||||
Permission permission;
|
Permission permission;
|
||||||
if (filtered.size () > (size_t) context.config.getInteger ("bulk"))
|
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.
|
// Apply the command line modifications to the started task.
|
||||||
Arguments modifications = context.args.extract_modifications ();
|
A3 modifications = context.a3.extract_modifications ();
|
||||||
if (!modifications.size ())
|
if (!modifications.size ())
|
||||||
throw std::string (STRING_CMD_XPEND_NEED_TEXT);
|
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 '--'
|
// Obtain the arguments from the description. That way, things like '--'
|
||||||
// have already been handled.
|
// have already been handled.
|
||||||
if (context.args.size () > 2)
|
if (context.a3.size () > 2)
|
||||||
throw std::string (STRING_CMD_SHOW_ARGS);
|
throw std::string (STRING_CMD_SHOW_ARGS);
|
||||||
|
|
||||||
int width = context.getWidth ();
|
int width = context.getWidth ();
|
||||||
|
|
|
@ -69,7 +69,7 @@ int CmdStart::execute (std::string& output)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply the command line modifications to the started task.
|
// Apply the command line modifications to the started task.
|
||||||
Arguments modifications = context.args.extract_modifications ();
|
A3 modifications = context.a3.extract_modifications ();
|
||||||
|
|
||||||
Permission permission;
|
Permission permission;
|
||||||
if (filtered.size () > (size_t) context.config.getInteger ("bulk"))
|
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.
|
// Apply the command line modifications to the stopped task.
|
||||||
Arguments modifications = context.args.extract_modifications ();
|
A3 modifications = context.a3.extract_modifications ();
|
||||||
|
|
||||||
Permission permission;
|
Permission permission;
|
||||||
if (filtered.size () > (size_t) context.config.getInteger ("bulk"))
|
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 ();
|
A3 filt = context.a3.extract_filter ();
|
||||||
filt.dump ("extract_filter");
|
filt.dump ("extract_filter");
|
||||||
|
|
||||||
Arguments f;
|
if (filt.size ())
|
||||||
if (read_only ())
|
|
||||||
f = context.args.extract_read_only_filter ();
|
|
||||||
else
|
|
||||||
f = context.args.extract_write_filter ();
|
|
||||||
|
|
||||||
if (f.size ())
|
|
||||||
{
|
{
|
||||||
E9 e (filt);
|
E9 e (filt);
|
||||||
|
|
||||||
|
@ -299,13 +293,7 @@ void Command::filter (std::vector <Task>& output)
|
||||||
A3 filt = context.a3.extract_filter ();
|
A3 filt = context.a3.extract_filter ();
|
||||||
filt.dump ("extract_filter");
|
filt.dump ("extract_filter");
|
||||||
|
|
||||||
Arguments f;
|
if (filt.size ())
|
||||||
if (read_only ())
|
|
||||||
f = context.args.extract_read_only_filter ();
|
|
||||||
else
|
|
||||||
f = context.args.extract_write_filter ();
|
|
||||||
|
|
||||||
if (f.size ())
|
|
||||||
{
|
{
|
||||||
const std::vector <Task>& pending = context.tdb2.pending.get_tasks ();
|
const std::vector <Task>& pending = context.tdb2.pending.get_tasks ();
|
||||||
E9 e (filt);
|
E9 e (filt);
|
||||||
|
@ -316,7 +304,7 @@ void Command::filter (std::vector <Task>& output)
|
||||||
if (e.evalFilter (*task))
|
if (e.evalFilter (*task))
|
||||||
output.push_back (*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
|
const std::vector <Task>& completed = context.tdb2.completed.get_tasks (); // TODO Optional
|
||||||
for (task = completed.begin (); task != completed.end (); ++task)
|
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
|
// If the filter contains the restriction "status:pending", as the first filter
|
||||||
// term, then completed.data does not need to be loaded.
|
// 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)
|
if (filter.size () >= 3)
|
||||||
{
|
{
|
||||||
std::cout << "# filter[0] " << filter[0]._first << "\n"
|
std::cout << "# filter[0] " << filter[0]._raw << "\n"
|
||||||
<< "# filter[1] " << filter[1]._first << "\n"
|
<< "# filter[1] " << filter[1]._raw << "\n"
|
||||||
<< "# filter[2] " << filter[2]._first << "\n";
|
<< "# filter[2] " << filter[2]._raw << "\n";
|
||||||
}
|
}
|
||||||
/**/
|
/**/
|
||||||
|
|
||||||
// Postfix: <status> <"pending"> <=>
|
// Postfix: <status> <"pending"> <=>
|
||||||
// 0 1 2
|
// 0 1 2
|
||||||
if (filter.size () >= 3 &&
|
if (filter.size () >= 3 &&
|
||||||
filter[0]._first == "status" &&
|
filter[0]._raw == "status" &&
|
||||||
filter[1]._first.find ("pending") != std::string::npos &&
|
filter[1]._raw.find ("pending") != std::string::npos &&
|
||||||
filter[2]._first == "=")
|
filter[2]._raw == "=")
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -367,7 +355,7 @@ bool Command::filter_shortcut (const Arguments& filter)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Apply the modifications in arguments to the task.
|
// 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;
|
std::string description;
|
||||||
modify_task (task, arguments, 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;
|
std::string description;
|
||||||
modify_task (task, arguments, 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;
|
std::string description;
|
||||||
modify_task (task, arguments, 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;
|
std::string description;
|
||||||
modify_task (task, arguments, 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.
|
// Worker function that does all the updates, but never overwrites description.
|
||||||
void Command::modify_task (
|
void Command::modify_task (
|
||||||
Task& task,
|
Task& task,
|
||||||
Arguments& arguments,
|
const A3& arguments,
|
||||||
std::string& description)
|
std::string& description)
|
||||||
{
|
{
|
||||||
std::vector <Triple>::iterator arg;
|
std::vector <Arg>::const_iterator arg;
|
||||||
for (arg = arguments.begin (); arg != arguments.end (); ++arg)
|
for (arg = arguments.begin (); arg != arguments.end (); ++arg)
|
||||||
{
|
{
|
||||||
// Attributes are essentially name:value pairs, and correspond directly
|
// Attributes are essentially name:value pairs, and correspond directly
|
||||||
// to stored attributes.
|
// to stored attributes.
|
||||||
if (arg->_third == "attr")
|
if (arg->_category == "attr")
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string value;
|
std::string value;
|
||||||
Arguments::extract_attr (arg->_first, name, value);
|
A3::extract_attr (arg->_raw, name, value);
|
||||||
if (Arguments::is_attribute (name, name)) // Canonicalize
|
if (A3::is_attribute (name, name)) // Canonicalize
|
||||||
{
|
{
|
||||||
// All values must be eval'd first.
|
// All values must be eval'd first.
|
||||||
A3 fragment;
|
A3 fragment;
|
||||||
|
@ -462,11 +450,11 @@ void Command::modify_task (
|
||||||
// Tags need special handling because they are essentially a vector stored
|
// Tags need special handling because they are essentially a vector stored
|
||||||
// in a single string, therefore Task::{add,remove}Tag must be called as
|
// in a single string, therefore Task::{add,remove}Tag must be called as
|
||||||
// appropriate.
|
// appropriate.
|
||||||
else if (arg->_third == "tag")
|
else if (arg->_category == "tag")
|
||||||
{
|
{
|
||||||
char type;
|
char type;
|
||||||
std::string value;
|
std::string value;
|
||||||
Arguments::extract_tag (arg->_first, type, value);
|
A3::extract_tag (arg->_raw, type, value);
|
||||||
|
|
||||||
if (type == '+')
|
if (type == '+')
|
||||||
task.addTag (value);
|
task.addTag (value);
|
||||||
|
@ -475,29 +463,29 @@ void Command::modify_task (
|
||||||
}
|
}
|
||||||
|
|
||||||
// Words and operators are aggregated into a description.
|
// Words and operators are aggregated into a description.
|
||||||
else if (arg->_third == "word" ||
|
else if (arg->_category == "word" ||
|
||||||
arg->_third == "op")
|
arg->_category == "op")
|
||||||
{
|
{
|
||||||
if (description.length ())
|
if (description.length ())
|
||||||
description += " ";
|
description += " ";
|
||||||
|
|
||||||
description += arg->_first;
|
description += arg->_raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Substitutions.
|
// Substitutions.
|
||||||
else if (arg->_third == "subst")
|
else if (arg->_category == "subst")
|
||||||
{
|
{
|
||||||
std::string from;
|
std::string from;
|
||||||
std::string to;
|
std::string to;
|
||||||
bool global;
|
bool global;
|
||||||
Arguments::extract_subst (arg->_first, from, to, global);
|
A3::extract_subst (arg->_raw, from, to, global);
|
||||||
task.substitute (from, to, global);
|
task.substitute (from, to, global);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Any additional argument types are indicative of a failure in
|
// Any additional argument types are indicative of a failure in
|
||||||
// Arguments::extract_modifications.
|
// A3::extract_modifications.
|
||||||
else
|
else
|
||||||
throw format (STRING_CMD_MOD_UNEXPECTED, arg->_first);
|
throw format (STRING_CMD_MOD_UNEXPECTED, arg->_raw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <Task.h>
|
#include <Task.h>
|
||||||
#include <Arguments.h>
|
#include <A3.h>
|
||||||
|
|
||||||
class Command
|
class Command
|
||||||
{
|
{
|
||||||
|
@ -55,13 +55,13 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void filter (std::vector <Task>&, std::vector <Task>&);
|
void filter (std::vector <Task>&, std::vector <Task>&);
|
||||||
void filter (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_replace (Task&, const A3&);
|
||||||
void modify_task_description_prepend (Task&, Arguments&);
|
void modify_task_description_prepend (Task&, const A3&);
|
||||||
void modify_task_description_append (Task&, Arguments&);
|
void modify_task_description_append (Task&, const A3&);
|
||||||
void modify_task_annotate (Task&, Arguments&);
|
void modify_task_annotate (Task&, const A3&);
|
||||||
void modify_task (Task&, Arguments&, std::string&);
|
void modify_task (Task&, const A3&, std::string&);
|
||||||
void apply_defaults (Task&);
|
void apply_defaults (Task&);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue