@@ -14,13 +14,41 @@ pub struct CommandRegistration {
1414 pub ( super ) handler : CommandHandlerWrapper ,
1515}
1616
17+ /// A free-form help topic not tied to a command handler.
18+ ///
19+ /// Use this for topics that describe concepts rather than commands — for example
20+ /// channel modes, user modes, or any other subject a user might query with `HELP`.
21+ ///
22+ /// Register a topic at the call site with [`inventory::submit!`]:
23+ ///
24+ /// ```rust,ignore
25+ /// inventory::submit!(HelpTopic {
26+ /// topic: "CMODE_SECRET",
27+ /// lines: &[
28+ /// "CMODE_SECRET (+s)",
29+ /// "",
30+ /// "Marks the channel as secret. Secret channels are hidden from /LIST",
31+ /// "and /WHOIS for users who are not members.",
32+ /// ],
33+ /// });
34+ /// ```
35+ ///
36+ /// Topics are looked up case-insensitively via [`CommandDispatcher::get_help_topic`].
37+ pub struct HelpTopic {
38+ /// The name of the topic, matched case-insensitively against the argument to `HELP`.
39+ pub topic : & ' static str ,
40+ /// Lines of help text returned to the client.
41+ pub lines : & ' static [ & ' static str ] ,
42+ }
43+
1744/// A command dispatcher. Collects registered command handlers and allows lookup by
1845/// command name.
1946pub struct CommandDispatcher {
2047 handlers : HashMap < String , CommandHandlerWrapper > ,
2148}
2249
2350inventory:: collect!( CommandRegistration ) ;
51+ inventory:: collect!( HelpTopic ) ;
2452
2553impl CommandDispatcher {
2654 /// Construct a default `CommandDispatcher`.
@@ -67,4 +95,19 @@ impl CommandDispatcher {
6795 }
6896 }
6997 }
98+
99+ /// Look up a free-form [`HelpTopic`] by name (case-insensitive).
100+ ///
101+ /// Returns the topic's lines of text, or `None` if no topic with that name was registered.
102+ pub fn get_help_topic ( & self , topic : & str ) -> Option < & ' static [ & ' static str ] > {
103+ inventory:: iter :: < HelpTopic >
104+ . into_iter ( )
105+ . find ( |t| t. topic . eq_ignore_ascii_case ( topic) )
106+ . map ( |t| t. lines )
107+ }
108+
109+ /// Iterate over all registered free-form [`HelpTopic`] entries.
110+ pub fn iter_help_topics ( & self ) -> impl Iterator < Item = & ' static HelpTopic > {
111+ inventory:: iter :: < HelpTopic > . into_iter ( )
112+ }
70113}
0 commit comments