mu init: implement --reinit option
Create new mu database from an existing one.
This commit is contained in:
@ -34,6 +34,13 @@ mailing list messages.
|
|||||||
wrapped in */* (such as =/foo-.*@example\\.com/=). Depending on your shell, the
|
wrapped in */* (such as =/foo-.*@example\\.com/=). Depending on your shell, the
|
||||||
argument may need to be quoted.
|
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: "muhome.inc" :minlevel 2
|
||||||
|
|
||||||
#+include: "prefooter.inc" :minlevel 1
|
#+include: "prefooter.inc" :minlevel 1
|
||||||
|
|||||||
39
mu/mu-cmd.cc
39
mu/mu-cmd.cc
@ -410,26 +410,41 @@ cmd_info(const Mu::Store& store, const Options& opts)
|
|||||||
static Result<void>
|
static Result<void>
|
||||||
cmd_init(const Options& opts)
|
cmd_init(const Options& opts)
|
||||||
{
|
{
|
||||||
/* not provided, nor could we find a good default */
|
auto store = std::invoke([&]()->Result<Store> {
|
||||||
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);
|
* reinit
|
||||||
conf.batch_size = opts.init.batch_size.value_or(0);
|
*/
|
||||||
|
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)
|
if (!store)
|
||||||
return Err(store.error());
|
return Err(store.error());
|
||||||
|
|
||||||
if (!opts.quiet) {
|
if (!opts.quiet) {
|
||||||
cmd_info(*store, opts);
|
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();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -364,11 +364,17 @@ sub_init(CLI::App& sub, Options& opts)
|
|||||||
->type_name("<maildir>");
|
->type_name("<maildir>");
|
||||||
sub.add_option("--my-address", opts.init.my_addresses,
|
sub.add_option("--my-address", opts.init.my_addresses,
|
||||||
"Personal e-mail addresses")
|
"Personal e-mail addresses")
|
||||||
->type_name("<addresses>");
|
->type_name("<address>");
|
||||||
sub.add_option("--max-message-size", opts.init.max_msg_size,
|
sub.add_option("--max-message-size", opts.init.max_msg_size,
|
||||||
"Maximum allowed message size in bytes");
|
"Maximum allowed message size in bytes");
|
||||||
sub.add_option("--batch-size", opts.init.batch_size,
|
sub.add_option("--batch-size", opts.init.batch_size,
|
||||||
"Maximum size of database transaction");
|
"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
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user