Skip to content

Commit

Permalink
command args: trim leading/trailing whitespace
Browse files Browse the repository at this point in the history
When certain commands in tasksh (such as 'review N') contain whitespace,
such as:

    review '1     '

The whitespace would tokenise into the command arg vector, effectively
treating the whitespace as a literal component.

In the case of the 'review' command, this is undesirable.  Therefore,
strip out all leading/trailing whitespace from the command args vector.

Fixes GH issue GothenburgBitFactory#43
  • Loading branch information
ThomasAdam committed Jun 19, 2018
1 parent 68d8a9a commit 2928e12
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include <readline/history.h>
#endif

#define WHITESPACE_CHARS " \t\n\r\f\v"

// TODO These conflict with tw commands. This needs to be resolved.
// Perhaps an escape, such as '-- help' could invoke local help, or using
// a 'task' prefix could disambiguate.
Expand Down Expand Up @@ -113,7 +115,13 @@ static int commandLoop (bool autoClear)
}
else if (command != "")
{
auto args = split (command, ' ');
std::vector<std::string> args;
std::string n;
for (const auto& s : split (command, ' '))
{
if ((n = trim(s)) != "")
args.push_back(n);
}

// Dispatch command.
if (args[0] == "<EOF>") status = -1;
Expand Down

0 comments on commit 2928e12

Please sign in to comment.