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:
dawn 2026-01-26 02:22:54 +03:00
parent 8431255930
commit 12655fb539
No known key found for this signature in database
16 changed files with 130 additions and 53 deletions

View file

@ -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" ] }

View file

@ -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 {