This commit introduces a significant refactoring to how command arguments are parsed. The primary goal is to allow users to optionally enclose arguments containing spaces in double quotes for all commands, providing a more flexible and intuitive command input experience.
Key changes include:
1. **Centralized Argument Parsing (`src/queue/server.py`):**
* The `process_chat_command` function in `src/queue/server.py` now handles the primary parsing of command arguments.
* Incoming raw arguments (previously a list of strings split by spaces) are joined into a single string.
* This string is then processed using the regular expression `re.findall(r'"([^"]*)"|(\S+)', ...)` to accurately identify and separate arguments. This regex correctly distinguishes between:
* Substrings enclosed in double quotes (e.g., `"my poll question"`), which are treated as single arguments.
* Sequences of non-whitespace characters (e.g., `1`, `myoption`), also treated as single arguments.
* This ensures that all command handlers receive a list of arguments (`parsed_args`) where multi-word arguments (if originally quoted) are correctly preserved as single elements.
* A correction was made to the regex pattern: an initial version mistakenly used `(\\\\S+)` (matching a literal backslash then 'S') instead of the intended `(\\S+)` (matching any non-whitespace sequence) for unquoted arguments. This fix ensures that simple unquoted arguments like numbers (e.g., for the `!vote` command) are parsed correctly.
* The `re` module import was ensured.
2. **Simplification of Poll Command (`src/features/examples.py`):**
* The `cmd_start_poll` method in `src/features/examples.py` has been simplified. Its specific regex-based logic for parsing quoted poll questions and options was removed.
* This method now relies on the generalized, upstream parsing performed by `process_chat_command` in `src/queue/server.py`. It expects to receive a list of arguments that have already been correctly parsed.
* Test calls for `cmd_start_poll` within the `if __name__ == '__main__':` block were updated to align with this change, demonstrating how arguments (like poll questions and options) are now passed as a simple list of strings.
These changes collectively improve the robustness and usability of the command system by standardizing argument parsing and allowing for more complex argument values.