Argument Parsing

- On task modification, all attributes are canonicalized.
This commit is contained in:
Paul Beckingham
2011-07-09 09:51:19 -04:00
parent 2b135ed3c2
commit 1cb4d19c3c
2 changed files with 25 additions and 20 deletions

View File

@@ -299,31 +299,35 @@ void Command::modify_task (Task& task, Arguments& arguments)
std::string name; std::string name;
std::string value; std::string value;
Arguments::extract_attr (arg->_first, name, value); Arguments::extract_attr (arg->_first, name, value);
if (Arguments::is_attribute (name, name))
// TODO All 'value's must be eval'd first.
// Dependencies must be resolved to UUIDs.
if (name == "depends")
{ {
// Convert ID to UUID. // TODO All 'value's must be eval'd first.
std::vector <std::string> deps;
split (deps, value, ',');
// Apply or remove dendencies in turn. // Dependencies must be resolved to UUIDs.
std::vector <std::string>::iterator i; if (name == "depends")
for (i = deps.begin (); i != deps.end (); i++)
{ {
int id = strtol (i->c_str (), NULL, 10); // Convert ID to UUID.
if (id < 0) std::vector <std::string> deps;
task.removeDependency (-id); split (deps, value, ',');
else
task.addDependency (id);
}
}
// By default, just add it. // Apply or remove dendencies in turn.
std::vector <std::string>::iterator i;
for (i = deps.begin (); i != deps.end (); i++)
{
int id = strtol (i->c_str (), NULL, 10);
if (id < 0)
task.removeDependency (-id);
else
task.addDependency (id);
}
}
// By default, just add it.
else
task.set (name, value);
}
else else
task.set (name, value); throw format (STRING_CMD_ADD_BAD_ATTRIBUTE, name);
} }
// Tags need special handling because they are essentially a vector stored // Tags need special handling because they are essentially a vector stored

View File

@@ -173,6 +173,7 @@
#define STRING_CMD_URGENCY_RESULT "task {1} urgency {2}" #define STRING_CMD_URGENCY_RESULT "task {1} urgency {2}"
#define STRING_CMD_ADD_USAGE "Adds a new task." #define STRING_CMD_ADD_USAGE "Adds a new task."
#define STRING_CMD_ADD_FEEDBACK "Created task {1}." #define STRING_CMD_ADD_FEEDBACK "Created task {1}."
#define STRING_CMD_ADD_BAD_ATTRIBUTE "Unrecognized attribute '{1}'."
#define STRING_CMD_MOD_UNEXPECTED "Unexpected argument '{1}' found while modifying a task." #define STRING_CMD_MOD_UNEXPECTED "Unexpected argument '{1}' found while modifying a task."
#define STRING_CMD_LOG_USAGE "Adds a new task that is already completed." #define STRING_CMD_LOG_USAGE "Adds a new task that is already completed."
#define STRING_CMD_IDS_USAGE_RANGE "Shows only the IDs of matching tasks, in the form of a range." #define STRING_CMD_IDS_USAGE_RANGE "Shows only the IDs of matching tasks, in the form of a range."