From e21d59e346c5ac04c02fd0309b7085ff1a987f6c Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 29 Jan 2023 13:40:40 +0200 Subject: [PATCH] mu init: implement --reinit option Create new mu database from an existing one. --- man/mu-init.1.org | 7 +++++++ mu/mu-cmd.cc | 39 +++++++++++++++++++++++++++------------ mu/mu-options.cc | 8 +++++++- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/man/mu-init.1.org b/man/mu-init.1.org index 9bf9f76b..220d3769 100644 --- a/man/mu-init.1.org +++ b/man/mu-init.1.org @@ -34,6 +34,13 @@ mailing list messages. wrapped in */* (such as =/foo-.*@example\\.com/=). Depending on your shell, the argument may need to be quoted. +** --reinit + +reinitialize the database from an earlier version; that is, create a new +empty database witht the existing settings. This cannot be combined +with the other ~init~ options. + + #+include: "muhome.inc" :minlevel 2 #+include: "prefooter.inc" :minlevel 1 diff --git a/mu/mu-cmd.cc b/mu/mu-cmd.cc index 5042239a..3f8a7c9c 100644 --- a/mu/mu-cmd.cc +++ b/mu/mu-cmd.cc @@ -410,26 +410,41 @@ cmd_info(const Mu::Store& store, const Options& opts) static Result cmd_init(const Options& opts) { - /* not provided, nor could we find a good default */ - if (opts.init.maildir.empty()) - return Err(Error::Code::InvalidArgument, - "missing --maildir parameter and could " - "not determine default"); + auto store = std::invoke([&]()->Result { - Mu::Store::Config conf{}; - conf.max_message_size = opts.init.max_msg_size.value_or(0); - conf.batch_size = opts.init.batch_size.value_or(0); + /* + * reinit + */ + if (opts.init.reinit) + return Store::make(opts.runtime_path(RuntimePath::XapianDb), + Store::Options::ReInit|Store::Options::Writable); + /* + * full init + */ + + /* not provided, nor could we find a good default */ + if (opts.init.maildir.empty()) + return Err(Error::Code::InvalidArgument, + "missing --maildir parameter and could " + "not determine default"); + + Mu::Store::Config conf{}; + conf.max_message_size = opts.init.max_msg_size.value_or(0); + conf.batch_size = opts.init.batch_size.value_or(0); + + return Store::make_new(opts.runtime_path(RuntimePath::XapianDb), + opts.init.maildir, opts.init.my_addresses, conf); + }); - auto store = Store::make_new(opts.runtime_path(RuntimePath::XapianDb), - opts.init.maildir, opts.init.my_addresses, conf); if (!store) return Err(store.error()); if (!opts.quiet) { cmd_info(*store, opts); - std::cout << "\nstore created; use the 'index' command to fill/update it.\n"; + std::cout << "database " + << (opts.init.reinit ? "reinitialized" : "created") + << "; use the 'index' command to fill/update it.\n"; } - return Ok(); } diff --git a/mu/mu-options.cc b/mu/mu-options.cc index d116511a..99e8efe4 100644 --- a/mu/mu-options.cc +++ b/mu/mu-options.cc @@ -364,11 +364,17 @@ sub_init(CLI::App& sub, Options& opts) ->type_name(""); sub.add_option("--my-address", opts.init.my_addresses, "Personal e-mail addresses") - ->type_name(""); + ->type_name("
"); sub.add_option("--max-message-size", opts.init.max_msg_size, "Maximum allowed message size in bytes"); sub.add_option("--batch-size", opts.init.batch_size, "Maximum size of database transaction"); + sub.add_flag("--reinit", opts.init.reinit, + "Re-initialize database with current settings") + ->excludes("--maildir") + ->excludes("--my-address") + ->excludes("--max-message-size") + ->excludes("--batch-size"); } static void