2025-01-11 19:49:16 +09:00
|
|
|
#![feature(iter_intersperse)]
|
|
|
|
|
|
2025-01-24 04:13:06 +09:00
|
|
|
use command_parser::Tree;
|
2025-01-21 12:36:54 +09:00
|
|
|
use commands::COMMAND_TREE;
|
|
|
|
|
|
2025-01-08 18:31:59 +09:00
|
|
|
fn main() {
|
2025-10-08 17:57:56 +00:00
|
|
|
parse();
|
2025-10-07 21:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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() {
|
2025-01-11 19:49:16 +09:00
|
|
|
let cmd = std::env::args()
|
|
|
|
|
.skip(1)
|
|
|
|
|
.intersperse(" ".to_string())
|
|
|
|
|
.collect::<String>();
|
|
|
|
|
if !cmd.is_empty() {
|
2025-01-11 22:38:29 +09:00
|
|
|
use commands::CommandResult;
|
|
|
|
|
let parsed = commands::parse_command("pk;".to_string(), cmd);
|
|
|
|
|
match parsed {
|
|
|
|
|
CommandResult::Ok { command } => println!("{command:#?}"),
|
|
|
|
|
CommandResult::Err { error } => println!("{error}"),
|
|
|
|
|
}
|
2025-01-11 19:49:16 +09:00
|
|
|
} else {
|
2025-01-21 04:31:03 +09:00
|
|
|
for command in command_definitions::all() {
|
2025-09-30 18:45:35 +00:00
|
|
|
println!("{} => {} - {}", command.cb, command, command.help);
|
2025-01-11 19:49:16 +09:00
|
|
|
}
|
2025-01-08 18:31:59 +09:00
|
|
|
}
|
|
|
|
|
}
|
2025-01-21 12:36:54 +09:00
|
|
|
|
|
|
|
|
fn print_tree(tree: &Tree, depth: usize) {
|
|
|
|
|
println!();
|
|
|
|
|
for (token, branch) in tree.branches() {
|
|
|
|
|
for _ in 0..depth {
|
|
|
|
|
print!(" ");
|
|
|
|
|
}
|
|
|
|
|
for _ in 0..depth {
|
|
|
|
|
print!("-");
|
|
|
|
|
}
|
|
|
|
|
print!("> {token:?}");
|
2025-01-24 04:13:06 +09:00
|
|
|
if let Some(command) = branch.command() {
|
|
|
|
|
println!(": {}", command.cb)
|
2025-01-21 12:36:54 +09:00
|
|
|
} else {
|
|
|
|
|
print_tree(branch, depth + 1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|