From b9f23e134a905b13aaa86935929a510ff75f75ef Mon Sep 17 00:00:00 2001
From: Lars Henriksen <LarsHenriksen@get2net.dk>
Date: Thu, 6 Dec 2018 10:35:26 +0100
Subject: Purge option glorified

The invert filter option is automatically set for -P (and cannot be used
on the command line). The intention is that the grep option (-G) is used
to find the items that should be removed. To remove them, the same
command is run with -P instead of -G.

In general, purge will remove matching items (silently).

Backward compatibility for option -F (no invert filter).

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
---
 src/args.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

(limited to 'src')

diff --git a/src/args.c b/src/args.c
index d2e4860..9986886 100644
--- a/src/args.c
+++ b/src/args.c
@@ -401,7 +401,7 @@ cleanup:
 int parse_args(int argc, char **argv)
 {
 	/* Command-line flags - NOTE that read_only is global */
-	int grep = 0, purge = 0, query = 0, next = 0;
+	int grep = 0, grep_filter = 0, purge = 0, query = 0, next = 0;
 	int status = 0, gc = 0, import = 0, export = 0, daemon = 0;
 	/* Command line invocation */
 	int filter_opt = 0, format_opt = 0, query_range = 0, cmd_line = 0;
@@ -545,7 +545,7 @@ int parse_args(int argc, char **argv)
 		case 'D':
 			break;
 		case 'F':
-			purge = grep = 1;
+			grep_filter = grep = 1;
 			break;
 		case 'h':
 			help_arg();
@@ -567,6 +567,7 @@ int parse_args(int argc, char **argv)
 			next = 1;
 			break;
 		case 'P':
+			filter.invert = 1;
 			purge = grep = 1;
 			break;
 		case 'r':
@@ -865,7 +866,9 @@ int parse_args(int argc, char **argv)
 	    optind < argc ||
 	    (filter_opt && !(grep + query + export)) ||
 	    (format_opt && !(grep + query + dump_imported)) ||
-	    (query_range && !query)) {
+	    (query_range && !query) ||
+	    (purge && !filter.invert)
+	   ) {
 		ERROR_MSG(_("invalid argument combination"));
 		usage();
 		usage_try();
@@ -895,7 +898,7 @@ int parse_args(int argc, char **argv)
 		io_check_file(path_todo);
 		io_check_file(path_conf);
 		io_load_data(&filter, FORCE);
-		if (purge) {
+		if (purge || grep_filter) {
 			io_save_todo(path_todo);
 			io_save_apts(path_apts);
 		} else {
-- 
cgit v1.2.3-70-g09d2