From 12655fb5390ea44764981451f7ace6b755fc4b02 Mon Sep 17 00:00:00 2001 From: dawn <90008@gaze.systems> Date: Mon, 26 Jan 2026 02:22:54 +0300 Subject: [PATCH] add missing -yes flags to command definitions, use log crate instead of printlns in command parser, also accept double dash for flags --- Cargo.lock | 36 +++++++++++++++++++++++ PluralKit.Bot/CommandMeta/CommandTree.cs | 25 ++++++++-------- PluralKit.Bot/CommandSystem/Parameters.cs | 4 --- PluralKit.Bot/Commands/GroupMember.cs | 2 +- PluralKit.Bot/Commands/SystemLink.cs | 4 +-- crates/command_definitions/src/config.rs | 10 +++++-- crates/command_definitions/src/group.rs | 9 ++---- crates/command_definitions/src/member.rs | 6 +++- crates/command_definitions/src/random.rs | 2 +- crates/command_definitions/src/switch.rs | 3 ++ crates/command_definitions/src/system.rs | 16 ++++++++-- crates/command_parser/Cargo.toml | 3 +- crates/command_parser/src/lib.rs | 19 ++++++------ crates/command_parser/src/string.rs | 24 ++++++++++----- crates/commands/Cargo.toml | 2 ++ crates/commands/src/lib.rs | 18 +++++++++++- 16 files changed, 130 insertions(+), 53 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0bc78644..c8afef88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -647,6 +647,16 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "colored" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" +dependencies = [ + "lazy_static", + "windows-sys 0.59.0", +] + [[package]] name = "combine" version = "4.6.7" @@ -669,6 +679,7 @@ name = "command_parser" version = "0.1.0" dependencies = [ "lazy_static", + "log", "ordermap", "regex", "smol_str", @@ -682,6 +693,8 @@ dependencies = [ "command_definitions", "command_parser", "lazy_static", + "log", + "simple_logger", "uniffi", ] @@ -2532,6 +2545,15 @@ dependencies = [ "libc", ] +[[package]] +name = "num_threads" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" +dependencies = [ + "libc", +] + [[package]] name = "object" version = "0.37.3" @@ -3928,6 +3950,18 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" +[[package]] +name = "simple_logger" +version = "4.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e7e46c8c90251d47d08b28b8a419ffb4aede0f87c2eea95e17d1d5bacbf3ef1" +dependencies = [ + "colored", + "log", + "time", + "windows-sys 0.48.0", +] + [[package]] name = "siphasher" version = "0.3.11" @@ -4402,7 +4436,9 @@ checksum = "91e7d9e3bb61134e77bde20dd4825b97c010155709965fedf0f49bb138e52a9d" dependencies = [ "deranged", "itoa", + "libc", "num-conv", + "num_threads", "powerfmt", "serde", "time-core", diff --git a/PluralKit.Bot/CommandMeta/CommandTree.cs b/PluralKit.Bot/CommandMeta/CommandTree.cs index 69da30d0..210c36a0 100644 --- a/PluralKit.Bot/CommandMeta/CommandTree.cs +++ b/PluralKit.Bot/CommandMeta/CommandTree.cs @@ -19,7 +19,7 @@ public partial class CommandTree Commands.Invite => ctx.Execute(Invite, m => m.Invite(ctx)), Commands.Stats => ctx.Execute(null, m => m.Stats(ctx)), Commands.MemberShow(var param, var flags) => ctx.Execute(MemberInfo, m => m.ViewMember(ctx, param.target, flags.show_embed)), - Commands.MemberNew(var param, _) => ctx.Execute(MemberNew, m => m.NewMember(ctx, param.name)), + Commands.MemberNew(var param, var flags) => ctx.Execute(MemberNew, m => m.NewMember(ctx, param.name, flags.yes)), Commands.MemberSoulscream(var param, _) => ctx.Execute(MemberInfo, m => m.Soulscream(ctx, param.target)), Commands.MemberAvatarShow(var param, var flags) => ctx.Execute(MemberAvatar, m => m.ShowAvatar(ctx, param.target, flags.GetReplyFormat())), Commands.MemberAvatarClear(var param, var flags) => ctx.Execute(MemberAvatar, m => m.ClearAvatar(ctx, param.target, flags.yes)), @@ -60,9 +60,9 @@ public partial class CommandTree Commands.MemberServerKeepproxyClear(var param, var flags) => ctx.Execute(MemberServerKeepProxy, m => m.ClearServerKeepProxy(ctx, param.target, flags.yes)), Commands.MemberProxyShow(var param, _) => ctx.Execute(MemberProxy, m => m.ShowProxy(ctx, param.target)), Commands.MemberProxyClear(var param, var flags) => ctx.Execute(MemberProxy, m => m.ClearProxy(ctx, param.target, flags.yes)), - Commands.MemberProxyAdd(var param, _) => ctx.Execute(MemberProxy, m => m.AddProxy(ctx, param.target, param.tag)), + Commands.MemberProxyAdd(var param, var flags) => ctx.Execute(MemberProxy, m => m.AddProxy(ctx, param.target, param.tag, flags.yes)), Commands.MemberProxyRemove(var param, _) => ctx.Execute(MemberProxy, m => m.RemoveProxy(ctx, param.target, param.tag)), - Commands.MemberProxySet(var param, _) => ctx.Execute(MemberProxy, m => m.SetProxy(ctx, param.target, param.tags)), + Commands.MemberProxySet(var param, var flags) => ctx.Execute(MemberProxy, m => m.SetProxy(ctx, param.target, param.tags, flags.yes)), Commands.MemberTtsShow(var param, _) => ctx.Execute(MemberTts, m => m.ShowTts(ctx, param.target)), Commands.MemberTtsUpdate(var param, _) => ctx.Execute(MemberTts, m => m.ChangeTts(ctx, param.target, param.value)), Commands.MemberAutoproxyShow(var param, _) => ctx.Execute(MemberAutoproxy, m => m.ShowAutoproxy(ctx, param.target)), @@ -82,7 +82,7 @@ public partial class CommandTree Commands.CfgApTimeoutUpdate(var param, _) => ctx.Execute(null, m => m.EditAutoproxyTimeout(ctx, param.timeout)), Commands.CfgTimezoneShow => ctx.Execute(null, m => m.ViewSystemTimezone(ctx)), Commands.CfgTimezoneReset => ctx.Execute(null, m => m.ResetSystemTimezone(ctx)), - Commands.CfgTimezoneUpdate(var param, _) => ctx.Execute(null, m => m.EditSystemTimezone(ctx, param.timezone)), + Commands.CfgTimezoneUpdate(var param, var flags) => ctx.Execute(null, m => m.EditSystemTimezone(ctx, param.timezone, flags.yes)), Commands.CfgPingShow => ctx.Execute(null, m => m.ViewSystemPing(ctx)), Commands.CfgPingUpdate(var param, _) => ctx.Execute(null, m => m.EditSystemPing(ctx, param.toggle)), Commands.CfgMemberPrivacyShow => ctx.Execute(null, m => m.ViewMemberDefaultPrivacy(ctx)), @@ -126,7 +126,6 @@ public partial class CommandTree Commands.SystemNew(var param, _) => ctx.Execute(SystemNew, m => m.New(ctx, param.name)), Commands.SystemShowName(var param, var flags) => ctx.Execute(SystemRename, m => m.ShowName(ctx, param.target ?? ctx.System, flags.GetReplyFormat())), Commands.SystemRename(var param, _) => ctx.Execute(SystemRename, m => m.Rename(ctx, ctx.System, param.name)), - Commands.SystemClearName(var param, var flags) => ctx.Execute(SystemRename, m => m.ClearName(ctx, ctx.System, flags.yes)), Commands.SystemShowServerName(var param, var flags) => ctx.Execute(SystemServerName, m => m.ShowServerName(ctx, param.target ?? ctx.System, flags.GetReplyFormat())), Commands.SystemClearServerName(var param, var flags) => ctx.Execute(SystemServerName, m => m.ClearServerName(ctx, ctx.System, flags.yes)), Commands.SystemRenameServerName(var param, _) => ctx.Execute(SystemServerName, m => m.RenameServerName(ctx, ctx.System, param.name)), @@ -200,11 +199,11 @@ public partial class CommandTree Commands.SystemChangePrivacy(var param, _) => ctx.Execute(SystemPrivacy, m => m.ChangeSystemPrivacy(ctx, ctx.System, param.privacy, param.level)), Commands.SwitchOut(_, _) => ctx.Execute(SwitchOut, m => m.SwitchOut(ctx)), Commands.SwitchDo(var param, _) => ctx.Execute(Switch, m => m.SwitchDo(ctx, param.targets)), - Commands.SwitchMove(var param, _) => ctx.Execute(SwitchMove, m => m.SwitchMove(ctx, param.@string)), - Commands.SwitchEdit(var param, var flags) => ctx.Execute(SwitchEdit, m => m.SwitchEdit(ctx, param.targets, false, flags.first, flags.remove, flags.append, flags.prepend)), + Commands.SwitchMove(var param, var flags) => ctx.Execute(SwitchMove, m => m.SwitchMove(ctx, param.@string, flags.yes)), + Commands.SwitchEdit(var param, var flags) => ctx.Execute(SwitchEdit, m => m.SwitchEdit(ctx, param.targets, false, flags.first, flags.remove, flags.append, flags.prepend, flags.yes)), Commands.SwitchEditOut(_, var flags) => ctx.Execute(SwitchEditOut, m => m.SwitchEditOut(ctx, flags.yes)), - Commands.SwitchDelete(var param, var flags) => ctx.Execute(SwitchDelete, m => m.SwitchDelete(ctx, flags.all)), - Commands.SwitchCopy(var param, var flags) => ctx.Execute(SwitchCopy, m => m.SwitchEdit(ctx, param.targets, true, flags.first, flags.remove, flags.append, flags.prepend)), + Commands.SwitchDelete(var param, var flags) => ctx.Execute(SwitchDelete, m => m.SwitchDelete(ctx, flags.all, flags.yes)), + Commands.SwitchCopy(var param, var flags) => ctx.Execute(SwitchCopy, m => m.SwitchEdit(ctx, param.targets, true, flags.first, flags.remove, flags.append, flags.prepend, false)), Commands.SystemFronter(var param, var flags) => ctx.Execute(SystemFronter, m => m.Fronter(ctx, param.target ?? ctx.System)), Commands.SystemFronterHistory(var param, var flags) => ctx.Execute(SystemFrontHistory, m => m.FrontHistory(ctx, param.target ?? ctx.System, flags.clear)), Commands.SystemFronterPercent(var param, var flags) => ctx.Execute(SystemFrontPercent, m => m.FrontPercent(ctx, param.target ?? ctx.System, flags.duration, flags.fronters_only, flags.flat)), @@ -225,18 +224,18 @@ public partial class CommandTree Commands.SystemRandomGroup(var param, var flags) => ctx.Execute(GroupRandom, m => m.Group(ctx, param.target, flags.all, flags.show_embed)), Commands.GroupRandomMember(var param, var flags) => ctx.Execute(GroupMemberRandom, m => m.GroupMember(ctx, param.target, flags.all, flags.show_embed, flags)), - Commands.SystemLink(var param, _) => ctx.Execute(Link, m => m.LinkSystem(ctx, param.account)), + Commands.SystemLink(var param, var flags) => ctx.Execute(Link, m => m.LinkSystem(ctx, param.account, flags.yes)), Commands.SystemUnlink(var param, var flags) => ctx.Execute(Unlink, m => m.UnlinkAccount(ctx, param.account, flags.yes)), Commands.SystemMembers(var param, var flags) => ctx.Execute(SystemList, m => m.MemberList(ctx, param.target ?? ctx.System, param.query, flags)), Commands.MemberGroups(var param, var flags) => ctx.Execute(MemberGroups, m => m.ListMemberGroups(ctx, param.target, param.query, flags, flags.all)), Commands.GroupMembers(var param, var flags) => ctx.Execute(GroupMemberList, m => m.ListGroupMembers(ctx, param.target, param.query, flags)), Commands.SystemGroups(var param, var flags) => ctx.Execute(GroupList, g => g.ListSystemGroups(ctx, param.target ?? ctx.System, param.query, flags, flags.all)), Commands.GroupsSelf(var param, var flags) => ctx.Execute(GroupList, g => g.ListSystemGroups(ctx, ctx.System, param.query, flags, flags.all)), - Commands.GroupNew(var param, _) => ctx.Execute(GroupNew, g => g.CreateGroup(ctx, param.name)), + Commands.GroupNew(var param, var flags) => ctx.Execute(GroupNew, g => g.CreateGroup(ctx, param.name, flags.yes)), Commands.GroupInfo(var param, var flags) => ctx.Execute(GroupInfo, g => g.ShowGroupCard(ctx, param.target, flags.show_embed, flags.all)), Commands.GroupShowName(var param, var flags) => ctx.Execute(GroupRename, g => g.ShowGroupDisplayName(ctx, param.target, flags.GetReplyFormat())), Commands.GroupClearName(var param, var flags) => ctx.Execute(GroupRename, g => g.RenameGroup(ctx, param.target, null)), - Commands.GroupRename(var param, _) => ctx.Execute(GroupRename, g => g.RenameGroup(ctx, param.target, param.name)), + Commands.GroupRename(var param, var flags) => ctx.Execute(GroupRename, g => g.RenameGroup(ctx, param.target, param.name, flags.yes)), Commands.GroupShowDisplayName(var param, var flags) => ctx.Execute(GroupDisplayName, g => g.ShowGroupDisplayName(ctx, param.target, flags.GetReplyFormat())), Commands.GroupClearDisplayName(var param, var flags) => ctx.Execute(GroupDisplayName, g => g.ClearGroupDisplayName(ctx, param.target)), Commands.GroupChangeDisplayName(var param, _) => ctx.Execute(GroupDisplayName, g => g.ChangeGroupDisplayName(ctx, param.target, param.name)), @@ -252,7 +251,7 @@ public partial class CommandTree Commands.GroupShowColor(var param, var flags) => ctx.Execute(GroupColor, g => g.ShowGroupColor(ctx, param.target, flags.GetReplyFormat())), Commands.GroupClearColor(var param, var flags) => ctx.Execute(GroupColor, g => g.ClearGroupColor(ctx, param.target)), Commands.GroupChangeColor(var param, _) => ctx.Execute(GroupColor, g => g.ChangeGroupColor(ctx, param.target, param.color)), - Commands.GroupAddMember(var param, var flags) => ctx.Execute(GroupAdd, g => g.AddRemoveMembers(ctx, param.target, param.targets, Groups.AddRemoveOperation.Add, flags.all, flags.yes)), + Commands.GroupAddMember(var param, var flags) => ctx.Execute(GroupAdd, g => g.AddRemoveMembers(ctx, param.target, param.targets, Groups.AddRemoveOperation.Add, flags.all)), Commands.GroupRemoveMember(var param, var flags) => ctx.Execute(GroupRemove, g => g.AddRemoveMembers(ctx, param.target, param.targets, Groups.AddRemoveOperation.Remove, flags.all, flags.yes)), Commands.GroupShowPrivacy(var param, _) => ctx.Execute(GroupPrivacy, g => g.ShowGroupPrivacy(ctx, param.target)), Commands.GroupChangePrivacyAll(var param, _) => ctx.Execute(GroupPrivacy, g => g.SetAllGroupPrivacy(ctx, param.target, param.level)), diff --git a/PluralKit.Bot/CommandSystem/Parameters.cs b/PluralKit.Bot/CommandSystem/Parameters.cs index 8de534fd..0278f661 100644 --- a/PluralKit.Bot/CommandSystem/Parameters.cs +++ b/PluralKit.Bot/CommandSystem/Parameters.cs @@ -48,10 +48,6 @@ public class Parameters _cb = command.@commandRef; _flags = command.@flags; _params = command.@params; - foreach (var param in _params) - { - Console.WriteLine($"{param.Key}: {param.Value}"); - } } else { diff --git a/PluralKit.Bot/Commands/GroupMember.cs b/PluralKit.Bot/Commands/GroupMember.cs index 43ccbba9..9dc007f8 100644 --- a/PluralKit.Bot/Commands/GroupMember.cs +++ b/PluralKit.Bot/Commands/GroupMember.cs @@ -83,7 +83,7 @@ public class GroupMember target.Color, opts, all); } - public async Task AddRemoveMembers(Context ctx, PKGroup target, List? _members, Groups.AddRemoveOperation op, bool all, bool confirmYes) + public async Task AddRemoveMembers(Context ctx, PKGroup target, List? _members, Groups.AddRemoveOperation op, bool all, bool confirmYes = false) { ctx.CheckOwnGroup(target); diff --git a/PluralKit.Bot/Commands/SystemLink.cs b/PluralKit.Bot/Commands/SystemLink.cs index ef5f89af..16838367 100644 --- a/PluralKit.Bot/Commands/SystemLink.cs +++ b/PluralKit.Bot/Commands/SystemLink.cs @@ -7,7 +7,7 @@ namespace PluralKit.Bot; public class SystemLink { - public async Task LinkSystem(Context ctx, User account) + public async Task LinkSystem(Context ctx, User account, bool confirmYes = false) { ctx.CheckSystem(); @@ -20,7 +20,7 @@ public class SystemLink throw Errors.AccountInOtherSystem(existingAccount, ctx.Config, ctx.DefaultPrefix); var msg = $"{account.Mention()}, please confirm the link."; - if (!await ctx.PromptYesNo(msg, "Confirm", account, false)) throw Errors.MemberLinkCancelled; + if (!await ctx.PromptYesNo(msg, "Confirm", account, true, confirmYes)) throw Errors.MemberLinkCancelled; await ctx.Repository.AddAccount(ctx.System.Id, account.Id); await ctx.Reply($"{Emojis.Success} Account linked to system."); } diff --git a/crates/command_definitions/src/config.rs b/crates/command_definitions/src/config.rs index 68bd245f..ebd73491 100644 --- a/crates/command_definitions/src/config.rs +++ b/crates/command_definitions/src/config.rs @@ -16,7 +16,8 @@ pub fn cmds() -> impl IntoIterator { command!(ap_account, Toggle => "cfg_ap_account_update") .help("Toggles autoproxy globally for the current account"), command!(ap_timeout => "cfg_ap_timeout_show").help("Shows the autoproxy timeout"), - command!(ap_timeout, RESET => "cfg_ap_timeout_reset").help("Resets the autoproxy timeout"), + command!(ap_timeout, RESET => "cfg_ap_timeout_reset") + .help("Resets the autoproxy timeout"), command!(ap_timeout, parameter::Toggle::Off => "cfg_ap_timeout_off") .help("Disables the autoproxy timeout"), command!(ap_timeout, ("timeout", OpaqueString) => "cfg_ap_timeout_update") @@ -26,8 +27,10 @@ pub fn cmds() -> impl IntoIterator { let timezone_tokens = tokens!(cfg, ("timezone", ["zone", "tz"])); let timezone = [ command!(timezone_tokens => "cfg_timezone_show").help("Shows the system timezone"), - command!(timezone_tokens, RESET => "cfg_timezone_reset").help("Resets the system timezone"), + command!(timezone_tokens, RESET => "cfg_timezone_reset") + .help("Resets the system timezone"), command!(timezone_tokens, ("timezone", OpaqueString) => "cfg_timezone_update") + .flag(YES) .help("Changes your system's time zone"), ]; @@ -168,7 +171,8 @@ pub fn cmds() -> impl IntoIterator { let name_format_short = tokens!(cfg, ("nameformat", ["nf"])); let name_formatting = [ command!(name_format => "cfg_name_format_show").help("Shows the name format"), - command!(name_format, RESET => "cfg_name_format_reset").help("Resets the name format"), + command!(name_format, RESET => "cfg_name_format_reset") + .help("Resets the name format"), command!(name_format, ("format", OpaqueString) => "cfg_name_format_update") .help("Changes your system's username formatting"), command!(name_format_short => "cfg_name_format_show").help("Shows the name format"), diff --git a/crates/command_definitions/src/group.rs b/crates/command_definitions/src/group.rs index 2de9883c..449bc26e 100644 --- a/crates/command_definitions/src/group.rs +++ b/crates/command_definitions/src/group.rs @@ -21,6 +21,7 @@ pub fn cmds() -> impl Iterator { let group_new = tokens!(group, ("new", ["n"])); let group_new_cmd = once( command!(group_new, Remainder(("name", OpaqueString)) => "group_new") + .flag(YES) .help("Creates a new group"), ); @@ -37,9 +38,9 @@ pub fn cmds() -> impl Iterator { let group_name_cmd = [ command!(group_name => "group_show_name").help("Shows the group's name"), command!(group_name, CLEAR => "group_clear_name") - .flag(YES) .help("Clears the group's name"), command!(group_name, Remainder(("name", OpaqueString)) => "group_rename") + .flag(YES) .help("Renames a group"), ]; @@ -48,7 +49,6 @@ pub fn cmds() -> impl Iterator { command!(group_display_name => "group_show_display_name") .help("Shows the group's display name"), command!(group_display_name, CLEAR => "group_clear_display_name") - .flag(YES) .help("Clears the group's display name"), command!(group_display_name, Remainder(("name", OpaqueString)) => "group_change_display_name") .help("Changes the group's display name"), @@ -65,7 +65,6 @@ pub fn cmds() -> impl Iterator { command!(group_description => "group_show_description") .help("Shows the group's description"), command!(group_description, CLEAR => "group_clear_description") - .flag(YES) .help("Clears the group's description"), command!(group_description, Remainder(("description", OpaqueString)) => "group_change_description") .help("Changes the group's description"), @@ -98,7 +97,6 @@ pub fn cmds() -> impl Iterator { let group_color_cmd = [ command!(group_color => "group_show_color").help("Shows the group's color"), command!(group_color, CLEAR => "group_clear_color") - .flag(YES) .help("Clears the group's color"), command!(group_color, ("color", OpaqueString) => "group_change_color") .help("Changes a group's color"), @@ -126,7 +124,6 @@ pub fn cmds() -> impl Iterator { let group_delete_cmd = [ command!(group_target, ("delete", ["destroy", "erase", "yeet"]) => "group_delete") - .flag(YES) .help("Deletes a group"), ]; @@ -151,7 +148,7 @@ pub fn cmds() -> impl Iterator { let group_modify_members_cmd = [ command!(group_target, "add", Optional(MemberRefs) => "group_add_member") .help("Adds one or more members to a group") - .flag(ALL).flag(YES), + .flag(ALL), command!(group_target, ("remove", ["rem", "rm"]), Optional(MemberRefs) => "group_remove_member") .help("Removes one or more members from a group") .flag(ALL).flag(YES), diff --git a/crates/command_definitions/src/member.rs b/crates/command_definitions/src/member.rs index 1589e6da..69022e96 100644 --- a/crates/command_definitions/src/member.rs +++ b/crates/command_definitions/src/member.rs @@ -36,7 +36,9 @@ pub fn cmds() -> impl Iterator { let delete = ("delete", ["del", "remove"]); let member_new_cmd = once( - command!(member, new, ("name", OpaqueString) => "member_new").help("Creates a new member"), + command!(member, new, ("name", OpaqueString) => "member_new") + .flag(YES) + .help("Creates a new member"), ); let member_info_cmd = once( @@ -161,6 +163,7 @@ pub fn cmds() -> impl Iterator { command!(member_proxy => "member_proxy_show") .help("Shows a member's proxy tags"), command!(member_proxy, ("add", ["a"]), ("tag", OpaqueString) => "member_proxy_add") + .flag(YES) .help("Adds proxy tag to a member"), command!(member_proxy, ("remove", ["r", "rm"]), ("tag", OpaqueString) => "member_proxy_remove") .help("Removes proxy tag from a member"), @@ -168,6 +171,7 @@ pub fn cmds() -> impl Iterator { .flag(YES) .help("Clears all proxy tags from a member"), command!(member_proxy, Remainder(("tags", OpaqueString)) => "member_proxy_set") + .flag(YES) .help("Sets a member's proxy tags"), ] }; diff --git a/crates/command_definitions/src/random.rs b/crates/command_definitions/src/random.rs index 0c14b002..c8e6c414 100644 --- a/crates/command_definitions/src/random.rs +++ b/crates/command_definitions/src/random.rs @@ -3,7 +3,7 @@ use crate::utils::get_list_flags; use super::*; pub fn cmds() -> impl Iterator { - let random = ("random", ["rand"]); + let random = ("random", ["rand", "r"]); let group = group::group(); let member = member::member(); diff --git a/crates/command_definitions/src/switch.rs b/crates/command_definitions/src/switch.rs index ab87c6ec..c33410ea 100644 --- a/crates/command_definitions/src/switch.rs +++ b/crates/command_definitions/src/switch.rs @@ -21,14 +21,17 @@ pub fn cmds() -> impl IntoIterator { .help("Shows help for switch commands"), command!(switch, out => "switch_out").help("Registers a switch with no members"), command!(switch, delete => "switch_delete") + .flag(YES) .help("Deletes the latest switch") .flag(("all", ["clear", "c"])), command!(switch, r#move, Remainder(OpaqueString) => "switch_move") + .flag(YES) .help("Moves the latest switch in time"), // TODO: datetime parsing command!(switch, edit, out => "switch_edit_out") .help("Turns the latest switch into a switch-out") .flag(YES), command!(switch, edit, Optional(MemberRefs) => "switch_edit") + .flag(YES) .help("Edits the members in the latest switch") .flags(edit_flags), command!(switch, copy, Optional(MemberRefs) => "switch_copy") diff --git a/crates/command_definitions/src/system.rs b/crates/command_definitions/src/system.rs index 04a73c5c..5a76cfb0 100644 --- a/crates/command_definitions/src/system.rs +++ b/crates/command_definitions/src/system.rs @@ -230,15 +230,24 @@ pub fn edit() -> impl Iterator { command!(system, Optional(SystemRef), front => "system_fronter") .help("Shows a system's fronter(s)"), make_front_history(tokens!(front, ("history", ["h"]))), - make_front_history(tokens!(("fronthistory", ["fh"]))), + make_front_history(tokens!(("fronthistory", ["fh", "history", "switches"]))), make_front_percent(tokens!(front, ("percent", ["p", "%"]))), - make_front_percent(tokens!(("frontpercent", ["fp"]))), + make_front_percent(tokens!(( + "frontpercent", + ["fp", "front%", "frontbreakdown"] + ))), ]; let search_param = Optional(Remainder(("query", OpaqueString))); let apply_list_opts = |cmd: Command| cmd.flags(get_list_flags()); - let members_subcmd = tokens!(("members", ["l", "ls", "list"]), search_param); + let members_subcmd = tokens!( + ( + "members", + ["l", "ls", "list", "find", "search", "query", "fd"] + ), + search_param + ); let system_members_cmd = [ command!(system, Optional(SystemRef), members_subcmd => "system_members") .help("Lists a system's members"), @@ -265,6 +274,7 @@ pub fn edit() -> impl Iterator { let system_link = [ command!("link", ("account", UserRef) => "system_link") + .flag(YES) .help("Links another Discord account to your system"), command!("unlink", ("account", OpaqueString) => "system_unlink") .help("Unlinks a Discord account from your system") diff --git a/crates/command_parser/Cargo.toml b/crates/command_parser/Cargo.toml index 74c1a769..248a5ab2 100644 --- a/crates/command_parser/Cargo.toml +++ b/crates/command_parser/Cargo.toml @@ -8,4 +8,5 @@ lazy_static = { workspace = true } smol_str = "0.3.2" ordermap = "0.5" regex = "1" -strsim = "0.11" \ No newline at end of file +strsim = "0.11" +log = "0.4" \ No newline at end of file diff --git a/crates/command_parser/src/lib.rs b/crates/command_parser/src/lib.rs index c168248b..bf457c3d 100644 --- a/crates/command_parser/src/lib.rs +++ b/crates/command_parser/src/lib.rs @@ -18,6 +18,7 @@ use std::{collections::HashMap, usize}; use command::Command; use flag::{Flag, FlagMatchError, FlagValueMatchError}; +use log::debug; use parameter::ParameterValue; use smol_str::SmolStr; use string::MatchedFlag; @@ -82,9 +83,9 @@ pub fn parse_command( (_, Token::Parameter(_)) => std::cmp::Ordering::Less, _ => std::cmp::Ordering::Equal, }); - println!("possible: {:?}", possible_tokens); + debug!("possible: {:?}", possible_tokens); let next = next_token(possible_tokens.iter().cloned(), &input, current_pos); - println!("next: {:?}", next); + debug!("next: {:?}", next); match &next { Some((found_token, result, new_pos)) => { match &result { @@ -156,7 +157,7 @@ pub fn parse_command( .pop() .and_then(|m| matches!(m.token, Token::Parameter(_)).then_some(m)) { - println!("redoing previous branch: {:?}", state.token); + debug!("redoing previous branch: {:?}", state.token); local_tree = state.tree; current_pos = state.start_pos; // reset position to previous branch's start filtered_tokens = state.filtered_tokens; // reset filtered tokens to the previous branch's @@ -251,7 +252,7 @@ pub fn parse_command( // match flags until there are none left while let Some(matched_flag) = string::next_flag(&input, current_pos) { current_pos = matched_flag.next_pos; - println!("flag matched {matched_flag:?}"); + debug!("flag matched {matched_flag:?}"); raw_flags.push((current_token_idx, matched_flag)); } // if we have a command, stop parsing and return it (only if there is no remaining input) @@ -355,7 +356,7 @@ pub fn parse_command( flags.insert(name.to_string(), value.clone()); } - println!("{} {flags:?} {params:?}", full_cmd.cb); + debug!("{} {flags:?} {params:?}", full_cmd.cb); return Ok(ParsedCommand { command_def: full_cmd.clone(), flags, @@ -371,7 +372,7 @@ fn match_flag<'a>( ) -> Option), (&'a Flag, FlagMatchError)>> { // check for all (possible) flags, see if token matches for flag in possible_flags { - println!("matching flag {flag:?}"); + debug!("matching flag {flag:?}"); match flag.try_match(matched_flag.name, matched_flag.value) { Some(Ok(param)) => return Some(Ok((flag.get_name().into(), param))), Some(Err(err)) => return Some(Err((flag, err))), @@ -397,7 +398,7 @@ fn next_token<'a>( ) -> Option<(Token, TokenMatchResult, usize)> { // get next parameter, matching quotes let matched = string::next_param(&input, current_pos); - println!("matched: {matched:?}\n---"); + debug!("matched: {matched:?}\n---"); // iterate over tokens and run try_match for token in possible_tokens { @@ -421,7 +422,7 @@ fn next_token<'a>( }; match token.try_match(input_to_match) { Some(result) => { - //println!("matched token: {}", token); + //debug!("matched token: {}", token); return Some((token.clone(), result, next_pos)); } None => {} // continue matching until we exhaust all tokens @@ -448,7 +449,7 @@ fn rank_possible_commands( .map(move |(display, scoring, is_alias)| { let similarity = strsim::jaro_winkler(&input, &scoring); // if similarity > 0.7 { - // println!("DEBUG: ranking: '{}' vs '{}' = {}", input, scoring, similarity); + // debug!("DEBUG: ranking: '{}' vs '{}' = {}", input, scoring, similarity); // } (cmd, display, similarity, is_alias) }) diff --git a/crates/command_parser/src/string.rs b/crates/command_parser/src/string.rs index cc2dee63..2d07331e 100644 --- a/crates/command_parser/src/string.rs +++ b/crates/command_parser/src/string.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; +use log::debug; use smol_str::{SmolStr, ToSmolStr}; lazy_static::lazy_static! { @@ -79,8 +80,8 @@ pub(super) fn next_param<'a>(input: &'a str, current_pos: usize) -> Option(input: &'a str, mut current_pos: usize) -> Option 2 { // if it doesn't have one, then it is not a flag + // or if it has more dashes than 2, assume its not a flag return None; - }; - current_pos += 1; + } + + let substr_to_match = substr_without_dashes; + current_pos += dash_count; // try finding = or whitespace for (pos, char) in substr_to_match.char_indices() { - println!("flag find char {char} at {pos}"); + debug!("flag find char {char} at {pos}"); if char == '=' { let name = &substr_to_match[..pos]; - println!("flag find {name}"); + debug!("flag find {name}"); // try to get the value let Some(param) = next_param(input, current_pos + pos + 1) else { return Some(MatchedFlag { diff --git a/crates/commands/Cargo.toml b/crates/commands/Cargo.toml index 6c274a33..1d9dbebd 100644 --- a/crates/commands/Cargo.toml +++ b/crates/commands/Cargo.toml @@ -16,6 +16,8 @@ lazy_static = { workspace = true } command_parser = { path = "../command_parser"} command_definitions = { path = "../command_definitions"} uniffi = { version = "0.29" } +log = "0.4" +simple_logger = "4.3.3" [build-dependencies] uniffi = { version = "0.29", features = [ "build" ] } diff --git a/crates/commands/src/lib.rs b/crates/commands/src/lib.rs index 32869cab..a54fb3f0 100644 --- a/crates/commands/src/lib.rs +++ b/crates/commands/src/lib.rs @@ -1,4 +1,8 @@ -use std::{collections::HashMap, fmt::Write, sync::Arc}; +use std::{ + collections::HashMap, + fmt::Write, + sync::{Arc, Once}, +}; use command_parser::{parameter::ParameterValue, token::TokenMatchResult, Tree}; @@ -14,6 +18,8 @@ lazy_static::lazy_static! { }; } +static LOG_INIT: Once = Once::new(); + #[derive(Debug)] pub enum CommandResult { Ok { command: ParsedCommand }, @@ -121,6 +127,16 @@ pub struct ParsedCommand { } pub fn parse_command(prefix: String, input: String) -> CommandResult { + LOG_INIT.call_once(|| { + if let Err(err) = simple_logger::SimpleLogger::new() + .with_level(log::LevelFilter::Info) + .env() + .init() + { + eprintln!("cant initialize logger: {err}"); + } + }); + command_parser::parse_command(COMMAND_TREE.clone(), prefix, input).map_or_else( |error| CommandResult::Err { error }, |parsed| CommandResult::Ok {