Enhancement - Supports '--' on the command line

- Using '--' on the command line separates the left hand side, where
  task is free to interpret arguments in the usual way, and the right
  hand side, which is then assumed to be part of the task description,
  and is not interpreted by task.
This commit is contained in:
Paul Beckingham 2009-05-24 22:32:36 -04:00
parent 020604334e
commit c223d38872
7 changed files with 128 additions and 70 deletions

View file

@ -1,6 +1,12 @@
Principal Author:
Paul Beckingham
Package Maintainer & Contributing Author:
Federico Hernandez
Designer:
David J Patrick
Contributing Authors:
Damian Glenny
Andy Lester
@ -10,9 +16,7 @@ Contributing Authors:
Benjamin Tegarden
Chris Pride
Richard Querin
Federico Hernandez
T. Charles Yun
David J Patrick
P.C. Shyamshankar
Johan Friis
Steven de Brouwer

View file

@ -8,6 +8,8 @@
+ Fixed documentation errors (thanks to Thomas@BIC).
+ The 'weekstart' configuration variable now controls the 'calendar'
command (thanks to Federico Hernandez).
+ Supports '--' argument to indicate that all subsequence arguments are
part of the description, despite what they otherwise might mean.
------ old releases ------------------------------

View file

@ -485,6 +485,18 @@ on_white on_bright_white</code></pre>
Note also that this capability does depend on whether your terminal
program can display these colors.
</p>
<strong>% task add project:Home -- pri:H +tag /from/to/</strong>
<p>
The -- argument can be used to tell task to stop interpreting
the command line arguments. In the example above, a new task
is added for the project 'Home', then the -- argument appears,
and therefore all remaining arguments are part of the
description. In this case, the description is "pri:H +tag
/from/to/". This is one way to override task's interpretation
of the command line. The other way is to put the entire
description in quotes.
</p>
</div>
<br />

View file

@ -175,6 +175,24 @@
</p>
<hr>
<p>
<b>
Q: How do I use '+word' in a task description, and prevent it
from being interpreted as a tag?
</b>
<br />
A: There are several ways to do this. The simplest is to use
the '--' argument in the command line, and task will assume
that everything afterwards is part of the description. For
example:
<pre><code>% task add -- +tag</code></pre>
Allows the task description to be "+tag". If you use the
command:
<pre><code>% task &lt;id&gt; edit</code></pre>
Then you are free to put (almost) anything in the description
field without task interpreting it.
</p>
<hr>
<!--
<p>
<b>

View file

@ -138,6 +138,8 @@
<li>Fixed documentation errors (thanks to Thomas@BIC).
<li>The 'weekstart' configuration variable now controls the 'calendar'
command (thanks to Federico Hernandez).
<li>Supports '--' argument to indicate that all subsequence arguments are
part of the description, despite what they otherwise might mean.
</ul>
<p>

View file

@ -478,6 +478,7 @@ void parse (
{
command = "";
bool terminated = false;
bool foundSequence = false;
bool foundSomethingAfterSequence = false;
@ -489,6 +490,8 @@ void parse (
// Ignore any argument that is "rc:...", because that is the command line
// specified rc file.
if (arg.substr (0, 3) != "rc:")
{
if (!terminated)
{
size_t colon; // Pointer to colon in argument.
std::string from;
@ -496,8 +499,12 @@ void parse (
bool global;
std::vector <int> sequence;
// The '--' argument shuts off all parsing - everything is an argument.
if (arg == "--")
terminated = true;
// An id is the first argument found that contains all digits.
if (lowerCase (command) != "add" && // "add" doesn't require an ID
else if (lowerCase (command) != "add" && // "add" doesn't require an ID
validSequence (arg, sequence) &&
! foundSomethingAfterSequence)
{
@ -581,6 +588,17 @@ void parse (
descCandidate += arg;
}
}
// terminated, therefore everything subsequently is a description.
else
{
if (foundSequence)
foundSomethingAfterSequence = true;
if (descCandidate.length ())
descCandidate += " ";
descCandidate += arg;
}
}
}
if (validDescription (descCandidate))

View file

@ -272,6 +272,8 @@ static std::string longUsage (Config& conf)
<< " task add \"quoted ' quote\"" << "\n"
<< " task add escaped \\' quote" << "\n"
<< "\n"
<< "The argument -- tells task to treat all other args as description." << "\n"
<< "\n"
<< "Many characters have special meaning to the shell, including:" << "\n"
<< " $ ! ' \" ( ) ; \\ ` * ? { } [ ] < > | & % # ~" << "\n"
<< std::endl;