From 936086b734e281697c38af10431fb80ed86240c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sun, 3 Dec 2023 14:25:28 +0100 Subject: [PATCH] document the parser registry --- docs/core/index.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/core/index.md b/docs/core/index.md index 92b53bb..7a8ce4d 100644 --- a/docs/core/index.md +++ b/docs/core/index.md @@ -194,6 +194,29 @@ to be thrown. ### Parser Registry +The parser registry stores mappings between types and suppliers of parsers that produce those types. +The parser registry is primarily used in two different places: + +- When only a value type has been supplied to a command component to look up the relevant parser. +- When using annotated command methods. + +If you are creating a library or using `cloud-annotations`, it is recommended to register your parser +in the parser registry. +You can access the parser registry via `CommandManager#parserRegistry`. +The parser suppliers get access to a structure containing parser parameters. +These parameters are most often mapped to annotations, and allow for the customization of the parsers +when using `cloud-annotations`. + + +!!! example "Example parser registration" + ```java + parserRegistry.registerParserSupplier(TypeToken.get(Integer.class), options -> + new IntegerParser<>( + (int) options.get(StandardParameters.RANGE_MIN, Integer.MIN_VALUE), + (int) options.get(StandardParameters.RANGE_MAX, Integer.MAX_VALUE) + )); + ``` + ### Standard Parsers Cloud ships with parsers for all Java primitives as well as strings, enums, UUIDs and durations.