2025-01-11 19:49:16 +09:00
|
|
|
#![feature(iter_intersperse)]
|
|
|
|
|
|
2025-01-21 12:36:54 +09:00
|
|
|
use command_parser::{token::Token, Tree};
|
|
|
|
|
use commands::COMMAND_TREE;
|
|
|
|
|
|
2025-01-08 18:31:59 +09:00
|
|
|
fn main() {
|
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-01-21 00:39:25 +09:00
|
|
|
println!("{} - {}", 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:?}");
|
|
|
|
|
if matches!(token, Token::Empty) {
|
|
|
|
|
println!(": {}", branch.command().unwrap().cb)
|
|
|
|
|
} else {
|
|
|
|
|
print_tree(branch, depth + 1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|