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>
This commit is contained in:
Lars Henriksen 2018-12-06 10:35:26 +01:00 committed by Lukas Fleischer
parent 42abbf5346
commit b9f23e134a

View File

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