mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
refactor(commands): remove help text from command macro and use method to set it
This commit is contained in:
parent
07541d9926
commit
c6db96115e
6 changed files with 44 additions and 74 deletions
|
|
@ -36,11 +36,7 @@ pub struct Command {
|
|||
}
|
||||
|
||||
impl Command {
|
||||
pub fn new(
|
||||
tokens: impl IntoIterator<Item = Token>,
|
||||
help: impl Into<SmolStr>,
|
||||
cb: impl Into<SmolStr>,
|
||||
) -> Self {
|
||||
pub fn new(tokens: impl IntoIterator<Item = Token>, cb: impl Into<SmolStr>) -> Self {
|
||||
let tokens = tokens.into_iter().collect::<Vec<_>>();
|
||||
assert!(tokens.len() > 0);
|
||||
let mut parse_flags_before = tokens.len();
|
||||
|
|
@ -60,7 +56,7 @@ impl Command {
|
|||
}
|
||||
Self {
|
||||
flags: Vec::new(),
|
||||
help: help.into(),
|
||||
help: SmolStr::new_static("<no help text>"),
|
||||
cb: cb.into(),
|
||||
show_in_suggestions: true,
|
||||
parse_flags_before,
|
||||
|
|
@ -68,6 +64,11 @@ impl Command {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn help(mut self, v: impl Into<SmolStr>) -> Self {
|
||||
self.help = v.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn show_in_suggestions(mut self, v: bool) -> Self {
|
||||
self.show_in_suggestions = v;
|
||||
self
|
||||
|
|
@ -111,16 +112,15 @@ impl Display for Command {
|
|||
// (and something like &dyn Trait would require everything to be referenced which doesnt look nice anyway)
|
||||
#[macro_export]
|
||||
macro_rules! command {
|
||||
([$($v:expr),+], $cb:expr, $help:expr) => {
|
||||
$crate::commands::Command::new([$(Token::from($v)),*], $help, $cb)
|
||||
([$($v:expr),+], $cb:expr$(,)*) => {
|
||||
$crate::commands::Command::new([$(Token::from($v)),*], $cb)
|
||||
};
|
||||
}
|
||||
|
||||
pub fn all() -> Vec<Command> {
|
||||
pub fn all() -> impl Iterator<Item = Command> {
|
||||
(help::cmds())
|
||||
.chain(system::cmds())
|
||||
.chain(member::cmds())
|
||||
.chain(config::cmds())
|
||||
.chain(fun::cmds())
|
||||
.collect()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,21 +5,15 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
|||
let autoproxy = ["autoproxy", "ap"];
|
||||
|
||||
[
|
||||
command!(
|
||||
[cfg, autoproxy, ["account", "ac"]],
|
||||
"cfg_ap_account_show",
|
||||
"Shows autoproxy status for the account"
|
||||
),
|
||||
command!([cfg, autoproxy, ["account", "ac"]], "cfg_ap_account_show")
|
||||
.help("Shows autoproxy status for the account"),
|
||||
command!(
|
||||
[cfg, autoproxy, ["account", "ac"], Toggle],
|
||||
"cfg_ap_account_update",
|
||||
"Toggles autoproxy for the account"
|
||||
),
|
||||
command!(
|
||||
[cfg, autoproxy, ["timeout", "tm"]],
|
||||
"cfg_ap_timeout_show",
|
||||
"Shows the autoproxy timeout"
|
||||
),
|
||||
"cfg_ap_account_update"
|
||||
)
|
||||
.help("Toggles autoproxy for the account"),
|
||||
command!([cfg, autoproxy, ["timeout", "tm"]], "cfg_ap_timeout_show")
|
||||
.help("Shows the autoproxy timeout"),
|
||||
command!(
|
||||
[
|
||||
cfg,
|
||||
|
|
@ -27,9 +21,9 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
|||
["timeout", "tm"],
|
||||
any!(Disable, Reset, ("timeout", OpaqueString::SINGLE)) // todo: we should parse duration / time values
|
||||
],
|
||||
"cfg_ap_timeout_update",
|
||||
"Sets the autoproxy timeout"
|
||||
),
|
||||
"cfg_ap_timeout_update"
|
||||
)
|
||||
.help("Sets the autoproxy timeout"),
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ use super::*;
|
|||
|
||||
pub fn cmds() -> impl Iterator<Item = Command> {
|
||||
[
|
||||
command!(["thunder"], "fun_thunder", "fun thunder"),
|
||||
command!(["meow"], "fun_meow", "fun meow"),
|
||||
command!(["thunder"], "fun_thunder"),
|
||||
command!(["meow"], "fun_meow"),
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ use super::*;
|
|||
pub fn cmds() -> impl Iterator<Item = Command> {
|
||||
let help = ["help", "h"];
|
||||
[
|
||||
command!([help], "help", "Shows the help command"),
|
||||
command!([help, "commands"], "help_commands", "help commands"),
|
||||
command!([help, "proxy"], "help_proxy", "help proxy"),
|
||||
command!([help], "help").help("Shows the help command"),
|
||||
command!([help, "commands"], "help_commands").help("help commands"),
|
||||
command!([help, "proxy"], "help_proxy").help("help proxy"),
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,22 +7,13 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
|||
let new = ["new", "n"];
|
||||
|
||||
[
|
||||
command!(
|
||||
[member, new, ("name", OpaqueString::SINGLE)],
|
||||
"member_new",
|
||||
"Creates a new system member"
|
||||
),
|
||||
command!(
|
||||
[member, MemberRef],
|
||||
"member_show",
|
||||
"Shows information about a member"
|
||||
)
|
||||
.value_flag("pt", Disable),
|
||||
command!(
|
||||
[member, MemberRef, description],
|
||||
"member_desc_show",
|
||||
"Shows a member's description"
|
||||
),
|
||||
command!([member, new, ("name", OpaqueString::SINGLE)], "member_new")
|
||||
.help("Creates a new system member"),
|
||||
command!([member, MemberRef], "member_show")
|
||||
.help("Shows information about a member")
|
||||
.value_flag("pt", Disable),
|
||||
command!([member, MemberRef, description], "member_desc_show")
|
||||
.help("Shows a member's description"),
|
||||
command!(
|
||||
[
|
||||
member,
|
||||
|
|
@ -30,14 +21,11 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
|||
description,
|
||||
("description", OpaqueString::REMAINDER)
|
||||
],
|
||||
"member_desc_update",
|
||||
"Changes a member's description"
|
||||
),
|
||||
command!(
|
||||
[member, MemberRef, privacy],
|
||||
"member_privacy_show",
|
||||
"Displays a member's current privacy settings"
|
||||
),
|
||||
"member_desc_update"
|
||||
)
|
||||
.help("Changes a member's description"),
|
||||
command!([member, MemberRef, privacy], "member_privacy_show")
|
||||
.help("Displays a member's current privacy settings"),
|
||||
command!(
|
||||
[
|
||||
member,
|
||||
|
|
@ -46,15 +34,10 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
|||
MemberPrivacyTarget,
|
||||
("new_privacy_level", PrivacyLevel)
|
||||
],
|
||||
"member_privacy_update",
|
||||
"Changes a member's privacy settings"
|
||||
),
|
||||
command!(
|
||||
[member, MemberRef, "soulscream"],
|
||||
"member_soulscream",
|
||||
"todo"
|
||||
"member_privacy_update"
|
||||
)
|
||||
.show_in_suggestions(false),
|
||||
.help("Changes a member's privacy settings"),
|
||||
command!([member, MemberRef, "soulscream"], "member_soulscream").show_in_suggestions(false),
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,17 +5,10 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
|||
let new = ["new", "n"];
|
||||
|
||||
[
|
||||
command!(
|
||||
[system],
|
||||
"system_show",
|
||||
"Shows information about your system"
|
||||
),
|
||||
command!([system, new], "system_new", "Creates a new system"),
|
||||
command!(
|
||||
[system, new, ("name", OpaqueString::SINGLE)],
|
||||
"system_new",
|
||||
"Creates a new system"
|
||||
),
|
||||
command!([system], "system_show").help("Shows information about your system"),
|
||||
command!([system, new], "system_new").help("Creates a new system"),
|
||||
command!([system, new, ("name", OpaqueString::SINGLE)], "system_new")
|
||||
.help("Creates a new system"),
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue