summaryrefslogtreecommitdiff
path: root/mu
diff options
context:
space:
mode:
authorDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2025-09-02 21:08:54 +0300
committerDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2025-09-02 21:08:54 +0300
commit0a2fda4b0b3638fdbd80e9f4b2102f104cc8e192 (patch)
tree4b9c9fae9115e7d26b7239c7f60ab255f6019c86 /mu
parent59717bcfcc0812781f59d60e75aa149affd550bc (diff)
labels: allow restoring cache-map
E.g. with unexpected termination for mu it is possible that the labels-cache (i.e., the one that is used for auto-completion) gets disconnected from reality. Add a --restore option to `mu label list` to restore the actual labels from the labels seen in the store.
Diffstat (limited to 'mu')
-rw-r--r--mu/mu-cmd-label.cc11
-rw-r--r--mu/mu-options.cc2
-rw-r--r--mu/mu-options.hh4
3 files changed, 13 insertions, 4 deletions
diff --git a/mu/mu-cmd-label.cc b/mu/mu-cmd-label.cc
index f0df1d1..d2be417 100644
--- a/mu/mu-cmd-label.cc
+++ b/mu/mu-cmd-label.cc
@@ -113,11 +113,16 @@ label_clear(Mu::Store& store, const Options& opts)
}
static Result<void>
-label_list(const Mu::Store& store, const Options& opts)
+label_list(Mu::Store& store, const Options& opts)
{
- const auto label_map{store.label_map()};
+ if (opts.label.restore) {
+ if (!opts.quiet)
+ mu_println("labels: restoring list from store...");
+ if (const auto res = store.restore_label_map(); !res)
+ return res;
+ }
- for (const auto& [label, n]: label_map)
+ for (const auto& [label, n]: store.label_map())
if (opts.verbose)
mu_println("{}: {}", label, n);
else
diff --git a/mu/mu-options.cc b/mu/mu-options.cc
index e570ca8..bacaf40 100644
--- a/mu/mu-options.cc
+++ b/mu/mu-options.cc
@@ -528,6 +528,8 @@ sub_label(CLI::App& sub, Options& opts)
// list
[[maybe_unused]] auto list = sub.add_subcommand("list", "list labels in the store");
+ list->add_flag("--restore", opts.label.restore,
+ "Restore the label-list from the labels in store");
add_muhome_option(*list, opts);
// export
diff --git a/mu/mu-options.hh b/mu/mu-options.hh
index e0a51fe..66902ff 100644
--- a/mu/mu-options.hh
+++ b/mu/mu-options.hh
@@ -209,7 +209,9 @@ struct Options {
bool dry_run{}; /**< Merely print the messages that would be
* labeled without doing so */
StringVec delta_labels; /**< labels to add (+) or remove (-) */
- bool read_only{}; /** do not require writable store */
+ bool read_only{}; /**< do not require writable store */
+
+ bool restore{}; /**< restore the labels list */
OptString file; /** file for import/export */