diff options
| author | Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> | 2023-01-29 13:40:40 +0200 |
|---|---|---|
| committer | Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> | 2023-01-29 13:40:40 +0200 |
| commit | e21d59e346c5ac04c02fd0309b7085ff1a987f6c (patch) | |
| tree | 908b1f657ab2a32fc10e502af76129f3b5e74858 /mu | |
| parent | cc664b81284a469f4f6a90de260697ad2bb257f1 (diff) | |
mu init: implement --reinit option
Create new mu database from an existing one.
Diffstat (limited to 'mu')
| -rw-r--r-- | mu/mu-cmd.cc | 43 | ||||
| -rw-r--r-- | mu/mu-options.cc | 8 |
2 files changed, 36 insertions, 15 deletions
diff --git a/mu/mu-cmd.cc b/mu/mu-cmd.cc index 5042239..3f8a7c9 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<void> 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"); - - 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); - - auto store = Store::make_new(opts.runtime_path(RuntimePath::XapianDb), - opts.init.maildir, opts.init.my_addresses, conf); + auto store = std::invoke([&]()->Result<Store> { + + /* + * 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); + }); + 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 d116511..99e8efe 100644 --- a/mu/mu-options.cc +++ b/mu/mu-options.cc @@ -364,11 +364,17 @@ sub_init(CLI::App& sub, Options& opts) ->type_name("<maildir>"); sub.add_option("--my-address", opts.init.my_addresses, "Personal e-mail addresses") - ->type_name("<addresses>"); + ->type_name("<address>"); 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 |
