Author: Manos Pitsidianakis [manos@pitsidianak.is]
Hash: f5e21634de4d6a1e442d55398c8f916412d7a7c3
Timestamp: Sun, 29 Oct 2023 10:37:21 +0000 (10 months ago)

+24 -1 +/-3 browse
cli: add possible_values for QueueValueParser
cli: add possible_values for QueueValueParser

--help did not display possible values for --queue argument, so it was
not possible for the user to figure it out without looking at the source
code.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
1diff --git a/cli/src/args.rs b/cli/src/args.rs
2index eb65f52..2184b1f 100644
3--- a/cli/src/args.rs
4+++ b/cli/src/args.rs
5 @@ -554,6 +554,14 @@ impl TypedValueParser for QueueValueParser {
6 })?)
7 .map_err(|err| cmd.clone().error(ErrorKind::InvalidValue, err))
8 }
9+
10+ fn possible_values(&self) -> Option<Box<dyn Iterator<Item = clap::builder::PossibleValue>>> {
11+ Some(Box::new(
12+ mailpot::queue::Queue::possible_values()
13+ .iter()
14+ .map(clap::builder::PossibleValue::new),
15+ ))
16+ }
17 }
18
19 impl Default for QueueValueParser {
20 diff --git a/core/src/queue.rs b/core/src/queue.rs
21index 45761ad..9a09e26 100644
22--- a/core/src/queue.rs
23+++ b/core/src/queue.rs
24 @@ -69,7 +69,7 @@ impl std::str::FromStr for Queue {
25
26 impl Queue {
27 /// Returns the name of the queue used in the database schema.
28- pub fn as_str(&self) -> &'static str {
29+ pub const fn as_str(&self) -> &'static str {
30 match self {
31 Self::Maildrop => "maildrop",
32 Self::Hold => "hold",
33 @@ -79,6 +79,19 @@ impl Queue {
34 Self::Error => "error",
35 }
36 }
37+
38+ /// Returns all possible variants as `&'static str`
39+ pub const fn possible_values() -> &'static [&'static str] {
40+ const VALUES: &[&str] = &[
41+ Queue::Maildrop.as_str(),
42+ Queue::Hold.as_str(),
43+ Queue::Deferred.as_str(),
44+ Queue::Corrupt.as_str(),
45+ Queue::Out.as_str(),
46+ Queue::Error.as_str(),
47+ ];
48+ VALUES
49+ }
50 }
51
52 impl std::fmt::Display for Queue {
53 diff --git a/docs/mpot.1 b/docs/mpot.1
54index 8331f07..ae10fd7 100644
55--- a/docs/mpot.1
56+++ b/docs/mpot.1
57 @@ -754,6 +754,8 @@ Mail that has not been handled properly end up in the error queue.
58 .TP
59 \-\-queue \fIQUEUE\fR
60
61+ .br
62+ [\fIpossible values: \fRmaildrop, hold, deferred, corrupt, out, error]
63 .ie \n(.g .ds Aq \(aq
64 .el .ds Aq '
65 .\fB