mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
add missing -yes flags to command definitions, use log crate instead of printlns in command parser, also accept double dash for flags
This commit is contained in:
parent
8431255930
commit
12655fb539
16 changed files with 130 additions and 53 deletions
36
Cargo.lock
generated
36
Cargo.lock
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public partial class CommandTree
|
|||
Commands.Invite => ctx.Execute<Misc>(Invite, m => m.Invite(ctx)),
|
||||
Commands.Stats => ctx.Execute<Misc>(null, m => m.Stats(ctx)),
|
||||
Commands.MemberShow(var param, var flags) => ctx.Execute<Member>(MemberInfo, m => m.ViewMember(ctx, param.target, flags.show_embed)),
|
||||
Commands.MemberNew(var param, _) => ctx.Execute<Member>(MemberNew, m => m.NewMember(ctx, param.name)),
|
||||
Commands.MemberNew(var param, var flags) => ctx.Execute<Member>(MemberNew, m => m.NewMember(ctx, param.name, flags.yes)),
|
||||
Commands.MemberSoulscream(var param, _) => ctx.Execute<Member>(MemberInfo, m => m.Soulscream(ctx, param.target)),
|
||||
Commands.MemberAvatarShow(var param, var flags) => ctx.Execute<MemberAvatar>(MemberAvatar, m => m.ShowAvatar(ctx, param.target, flags.GetReplyFormat())),
|
||||
Commands.MemberAvatarClear(var param, var flags) => ctx.Execute<MemberAvatar>(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<MemberEdit>(MemberServerKeepProxy, m => m.ClearServerKeepProxy(ctx, param.target, flags.yes)),
|
||||
Commands.MemberProxyShow(var param, _) => ctx.Execute<MemberProxy>(MemberProxy, m => m.ShowProxy(ctx, param.target)),
|
||||
Commands.MemberProxyClear(var param, var flags) => ctx.Execute<MemberProxy>(MemberProxy, m => m.ClearProxy(ctx, param.target, flags.yes)),
|
||||
Commands.MemberProxyAdd(var param, _) => ctx.Execute<MemberProxy>(MemberProxy, m => m.AddProxy(ctx, param.target, param.tag)),
|
||||
Commands.MemberProxyAdd(var param, var flags) => ctx.Execute<MemberProxy>(MemberProxy, m => m.AddProxy(ctx, param.target, param.tag, flags.yes)),
|
||||
Commands.MemberProxyRemove(var param, _) => ctx.Execute<MemberProxy>(MemberProxy, m => m.RemoveProxy(ctx, param.target, param.tag)),
|
||||
Commands.MemberProxySet(var param, _) => ctx.Execute<MemberProxy>(MemberProxy, m => m.SetProxy(ctx, param.target, param.tags)),
|
||||
Commands.MemberProxySet(var param, var flags) => ctx.Execute<MemberProxy>(MemberProxy, m => m.SetProxy(ctx, param.target, param.tags, flags.yes)),
|
||||
Commands.MemberTtsShow(var param, _) => ctx.Execute<MemberEdit>(MemberTts, m => m.ShowTts(ctx, param.target)),
|
||||
Commands.MemberTtsUpdate(var param, _) => ctx.Execute<MemberEdit>(MemberTts, m => m.ChangeTts(ctx, param.target, param.value)),
|
||||
Commands.MemberAutoproxyShow(var param, _) => ctx.Execute<MemberEdit>(MemberAutoproxy, m => m.ShowAutoproxy(ctx, param.target)),
|
||||
|
|
@ -82,7 +82,7 @@ public partial class CommandTree
|
|||
Commands.CfgApTimeoutUpdate(var param, _) => ctx.Execute<Config>(null, m => m.EditAutoproxyTimeout(ctx, param.timeout)),
|
||||
Commands.CfgTimezoneShow => ctx.Execute<Config>(null, m => m.ViewSystemTimezone(ctx)),
|
||||
Commands.CfgTimezoneReset => ctx.Execute<Config>(null, m => m.ResetSystemTimezone(ctx)),
|
||||
Commands.CfgTimezoneUpdate(var param, _) => ctx.Execute<Config>(null, m => m.EditSystemTimezone(ctx, param.timezone)),
|
||||
Commands.CfgTimezoneUpdate(var param, var flags) => ctx.Execute<Config>(null, m => m.EditSystemTimezone(ctx, param.timezone, flags.yes)),
|
||||
Commands.CfgPingShow => ctx.Execute<Config>(null, m => m.ViewSystemPing(ctx)),
|
||||
Commands.CfgPingUpdate(var param, _) => ctx.Execute<Config>(null, m => m.EditSystemPing(ctx, param.toggle)),
|
||||
Commands.CfgMemberPrivacyShow => ctx.Execute<Config>(null, m => m.ViewMemberDefaultPrivacy(ctx)),
|
||||
|
|
@ -126,7 +126,6 @@ public partial class CommandTree
|
|||
Commands.SystemNew(var param, _) => ctx.Execute<System>(SystemNew, m => m.New(ctx, param.name)),
|
||||
Commands.SystemShowName(var param, var flags) => ctx.Execute<SystemEdit>(SystemRename, m => m.ShowName(ctx, param.target ?? ctx.System, flags.GetReplyFormat())),
|
||||
Commands.SystemRename(var param, _) => ctx.Execute<SystemEdit>(SystemRename, m => m.Rename(ctx, ctx.System, param.name)),
|
||||
Commands.SystemClearName(var param, var flags) => ctx.Execute<SystemEdit>(SystemRename, m => m.ClearName(ctx, ctx.System, flags.yes)),
|
||||
Commands.SystemShowServerName(var param, var flags) => ctx.Execute<SystemEdit>(SystemServerName, m => m.ShowServerName(ctx, param.target ?? ctx.System, flags.GetReplyFormat())),
|
||||
Commands.SystemClearServerName(var param, var flags) => ctx.Execute<SystemEdit>(SystemServerName, m => m.ClearServerName(ctx, ctx.System, flags.yes)),
|
||||
Commands.SystemRenameServerName(var param, _) => ctx.Execute<SystemEdit>(SystemServerName, m => m.RenameServerName(ctx, ctx.System, param.name)),
|
||||
|
|
@ -200,11 +199,11 @@ public partial class CommandTree
|
|||
Commands.SystemChangePrivacy(var param, _) => ctx.Execute<SystemEdit>(SystemPrivacy, m => m.ChangeSystemPrivacy(ctx, ctx.System, param.privacy, param.level)),
|
||||
Commands.SwitchOut(_, _) => ctx.Execute<Switch>(SwitchOut, m => m.SwitchOut(ctx)),
|
||||
Commands.SwitchDo(var param, _) => ctx.Execute<Switch>(Switch, m => m.SwitchDo(ctx, param.targets)),
|
||||
Commands.SwitchMove(var param, _) => ctx.Execute<Switch>(SwitchMove, m => m.SwitchMove(ctx, param.@string)),
|
||||
Commands.SwitchEdit(var param, var flags) => ctx.Execute<Switch>(SwitchEdit, m => m.SwitchEdit(ctx, param.targets, false, flags.first, flags.remove, flags.append, flags.prepend)),
|
||||
Commands.SwitchMove(var param, var flags) => ctx.Execute<Switch>(SwitchMove, m => m.SwitchMove(ctx, param.@string, flags.yes)),
|
||||
Commands.SwitchEdit(var param, var flags) => ctx.Execute<Switch>(SwitchEdit, m => m.SwitchEdit(ctx, param.targets, false, flags.first, flags.remove, flags.append, flags.prepend, flags.yes)),
|
||||
Commands.SwitchEditOut(_, var flags) => ctx.Execute<Switch>(SwitchEditOut, m => m.SwitchEditOut(ctx, flags.yes)),
|
||||
Commands.SwitchDelete(var param, var flags) => ctx.Execute<Switch>(SwitchDelete, m => m.SwitchDelete(ctx, flags.all)),
|
||||
Commands.SwitchCopy(var param, var flags) => ctx.Execute<Switch>(SwitchCopy, m => m.SwitchEdit(ctx, param.targets, true, flags.first, flags.remove, flags.append, flags.prepend)),
|
||||
Commands.SwitchDelete(var param, var flags) => ctx.Execute<Switch>(SwitchDelete, m => m.SwitchDelete(ctx, flags.all, flags.yes)),
|
||||
Commands.SwitchCopy(var param, var flags) => ctx.Execute<Switch>(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<SystemFront>(SystemFronter, m => m.Fronter(ctx, param.target ?? ctx.System)),
|
||||
Commands.SystemFronterHistory(var param, var flags) => ctx.Execute<SystemFront>(SystemFrontHistory, m => m.FrontHistory(ctx, param.target ?? ctx.System, flags.clear)),
|
||||
Commands.SystemFronterPercent(var param, var flags) => ctx.Execute<SystemFront>(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<Random>(GroupRandom, m => m.Group(ctx, param.target, flags.all, flags.show_embed)),
|
||||
Commands.GroupRandomMember(var param, var flags) => ctx.Execute<Random>(GroupMemberRandom, m => m.GroupMember(ctx, param.target, flags.all, flags.show_embed, flags)),
|
||||
Commands.SystemLink(var param, _) => ctx.Execute<SystemLink>(Link, m => m.LinkSystem(ctx, param.account)),
|
||||
Commands.SystemLink(var param, var flags) => ctx.Execute<SystemLink>(Link, m => m.LinkSystem(ctx, param.account, flags.yes)),
|
||||
Commands.SystemUnlink(var param, var flags) => ctx.Execute<SystemLink>(Unlink, m => m.UnlinkAccount(ctx, param.account, flags.yes)),
|
||||
Commands.SystemMembers(var param, var flags) => ctx.Execute<SystemList>(SystemList, m => m.MemberList(ctx, param.target ?? ctx.System, param.query, flags)),
|
||||
Commands.MemberGroups(var param, var flags) => ctx.Execute<GroupMember>(MemberGroups, m => m.ListMemberGroups(ctx, param.target, param.query, flags, flags.all)),
|
||||
Commands.GroupMembers(var param, var flags) => ctx.Execute<GroupMember>(GroupMemberList, m => m.ListGroupMembers(ctx, param.target, param.query, flags)),
|
||||
Commands.SystemGroups(var param, var flags) => ctx.Execute<Groups>(GroupList, g => g.ListSystemGroups(ctx, param.target ?? ctx.System, param.query, flags, flags.all)),
|
||||
Commands.GroupsSelf(var param, var flags) => ctx.Execute<Groups>(GroupList, g => g.ListSystemGroups(ctx, ctx.System, param.query, flags, flags.all)),
|
||||
Commands.GroupNew(var param, _) => ctx.Execute<Groups>(GroupNew, g => g.CreateGroup(ctx, param.name)),
|
||||
Commands.GroupNew(var param, var flags) => ctx.Execute<Groups>(GroupNew, g => g.CreateGroup(ctx, param.name, flags.yes)),
|
||||
Commands.GroupInfo(var param, var flags) => ctx.Execute<Groups>(GroupInfo, g => g.ShowGroupCard(ctx, param.target, flags.show_embed, flags.all)),
|
||||
Commands.GroupShowName(var param, var flags) => ctx.Execute<Groups>(GroupRename, g => g.ShowGroupDisplayName(ctx, param.target, flags.GetReplyFormat())),
|
||||
Commands.GroupClearName(var param, var flags) => ctx.Execute<Groups>(GroupRename, g => g.RenameGroup(ctx, param.target, null)),
|
||||
Commands.GroupRename(var param, _) => ctx.Execute<Groups>(GroupRename, g => g.RenameGroup(ctx, param.target, param.name)),
|
||||
Commands.GroupRename(var param, var flags) => ctx.Execute<Groups>(GroupRename, g => g.RenameGroup(ctx, param.target, param.name, flags.yes)),
|
||||
Commands.GroupShowDisplayName(var param, var flags) => ctx.Execute<Groups>(GroupDisplayName, g => g.ShowGroupDisplayName(ctx, param.target, flags.GetReplyFormat())),
|
||||
Commands.GroupClearDisplayName(var param, var flags) => ctx.Execute<Groups>(GroupDisplayName, g => g.ClearGroupDisplayName(ctx, param.target)),
|
||||
Commands.GroupChangeDisplayName(var param, _) => ctx.Execute<Groups>(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<Groups>(GroupColor, g => g.ShowGroupColor(ctx, param.target, flags.GetReplyFormat())),
|
||||
Commands.GroupClearColor(var param, var flags) => ctx.Execute<Groups>(GroupColor, g => g.ClearGroupColor(ctx, param.target)),
|
||||
Commands.GroupChangeColor(var param, _) => ctx.Execute<Groups>(GroupColor, g => g.ChangeGroupColor(ctx, param.target, param.color)),
|
||||
Commands.GroupAddMember(var param, var flags) => ctx.Execute<GroupMember>(GroupAdd, g => g.AddRemoveMembers(ctx, param.target, param.targets, Groups.AddRemoveOperation.Add, flags.all, flags.yes)),
|
||||
Commands.GroupAddMember(var param, var flags) => ctx.Execute<GroupMember>(GroupAdd, g => g.AddRemoveMembers(ctx, param.target, param.targets, Groups.AddRemoveOperation.Add, flags.all)),
|
||||
Commands.GroupRemoveMember(var param, var flags) => ctx.Execute<GroupMember>(GroupRemove, g => g.AddRemoveMembers(ctx, param.target, param.targets, Groups.AddRemoveOperation.Remove, flags.all, flags.yes)),
|
||||
Commands.GroupShowPrivacy(var param, _) => ctx.Execute<Groups>(GroupPrivacy, g => g.ShowGroupPrivacy(ctx, param.target)),
|
||||
Commands.GroupChangePrivacyAll(var param, _) => ctx.Execute<Groups>(GroupPrivacy, g => g.SetAllGroupPrivacy(ctx, param.target, param.level)),
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ public class GroupMember
|
|||
target.Color, opts, all);
|
||||
}
|
||||
|
||||
public async Task AddRemoveMembers(Context ctx, PKGroup target, List<PKMember>? _members, Groups.AddRemoveOperation op, bool all, bool confirmYes)
|
||||
public async Task AddRemoveMembers(Context ctx, PKGroup target, List<PKMember>? _members, Groups.AddRemoveOperation op, bool all, bool confirmYes = false)
|
||||
{
|
||||
ctx.CheckOwnGroup(target);
|
||||
|
||||
|
|
|
|||
|
|
@ -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.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ pub fn cmds() -> impl IntoIterator<Item = Command> {
|
|||
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<Item = Command> {
|
|||
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<Item = Command> {
|
|||
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"),
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
|||
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<Item = Command> {
|
|||
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<Item = Command> {
|
|||
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<Item = Command> {
|
|||
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<Item = Command> {
|
|||
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<Item = Command> {
|
|||
|
||||
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<Item = Command> {
|
|||
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),
|
||||
|
|
|
|||
|
|
@ -36,7 +36,9 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
|||
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<Item = Command> {
|
|||
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<Item = Command> {
|
|||
.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"),
|
||||
]
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::utils::get_list_flags;
|
|||
use super::*;
|
||||
|
||||
pub fn cmds() -> impl Iterator<Item = Command> {
|
||||
let random = ("random", ["rand"]);
|
||||
let random = ("random", ["rand", "r"]);
|
||||
let group = group::group();
|
||||
let member = member::member();
|
||||
|
||||
|
|
|
|||
|
|
@ -21,14 +21,17 @@ pub fn cmds() -> impl IntoIterator<Item = Command> {
|
|||
.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")
|
||||
|
|
|
|||
|
|
@ -230,15 +230,24 @@ pub fn edit() -> impl Iterator<Item = Command> {
|
|||
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<Item = Command> {
|
|||
|
||||
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")
|
||||
|
|
|
|||
|
|
@ -8,4 +8,5 @@ lazy_static = { workspace = true }
|
|||
smol_str = "0.3.2"
|
||||
ordermap = "0.5"
|
||||
regex = "1"
|
||||
strsim = "0.11"
|
||||
strsim = "0.11"
|
||||
log = "0.4"
|
||||
|
|
@ -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<Result<(SmolStr, Option<ParameterValue>), (&'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)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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<Match
|
|||
let leading_whitespace_count =
|
||||
input[..current_pos].len() - input[..current_pos].trim_start().len();
|
||||
let substr_to_match = &input[current_pos + leading_whitespace_count..];
|
||||
println!("stuff: {input} {current_pos} {leading_whitespace_count}");
|
||||
println!("to match: {substr_to_match}");
|
||||
debug!("stuff: {input} {current_pos} {leading_whitespace_count}");
|
||||
debug!("to match: {substr_to_match}");
|
||||
|
||||
if let Some(end_quote_pos) = find_quotes(substr_to_match) {
|
||||
// return quoted string, without quotes
|
||||
|
|
@ -132,20 +133,27 @@ pub(super) fn next_flag<'a>(input: &'a str, mut current_pos: usize) -> Option<Ma
|
|||
return None;
|
||||
}
|
||||
|
||||
println!("flag input {substr_to_match}");
|
||||
debug!("flag input {substr_to_match}");
|
||||
// strip the -
|
||||
let Some(substr_to_match) = substr_to_match.strip_prefix('-') else {
|
||||
let original_len = substr_to_match.len();
|
||||
let substr_without_dashes = substr_to_match.trim_start_matches('-');
|
||||
let dash_count = original_len - substr_without_dashes.len();
|
||||
|
||||
if dash_count == 0 || dash_count > 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 {
|
||||
|
|
|
|||
|
|
@ -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" ] }
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue