From 7e0cfbbf7d9aae3873ebf753b61bee4a90a62499 Mon Sep 17 00:00:00 2001 From: Sebastian Oeste Date: Tue, 3 Apr 2018 21:10:42 +0200 Subject: [PATCH] [TS-30] re-enable limit as optional last argument * With this commit the limit argument to the review command is re-enabled. If it is pass with an filter argument it needs to be the last argument. Otherwise it might be hard to distinguish between limit and filter. * An additional is_number function is introduced to check if the last argument is numeric and can be treated as a limit. --- src/review.cpp | 53 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/src/review.cpp b/src/review.cpp index d6e1931..4288637 100644 --- a/src/review.cpp +++ b/src/review.cpp @@ -300,28 +300,41 @@ static void configureReport() } } +//////////////////////////////////////////////////////////////////////////////// +static bool is_number (const std::string& s) +{ + return !s.empty () && std::find_if(s.begin (), + s.end (), [] (char c) { return !std::isdigit (c); }) == s.end (); +} + //////////////////////////////////////////////////////////////////////////////// int cmdReview (const std::vector & args, bool autoClear) { // Is there a specified limit? - //unsigned int limit = 0; - unsigned int limit = std::numeric_limits::max(); - int status = 0; + unsigned int limit = std::numeric_limits::max (); bool with_filter = false; std::string input; std::string output; std::vector filter; // here we store our filter arguments - //if (args.size () == 2) - //limit = strtol (args[1].c_str (), NULL, 10); + if (args.size () > 1) { + auto begin = args.begin (); + auto end = args.end (); + if (is_number (args.back ())) // if last argument is numeric, treat it as limit. + { + limit = strtol (args.back ().c_str (), NULL, 10); + std::advance(end, -1); + } + std::advance (begin, 1); + if (begin != end) + { with_filter = true; - auto begin = args.begin(); - std::advance(begin, 1); - std::copy(begin, args.end(), std::back_inserter(filter)); + std::copy (begin, end, std::back_inserter (filter)); //TODO: maybe also add "status:pending" ? - filter.push_back("uuids"); + filter.emplace_back ("uuids"); + } } configureReport (); @@ -329,9 +342,7 @@ int cmdReview (const std::vector & args, bool autoClear) if (with_filter) { // Obtain list of UUIDs to review, when a filter is given - status = execute ("task", - filter, - input, output); + execute ("task", filter, input, output); // Review the set of UUIDs. auto uuids = split (Lexer::trimRight (output, "\n"), ' '); reviewLoop (uuids, limit, autoClear); @@ -339,15 +350,15 @@ int cmdReview (const std::vector & args, bool autoClear) else { // Obtain a list of UUIDs to review. - status = execute ("task", - { - "rc.color=off", - "rc.detection=off", - "rc._forcecolor=off", - "rc.verbose=nothing", - "_reviewed" - }, - input, output); + execute ("task", + { + "rc.color=off", + "rc.detection=off", + "rc._forcecolor=off", + "rc.verbose=nothing", + "_reviewed" + }, + input, output); // Review the set of UUIDs. auto uuids = split (Lexer::trimRight (output, "\n"), '\n');