From 07954626c6925f22e4d59b6d68f0947d4e54b8b9 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Thu, 11 Feb 2016 18:22:05 +0100 Subject: Support format strings when dumping imported items In commit 3eae7ce (Add --list-imported command line option, 2016-01-12), we added an option to print the hashes of imported items to stdout. Extend this command line option such that it dumps the items using the specified formatting strings. With the new behavior it is, for example, easier to check items for import errors. Also, rename the option from --list-imported to --dump-imported (it is not part of any official release yet so we do not need to care about backwards compatibility). Signed-off-by: Lukas Fleischer --- src/args.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'src/args.c') diff --git a/src/args.c b/src/args.c index 4743067..3834f4a 100644 --- a/src/args.c +++ b/src/args.c @@ -70,7 +70,7 @@ enum { OPT_FMT_EV, OPT_FMT_REV, OPT_FMT_TODO, - OPT_LIST_IMPORTED, + OPT_DUMP_IMPORTED, OPT_EXPORT_UID, OPT_READ_ONLY, OPT_STATUS, @@ -402,7 +402,7 @@ int parse_args(int argc, char **argv) const char *fmt_todo = NULL; /* Import and export parameters */ int xfmt = IO_EXPORT_ICAL; - int list_imported = 0, export_uid = 0; + int dump_imported = 0, export_uid = 0; /* Data file locations */ const char *cfile = NULL, *datadir = NULL, *ifile = NULL; @@ -459,7 +459,7 @@ int parse_args(int argc, char **argv) {"format-recur-event", required_argument, NULL, OPT_FMT_REV}, {"format-todo", required_argument, NULL, OPT_FMT_TODO}, {"export-uid", no_argument, NULL, OPT_EXPORT_UID}, - {"list-imported", no_argument, NULL, OPT_LIST_IMPORTED}, + {"dump-imported", no_argument, NULL, OPT_DUMP_IMPORTED}, {"read-only", no_argument, NULL, OPT_READ_ONLY}, {"status", no_argument, NULL, OPT_STATUS}, {"daemon", no_argument, NULL, OPT_DAEMON}, @@ -669,8 +669,8 @@ int parse_args(int argc, char **argv) case OPT_FMT_TODO: fmt_todo = optarg; break; - case OPT_LIST_IMPORTED: - list_imported = 1; + case OPT_DUMP_IMPORTED: + dump_imported = 1; break; case OPT_EXPORT_UID: export_uid = 1; @@ -776,7 +776,24 @@ int parse_args(int argc, char **argv) /* Get default pager in case we need to show a log file. */ vars_init(); io_load_data(NULL); - io_import_data(IO_IMPORT_ICAL, ifile, list_imported); + if (dump_imported) { + /* + * Use default values for non-specified format strings. + */ + fmt_apt = fmt_apt ? fmt_apt : "%(raw)"; + fmt_rapt = fmt_rapt ? fmt_rapt : "%(raw)"; + fmt_ev = fmt_ev ? fmt_ev : "%(raw)"; + fmt_rev = fmt_rev ? fmt_rev : "%(raw)"; + fmt_todo = fmt_todo ? fmt_todo : "%(raw)"; + } else { + /* + * Do not dump items, unset format strings explicitly. + */ + fmt_apt = fmt_rapt = fmt_ev = fmt_rev = NULL; + fmt_todo = NULL; + } + io_import_data(IO_IMPORT_ICAL, ifile, fmt_ev, fmt_rev, fmt_apt, + fmt_rapt, fmt_todo); io_save_apts(path_apts); io_save_todo(path_todo); } else if (export) { -- cgit v1.2.3-54-g00ecf