mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-11 16:20:13 +00:00
implement command root
This commit is contained in:
parent
c1ed7487d7
commit
15ffd16c01
11 changed files with 107 additions and 170 deletions
|
|
@ -1,5 +1,6 @@
|
|||
namespace commands {
|
||||
CommandResult parse_command(string prefix, string input);
|
||||
string get_related_commands(string prefix, string input);
|
||||
};
|
||||
[Enum]
|
||||
interface CommandResult {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, fmt::Write, usize};
|
||||
|
||||
use command_parser::{parameter::ParameterValue, Tree};
|
||||
use command_parser::{parameter::ParameterValue, token::TokenMatchResult, Tree};
|
||||
|
||||
uniffi::include_scaffolding!("commands");
|
||||
|
||||
|
|
@ -143,3 +143,22 @@ pub fn parse_command(prefix: String, input: String) -> CommandResult {
|
|||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn get_related_commands(prefix: String, input: String) -> String {
|
||||
let mut s = String::new();
|
||||
for command in command_definitions::all() {
|
||||
if command.tokens.first().map_or(false, |token| {
|
||||
token
|
||||
.try_match(Some(&input))
|
||||
.map_or(false, |r| matches!(r, TokenMatchResult::MatchedValue))
|
||||
}) {
|
||||
writeln!(
|
||||
&mut s,
|
||||
"- **{prefix}{command}** - *{help}*",
|
||||
help = command.help
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
s
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,16 @@ use command_parser::Tree;
|
|||
use commands::COMMAND_TREE;
|
||||
|
||||
fn main() {
|
||||
parse();
|
||||
}
|
||||
|
||||
fn related() {
|
||||
let cmd = std::env::args().nth(1).unwrap();
|
||||
let related = commands::get_related_commands("pk;".to_string(), cmd);
|
||||
println!("Related commands:\n{related}");
|
||||
}
|
||||
|
||||
fn parse() {
|
||||
let cmd = std::env::args()
|
||||
.skip(1)
|
||||
.intersperse(" ".to_string())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue