GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
refactor(domain): format command parsing errors within `ParseCommand`
Lars Berger934bda01d05f
diff --git a/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs b/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.csindex a4e98612..37472995 100644--- a/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs+++ b/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs@@ -25,15 +25,8 @@ namespace GlazeWM.Domain.UserConfigs.CommandHandlers// Parse command strings defined in keybinding config.var parsedCommands = keybindingConfig.CommandList.Select(commandString =>{- try- {- commandString = _commandParsingService.FormatCommand(commandString);- return _commandParsingService.ParseCommand(commandString);- }- catch- {- throw new FatalUserException($"Invalid command '{commandString}'.");- }+ commandString = _commandParsingService.FormatCommand(commandString);+ return _commandParsingService.ParseCommand(commandString);});// Register all keybindings for a command sequence.diff --git a/GlazeWM.Domain/UserConfigs/CommandParsingService.cs b/GlazeWM.Domain/UserConfigs/CommandParsingService.csindex ab3e408c..f0030f23 100644--- a/GlazeWM.Domain/UserConfigs/CommandParsingService.cs+++ b/GlazeWM.Domain/UserConfigs/CommandParsingService.cs@@ -26,18 +26,25 @@ namespace GlazeWM.Domain.UserConfigspublic Command ParseCommand(string commandString){- var commandParts = commandString.Split(" ");+ try+ {+ var commandParts = commandString.Split(" ");- return commandParts[0] switch+ return commandParts[0] switch+ {+ "layout" => ParseLayoutCommand(commandParts),+ "focus" => ParseFocusCommand(commandParts),+ "move" => ParseMoveCommand(commandParts),+ "resize" => ParseResizeCommand(commandParts),+ "toggle" => ParseToggleCommand(commandParts),+ "close" => new CloseFocusedWindowCommand(),+ _ => throw new ArgumentException(),+ };+ }+ catch{- "layout" => ParseLayoutCommand(commandParts),- "focus" => ParseFocusCommand(commandParts),- "move" => ParseMoveCommand(commandParts),- "resize" => ParseResizeCommand(commandParts),- "toggle" => ParseToggleCommand(commandParts),- "close" => new CloseFocusedWindowCommand(),- _ => throw new ArgumentException(),- };+ throw new FatalUserException($"Invalid command '{commandString}'.");+ }}private Command ParseLayoutCommand(string[] commandParts)