implement parse list options and related commands

This commit is contained in:
dusk 2025-09-30 18:45:35 +00:00
parent 3e7898e5cc
commit 95fc7e9f60
No known key found for this signature in database
18 changed files with 367 additions and 199 deletions

View file

@ -1,11 +1,38 @@
use command_parser::token::TokensIterator;
use crate::utils::get_list_flags;
use super::*;
pub fn group() -> (&'static str, [&'static str; 1]) {
("group", ["g"])
pub fn group() -> (&'static str, [&'static str; 2]) {
("group", ["g", "groups"])
}
pub fn targeted() -> TokensIterator {
tokens!(group(), GroupRef)
}
pub fn cmds() -> impl Iterator<Item = Command> {
let group = group();
let group_target = targeted();
let apply_list_opts = |cmd: Command| cmd.flags(get_list_flags());
let group_list_members = tokens!(group_target, ("members", ["list", "ls"]));
let group_list_members_cmd = [
command!(group_list_members => "group_list_members"),
command!(group_list_members, "list" => "group_list_members"),
command!(group_list_members, ("search", ["find", "query"]), ("query", OpaqueStringRemainder) => "group_search_members"),
]
.into_iter()
.map(apply_list_opts);
let system_groups_cmd = [
command!(group, ("list", ["ls"]) => "group_list_groups"),
command!(group, ("search", ["find", "query"]), ("query", OpaqueStringRemainder) => "group_search_groups"),
]
.into_iter()
.map(apply_list_opts);
system_groups_cmd.chain(group_list_members_cmd)
}

View file

@ -18,11 +18,14 @@ pub mod server_config;
pub mod switch;
pub mod system;
pub mod utils;
use command_parser::{command, command::Command, parameter::ParameterKind::*, tokens};
pub fn all() -> impl Iterator<Item = Command> {
(help::cmds())
.chain(system::cmds())
.chain(group::cmds())
.chain(member::cmds())
.chain(config::cmds())
.chain(fun::cmds())

View file

@ -1,5 +1,7 @@
use command_parser::token::TokensIterator;
use crate::utils::get_list_flags;
use super::*;
pub fn member() -> (&'static str, [&'static str; 1]) {
@ -291,6 +293,16 @@ pub fn cmds() -> impl Iterator<Item = Command> {
.chain(member_webhook_avatar_cmd)
.chain(member_server_avatar_cmd);
let member_group = tokens!(member_target, group::group());
let member_list_group_cmds = [
command!(member_group => "member_list_groups"),
command!(member_group, "list" => "member_list_groups"),
command!(member_group, ("search", ["find", "query"]), ("query", OpaqueStringRemainder) => "member_search_groups"),
]
.into_iter()
.map(|cmd| cmd.flags(get_list_flags()));
let member_group_cmds = member_list_group_cmds;
let member_delete_cmd =
[command!(member_target, delete => "member_delete").help("Deletes a member")].into_iter();
@ -298,10 +310,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
[command!(member_target, "soulscream" => "member_soulscream").show_in_suggestions(false)]
.into_iter();
let member_list = [command!(member, "list" => "members_list")].into_iter();
member_new_cmd
.chain(member_list)
.chain(member_info_cmd)
.chain(member_name_cmd)
.chain(member_description_cmd)
@ -318,4 +327,5 @@ pub fn cmds() -> impl Iterator<Item = Command> {
.chain(member_message_settings_cmd)
.chain(member_delete_cmd)
.chain(member_easter_eggs)
.chain(member_group_cmds)
}

View file

@ -1,3 +1,5 @@
use crate::utils::get_list_flags;
use super::*;
pub fn cmds() -> impl Iterator<Item = Command> {
@ -7,7 +9,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
[
command!(random => "random_self").flag(group),
command!(system::targeted(), random => "system_random").flag(group),
command!(group::targeted(), random => "group_random_member"),
command!(group::targeted(), random => "group_random_member").flags(get_list_flags()),
]
.into_iter()
.map(|cmd| cmd.flag(("all", ["a"])))

View file

@ -1,5 +1,7 @@
use command_parser::token::TokensIterator;
use crate::utils::get_list_flags;
use super::*;
pub fn cmds() -> impl Iterator<Item = Command> {
@ -251,8 +253,33 @@ pub fn edit() -> impl Iterator<Item = Command> {
]
.into_iter();
let system_list =
[command!(system_target, ("members", ["list"]) => "system_members_list")].into_iter();
let system_list = ("members", ["list"]);
let system_search = tokens!(
("search", ["query", "find"]),
("query", OpaqueStringRemainder),
);
let add_list_flags = |cmd: Command| cmd.flags(get_list_flags());
let system_list_cmd = [
command!(system_target, system_list => "system_members_list"),
command!(system_target, system_search => "system_members_search"),
]
.into_iter()
.map(add_list_flags);
let system_list_self_cmd = [
command!(system, system_list => "system_members_list_self"),
command!(system, system_search => "system_members_search_self"),
]
.into_iter()
.map(add_list_flags);
let system_groups = tokens!(system_target, ("groups", ["gs"]));
let system_groups_cmd = [
command!(system_groups => "system_list_groups"),
command!(system_groups, ("list", ["ls"]) => "system_list_groups"),
command!(system_groups, ("search", ["find", "query"]), ("query", OpaqueStringRemainder) => "system_search_groups"),
]
.into_iter()
.map(add_list_flags);
system_new_cmd
.chain(system_name_self_cmd)
@ -265,6 +292,7 @@ pub fn edit() -> impl Iterator<Item = Command> {
.chain(system_avatar_self_cmd)
.chain(system_server_avatar_self_cmd)
.chain(system_banner_self_cmd)
.chain(system_list_self_cmd)
.chain(system_delete)
.chain(system_privacy_cmd)
.chain(system_proxy_cmd)
@ -281,5 +309,6 @@ pub fn edit() -> impl Iterator<Item = Command> {
.chain(system_info_cmd)
.chain(system_front_cmd)
.chain(system_link)
.chain(system_list)
.chain(system_list_cmd)
.chain(system_groups_cmd)
}

View file

@ -0,0 +1,52 @@
use command_parser::flag::Flag;
pub fn get_list_flags() -> [Flag; 22] {
[
// Short or long list
Flag::from(("full", ["f", "big", "details", "long"])),
// Search description
Flag::from((
"search-description",
[
"filter-description",
"in-description",
"sd",
"description",
"desc",
],
)),
// Sort properties
Flag::from(("by-name", ["bn"])),
Flag::from(("by-display-name", ["bdn"])),
Flag::from(("by-id", ["bid"])),
Flag::from(("by-message-count", ["bmc"])),
Flag::from(("by-created", ["bc", "bcd"])),
Flag::from((
"by-last-fronted",
["by-last-front", "by-last-switch", "blf", "bls"],
)),
Flag::from(("by-last-message", ["blm", "blp"])),
Flag::from(("by-birthday", ["by-birthdate", "bbd"])),
Flag::from(("random", ["rand"])),
// Sort reverse
Flag::from(("reverse", ["r", "rev"])),
// Privacy filter
Flag::from(("all", ["a"])),
Flag::from(("private-only", ["po"])),
// Additional fields to include
Flag::from((
"with-last-switch",
["with-last-fronted", "with-last-front", "wls", "wlf"],
)),
Flag::from(("with-last-message", ["with-last-proxy", "wlm", "wlp"])),
Flag::from(("with-message-count", ["wmc"])),
Flag::from(("with-created", ["wc"])),
Flag::from((
"with-avatar",
["with-image", "with-icon", "wa", "wi", "ia", "ii", "img"],
)),
Flag::from(("with-pronouns", ["wp", "wprns"])),
Flag::from(("with-displayname", ["wdn"])),
Flag::from(("with-birthday", ["wbd", "wb"])),
]
}