GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: add basic formatting to clap command parsing error message
Lars Berger2c14cb6e911d
diff --git a/packages/wm/src/app_command.rs b/packages/wm/src/app_command.rsindex f4c4bc74..d7a8c2fc 100644--- a/packages/wm/src/app_command.rs+++ b/packages/wm/src/app_command.rs@@ -1,6 +1,9 @@use std::{iter, path::PathBuf};-use clap::{Args, Command, CommandFactory, Parser, Subcommand};+use clap::{+ error::{KindFormatter, RichFormatter},+ Args, Command, CommandFactory, Parser, Subcommand,+};use serde::{Deserialize, Deserializer};use tracing::Level;@@ -97,11 +100,6 @@ pub enum QueryCommand {#[derive(Clone, Debug, Parser)]#[clap(rename_all = "snake_case")]-#[clap(- rename_all = "snake_case",- disable_help_flag = true,- disable_help_subcommand = true-)]pub enum InvokeCommand {Close,ChangeBorders(InvokeChangeBordersCommand),@@ -172,31 +170,11 @@ impl<'de> Deserialize<'de> for InvokeCommand {let unparsed = String::deserialize(deserializer)?;let unparsed_split = iter::once("").chain(unparsed.split_whitespace());- InvokeCommand::try_parse_from(unparsed_split).map_err(|e| {- for (kind, value) in e.context() {- println!("{:?} {:?}", kind, value);- }- serde::de::Error::custom(e)+ InvokeCommand::try_parse_from(unparsed_split).map_err(|err| {+ // Format the error message and remove the "error: " prefix.+ let err_msg = err.apply::<KindFormatter>().to_string();+ serde::de::Error::custom(err_msg.trim_start_matches("error: "))})-- // let xxx = InvokeCommand::command()- // .disable_help_flag(true)- // .disable_version_flag(true)- // .disable_help_subcommand(true)- // .try_get_matches_from(unparsed_split)- // .map_err(|e| {- // for (kind, value) in e.context() {- // println!("{:?} {:?}", kind, value);- // }- // // e.- // // e.apply()- // // e.format(cmd)- // // Err("fjdsiaofjdsao")- // serde::de::Error::custom(e)- // });-- // xxx.unwrap().- // // .map_err(serde::de::Error::custom)}}diff --git a/packages/wm/src/user_config.rs b/packages/wm/src/user_config.rsindex 29fa7013..082f3e59 100644--- a/packages/wm/src/user_config.rs+++ b/packages/wm/src/user_config.rs@@ -152,6 +152,8 @@ impl UserConfig {.await.context("Unable to read config file.")?;+ // TODO: Improve error formatting of serde_yaml errors. Something+ // similar to https://github.com/AlexanderThaller/format_serde_errorlet parsed_config = serde_yaml::from_str(&config_str)?;let (changes_tx, changes_rx) =