From 46fa4f2aa224daa806141c33e618feda2265ce92 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 27 Jul 2025 09:24:57 +0300 Subject: [PATCH] mu: add 'label' command + manpage + tests Add a label command and document it. --- lib/message/mu-labels.cc | 17 +- man/meson.build | 1 + man/mu-label.1.org | 156 ++++++++++ mu/meson.build | 1 + mu/mu-cmd-count.cc | 647 +++++++++++++++++++++++++++++++++++++++ mu/mu-cmd-label.cc | 549 +++++++++++++++++++++++++++++++++ mu/mu-cmd.cc | 19 ++ mu/mu-cmd.hh | 10 + mu/mu-options.cc | 95 +++++- mu/mu-options.hh | 26 +- mu/tests/meson.build | 7 + 11 files changed, 1510 insertions(+), 18 deletions(-) create mode 100644 man/mu-label.1.org create mode 100644 mu/mu-cmd-count.cc create mode 100644 mu/mu-cmd-label.cc diff --git a/lib/message/mu-labels.cc b/lib/message/mu-labels.cc index 3f800eba..13a789bc 100644 --- a/lib/message/mu-labels.cc +++ b/lib/message/mu-labels.cc @@ -20,12 +20,10 @@ #include "mu-labels.hh" #include -#include using namespace Mu; using namespace Mu::Labels; - Result Mu::Labels::validate_label(const std::string &label) { @@ -55,19 +53,24 @@ Mu::Labels::validate_label(const std::string &label) if (uc > ' ' && uc <= '~') { switch (uc) { case '"': + case ',': case '/': case '\\': case '*': case '$': return Err(Error{Error::Code::InvalidArgument, - "illegal character '{}' in label ({})", uc, label}); + "illegal character '{}' in label '{}'", uc, label}); default: break; } - } else + } else if (::isprint(uc)) return Err(Error{Error::Code::InvalidArgument, - "illegal non alpha-numeric character '{}' in label ({})", - uc, label}); + "illegal non alpha-numeric character '{}' in label '{}'", + static_cast(uc), label}); + else + return Err(Error{Error::Code::InvalidArgument, + "illegal non alpha-numeric character {:#x} in label '{}'", + uc, label}); } return Ok(); @@ -156,7 +159,6 @@ Mu::Labels::updated_labels(const LabelVec& labels, const DeltaLabelVec& deltas) static void test_parse_delta_label() { - { const auto expr = parse_delta_label("+foo"); assert_valid_result(expr); @@ -164,7 +166,6 @@ test_parse_delta_label() assert_equal(expr->second, "foo"); } - { const auto expr = parse_delta_label("-bar@cuux"); assert_valid_result(expr); diff --git a/man/meson.build b/man/meson.build index f48677b0..1034655c 100644 --- a/man/meson.build +++ b/man/meson.build @@ -55,6 +55,7 @@ man_orgs = [ 'mu-index.1.org', 'mu-info.1.org', 'mu-init.1.org', + 'mu-label.1.org', 'mu-mkdir.1.org', 'mu-move.1.org', 'mu-query.7.org', diff --git a/man/mu-label.1.org b/man/mu-label.1.org new file mode 100644 index 00000000..aab82b94 --- /dev/null +++ b/man/mu-label.1.org @@ -0,0 +1,156 @@ +#+TITLE: MU LABEL +#+MAN_CLASS_OPTIONS: :section-id "@SECTION_ID@" :date "@MAN_DATE@" +#+include: macros.inc + +* NAME + +mu-label - attach labels to messages. Export labels to file, and import them. + +* SYNOPSIS + +*mu* [​_COMMON-OPTIONS_​] *label* update [​UPDATE-OPTIONS​] "" --labels [{+,-}