diff --git a/src/Arguments.cpp b/src/Arguments.cpp index 3cf145f40..fda217384 100644 --- a/src/Arguments.cpp +++ b/src/Arguments.cpp @@ -257,6 +257,18 @@ bool Arguments::extract_command ( return false; } +//////////////////////////////////////////////////////////////////////////////// +// TODO +void Arguments::extract_filter () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +// TODO +void Arguments::extract_modifications () +{ +} + //////////////////////////////////////////////////////////////////////////////// // A sequence can be: // @@ -362,12 +374,6 @@ void Arguments::extract_sequence (std::vector & sequence) this->erase (this->begin () + kill[k]); } -//////////////////////////////////////////////////////////////////////////////// -// TODO -void Arguments::extract_nv () -{ -} - //////////////////////////////////////////////////////////////////////////////// // TODO void Arguments::extract_uuids (std::vector & uuids) @@ -378,19 +384,31 @@ void Arguments::extract_uuids (std::vector & uuids) //////////////////////////////////////////////////////////////////////////////// // TODO -void Arguments::extract_filter () +void Arguments::extract_attrs () { } //////////////////////////////////////////////////////////////////////////////// // TODO -void Arguments::extract_modifications () +void Arguments::extract_words () { } //////////////////////////////////////////////////////////////////////////////// // TODO -void Arguments::extract_text () +void Arguments::extract_tags () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +// TODO +void Arguments::extract_pattern () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +// TODO +void Arguments::extract_subst () { } diff --git a/src/Arguments.h b/src/Arguments.h index 92182b6ca..ffa10d3ce 100644 --- a/src/Arguments.h +++ b/src/Arguments.h @@ -49,12 +49,16 @@ public: std::string combine (); bool extract_command (const std::vector &, std::string&); - void extract_sequence (std::vector &); - void extract_nv (); - void extract_uuids (std::vector &); void extract_filter (); void extract_modifications (); - void extract_text (); + + void extract_sequence (std::vector &); + void extract_uuids (std::vector &); + void extract_attrs (); + void extract_words (); + void extract_tags (); + void extract_pattern (); + void extract_subst (); }; #endif diff --git a/src/Att.cpp b/src/Att.cpp index 80b59b8da..0875c71d3 100644 --- a/src/Att.cpp +++ b/src/Att.cpp @@ -349,12 +349,13 @@ bool Att::validNameValue ( // Some attributes are intended to be private, unless the command is read- // only, in which cased these are perfectly valid elements of a filter. +/* if (context.cmd.isWriteCommand () && !validModifiableName (name)) throw std::string ("\"") + name + "\" is not an attribute you may modify directly."; - +*/ else if (name == "priority") { if (value != "") @@ -371,7 +372,7 @@ bool Att::validNameValue ( else if (name == "description") { - if (context.cmd.isWriteCommand ()) +// if (context.cmd.isWriteCommand ()) { if (value == "") throw std::string ("The '") + name + "' attribute must not be blank."; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8b6892f23..fa827d52b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,7 +8,6 @@ include_directories (${CMAKE_SOURCE_DIR} set (task_SRCS API.cpp API.h Arguments.cpp Arguments.h Att.cpp Att.h - Cmd.cpp Cmd.h Color.cpp Color.h Config.cpp Config.h Context.cpp Context.h diff --git a/src/Cmd.cpp b/src/Cmd.cpp deleted file mode 100644 index ae47da8e2..000000000 --- a/src/Cmd.cpp +++ /dev/null @@ -1,197 +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 -// -//////////////////////////////////////////////////////////////////////////////// - -#include -#include -#include -#include -#include -#include -#include - -extern Context context; - -//////////////////////////////////////////////////////////////////////////////// -Cmd::Cmd () -: command ("") -{ -} - -//////////////////////////////////////////////////////////////////////////////// -Cmd::Cmd (const std::string& input) -{ - parse (input); -} - -//////////////////////////////////////////////////////////////////////////////// -Cmd::~Cmd () -{ -} - -//////////////////////////////////////////////////////////////////////////////// -// Determines whether the string represents a unique command name or custom -// report name. -// -// To be a valid command: -// 1. 'input' should autocomplete to one of 'commands'. -bool Cmd::valid (const std::string& input) -{ - load (); - - std::vector matches; - autoComplete (lowerCase (input), commands, matches); - if (matches.size () == 1) - return true; - - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -// Determines whether the string represents a valid custom report name. -// -// To be a valid custom command: -// 1. 'input' should autocomplete to one of 'commands'. -// 2. the result, canonicalized, should autocomplete to one of -// 'customreports'. -bool Cmd::validCustom (const std::string& input) -{ - load (); - - std::vector matches; - autoComplete (lowerCase (input), commands, matches); - if (matches.size () == 1) - { -/* - std::string canonical = context.canonicalize (matches[0]); - matches.clear (); - autoComplete (canonical, customReports, matches); - if (matches.size () == 1) -*/ - return true; - } - - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -// To be a valid custom command: -// 1. 'input' should autocomplete to one of 'commands'. -// 2. the result may then canonicalize to another command. -void Cmd::parse (const std::string& input) -{ - load (); - - std::vector matches; - autoComplete (input, commands, matches); - if (1 == matches.size ()) - /*command = context.canonicalize (matches[0])*/; - - else if (0 == matches.size ()) - command = ""; - - else - { - std::string error = "Ambiguous command '" + input + "' - could be either of "; // TODO i18n - - std::sort (matches.begin (), matches.end ()); - std::string combined; - join (combined, ", ", matches); - throw error + combined; - } -} - -//////////////////////////////////////////////////////////////////////////////// -void Cmd::load () -{ - if (commands.size () == 0) - { - // Now load the custom reports. - std::vector all; - context.config.all (all); - - std::vector ::iterator i; - for (i = all.begin (); i != all.end (); ++i) - { - if (i->substr (0, 7) == "report.") - { - std::string report = i->substr (7); - std::string::size_type columns = report.find (".columns"); - if (columns != std::string::npos) - { - report = report.substr (0, columns); - - // Make sure a custom report does not clash with a built-in - // command. - if (std::find (commands.begin (), commands.end (), report) != commands.end ()) - throw std::string ("Custom report '") + report + - "' conflicts with built-in task command."; - - // A custom report is also a command. - customReports.push_back (report); - commands.push_back (report); - } - } - } - - // Now load the aliases. - std::map ::iterator it; - for (it = context.aliases.begin (); it != context.aliases.end (); ++it) - commands.push_back (it->first); - } -} - -//////////////////////////////////////////////////////////////////////////////// -void Cmd::allCustomReports (std::vector & all) const -{ - all = customReports; -} - -//////////////////////////////////////////////////////////////////////////////// -void Cmd::allCommands (std::vector & all) const -{ - all.clear (); - std::vector ::const_iterator c; - for (c = commands.begin (); c != commands.end (); ++c) - if (c->substr (0, 1) != "_") - all.push_back (*c); -} - -//////////////////////////////////////////////////////////////////////////////// -// Commands that do not directly modify the data files. -bool Cmd::isReadOnlyCommand () -{ - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -// Commands that directly modify the data files. -bool Cmd::isWriteCommand () -{ - return false; -} - -//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Cmd.h b/src/Cmd.h deleted file mode 100644 index d4ea9e3c5..000000000 --- a/src/Cmd.h +++ /dev/null @@ -1,65 +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_CMD -#define INCLUDED_CMD -#define L10N // Localization complete. - -#include -#include - -class Cmd -{ -public: - Cmd (); // Default constructor - Cmd (const std::string&); // Default constructor - ~Cmd (); // Destructor - - Cmd (const Cmd&); - Cmd& operator= (const Cmd&); - - bool valid (const std::string&); - bool validCustom (const std::string&); - void parse (const std::string&); - void allCustomReports (std::vector &) const; - void allCommands (std::vector &) const; - - bool isReadOnlyCommand (); - bool isWriteCommand (); - -public: - std::string command; - -private: - void load (); - -private: - std::vector commands; - std::vector customReports; -}; - -#endif -//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Context.cpp b/src/Context.cpp index 89dd387ab..3b127705a 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -58,7 +58,6 @@ Context::Context () , commandLine ("") , file_override ("") , var_overrides ("") -, cmd () , dom () , determine_color_use (true) , use_color (true) @@ -110,13 +109,13 @@ void Context::initialize (int argc, const char** argv) // Create missing config file and data directory, if necessary. createDefaultConfig (); - // Apply rc overrides to Context::config, capturing raw args for later use. - args.apply_overrides (var_overrides); - // Handle Aliases. loadAliases (); args.resolve_aliases (); + // Apply rc overrides to Context::config, capturing raw args for later use. + args.apply_overrides (var_overrides); + // Combine command line into one string. commandLine = args.combine (); @@ -155,10 +154,7 @@ int Context::run () std::string output; try { - parse (); // Parse command line. TODO Obsolete - rc = dispatch2 (output); // Dispatch to new command handlers. - if (rc) - rc = dispatch (output); // Dispatch to old command handlers. + rc = dispatch (output); } catch (const std::string& error) @@ -207,9 +203,9 @@ int Context::run () //////////////////////////////////////////////////////////////////////////////// // Locate and dispatch to the command whose keyword matches via autoComplete // with the earliest argument. -int Context::dispatch2 (std::string &out) +int Context::dispatch (std::string &out) { - Timer t ("Context::dispatch2"); + Timer t ("Context::dispatch"); updateXtermTitle (); @@ -235,34 +231,7 @@ int Context::dispatch2 (std::string &out) // TODO Need to invoke 'information' when a sequence/filter is present, but // no command is specified. - // TODO When ::dispatch is eliminated, show usage on unrecognized command. -// commands["help"]->execute (commandLine, out); - - return 1; -} - -//////////////////////////////////////////////////////////////////////////////// -int Context::dispatch (std::string &out) -{ - int rc = 0; - - Timer t ("Context::dispatch"); - - // TODO Chain-of-command pattern dispatch. - // ... - - // Commands that display IDs and therefore need TDB::gc first. - // ... - - rc = commands["help"]->execute (commandLine, out); - - // Only update the shadow file if such an update was not suppressed (shadow), - if ((cmd.isWriteCommand () || - (cmd.command == "" && sequence.size ())) && - !inShadow) - shadow (); - - return rc; + return commands["help"]->execute (commandLine, out); } //////////////////////////////////////////////////////////////////////////////// @@ -359,7 +328,7 @@ void Context::shadow () config.set ("detection", "off"); config.set ("color", "off"); - parse (); +// parse (); std::string result; (void)dispatch (result); std::ofstream out (shadowFile.data.c_str ()); @@ -390,7 +359,7 @@ void Context::disallowModification () const tagAdditions.size () || tagRemovals.size ()) throw std::string ("The '") - + cmd.command +// + cmd.command + "' command does not allow further modification of a task."; } @@ -447,12 +416,15 @@ void Context::loadAliases () } //////////////////////////////////////////////////////////////////////////////// +/* void Context::parse () { parse (args, cmd, task, sequence, subst, filter); } +*/ //////////////////////////////////////////////////////////////////////////////// +/* void Context::parse ( std::vector & parseArgs, Cmd& parseCmd, @@ -697,6 +669,7 @@ void Context::parse ( } } } +*/ //////////////////////////////////////////////////////////////////////////////// void Context::decomposeSortField ( @@ -742,7 +715,7 @@ void Context::clear () args.clear (); file_override = ""; var_overrides = ""; - cmd.command = ""; // TODO Obsolete +// cmd.command = ""; // TODO Obsolete tagAdditions.clear (); tagRemovals.clear (); diff --git a/src/Context.h b/src/Context.h index 0e32ae55b..1369cc6c9 100644 --- a/src/Context.h +++ b/src/Context.h @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -56,7 +55,6 @@ public: void initialize (int, const char**); // all startup int run (); - int dispatch2 (std::string&); // command handler dispatch int dispatch (std::string&); // command handler dispatch void shadow (); // shadow file update @@ -71,8 +69,10 @@ public: void debug (const std::string&); // Debug message sink void clearMessages (); +/* void parse (); void parse (std::vector &, Cmd&, Task&, Sequence&, Subst&, Filter&); +*/ void clear (); void disallowModification () const; @@ -105,7 +105,6 @@ public: std::string commandLine; std::string file_override; std::string var_overrides; - Cmd cmd; // TODO Obsolete std::map aliases; std::vector tagAdditions; std::vector tagRemovals; diff --git a/src/commands/CmdCustom.cpp b/src/commands/CmdCustom.cpp index d3f7a753e..ea00dda02 100644 --- a/src/commands/CmdCustom.cpp +++ b/src/commands/CmdCustom.cpp @@ -87,6 +87,7 @@ int CmdCustom::execute (const std::string&, std::string& output) split (filterArgs, reportFilter, ' '); // context.applyOverrides (filterArgs, filteredArgs); +/* { Cmd cmd (_keyword); Task task; @@ -105,6 +106,7 @@ int CmdCustom::execute (const std::string&, std::string& output) for (att = filter.begin (); att != filter.end (); ++att) context.filter.push_back (*att); } +*/ // Get all the tasks. std::vector tasks; diff --git a/src/commands/CmdImport.cpp b/src/commands/CmdImport.cpp index f3a09ea14..83e5c99dd 100644 --- a/src/commands/CmdImport.cpp +++ b/src/commands/CmdImport.cpp @@ -693,15 +693,16 @@ std::string CmdImport::taskCmdLine (const std::vector & lines) try { +/* context.args.clear (); split (context.args, std::string ("add ") + line, ' '); context.task.clear (); context.cmd.command = ""; context.parse (); -// (void)handleAdd (unused); context.commands["add"]->execute (unused, unused); context.clearMessages (); +*/ } catch (...) @@ -801,10 +802,12 @@ std::string CmdImport::todoSh_2_0 (const std::vector & lines) } } +/* context.task.clear (); context.cmd.command = ""; context.parse (); decorateTask (context.task); +*/ // Override the Task::pending that decorateTask applies. if (!isPending) @@ -882,10 +885,12 @@ std::string CmdImport::text (const std::vector & lines) context.args.clear (); split (context.args, std::string ("add ") + line, ' '); +/* context.task.clear (); context.cmd.command = ""; context.parse (); decorateTask (context.task); +*/ context.tdb.add (context.task); context.clearMessages ();