Skip to content

Commit

Permalink
feature: add annotation based config sorter
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianmakila committed Jan 18, 2024
1 parent 0301f4e commit 235add4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import space.arim.dazzleconf.ext.snakeyaml.SnakeYamlConfigurationFactory;
import space.arim.dazzleconf.ext.snakeyaml.SnakeYamlOptions;
import space.arim.dazzleconf.helper.ConfigurationHelper;
import space.arim.dazzleconf.sorter.AnnotationBasedSorter;

import java.io.IOException;
import java.io.UncheckedIOException;
Expand Down Expand Up @@ -40,7 +41,10 @@ public static <C> ConfigManager<C> create(Path configFolder, String fileName, Cl
.commentMode(CommentMode.fullComments())
.build();

ConfigurationOptions options = new ConfigurationOptions.Builder().addSerialiser(new SimpleDateFormatSerializer()).build();
ConfigurationOptions options = new ConfigurationOptions.Builder()
.addSerialiser(new SimpleDateFormatSerializer())
.sorter(new AnnotationBasedSorter())
.build();

ConfigurationFactory<C> configFactory = SnakeYamlConfigurationFactory.create(
configClass,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import space.arim.dazzleconf.annote.ConfDefault;
import space.arim.dazzleconf.annote.ConfKey;
import space.arim.dazzleconf.annote.SubSection;
import space.arim.dazzleconf.sorter.AnnotationBasedSorter;

import java.text.SimpleDateFormat;


public interface WebhookChatLoggerConfig {
@AnnotationBasedSorter.Order(0)
@ConfDefault.DefaultString("[<timestamp>] <author_name>: <message>")
@ConfComments({
"Which format logged messages will use. Supports MiniMessage.",
Expand All @@ -19,16 +21,19 @@ public interface WebhookChatLoggerConfig {
})
String messageFormat();

@AnnotationBasedSorter.Order(1)
@ConfDefault.DefaultString("HH:mm:ss")
@ConfComments({
"Format for the <timestamp> placeholder."
})
SimpleDateFormat timestampFormat();

@AnnotationBasedSorter.Order(2)
@ConfDefault.DefaultBoolean(true)
@ConfComments("Whether cancelled chat messages should be sent to the webhook.")
boolean logCancelledMessages();

@AnnotationBasedSorter.Order(3)
@SubSection
@ConfKey("discord")
@ConfComments("Configuration options for the Discord client.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import space.arim.dazzleconf.annote.ConfComments;
import space.arim.dazzleconf.annote.ConfDefault;
import space.arim.dazzleconf.sorter.AnnotationBasedSorter;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -15,14 +16,17 @@ static Map<String, String> defaultTextReplacements() {
return replacementMap;
}

@AnnotationBasedSorter.Order(0)
@ConfComments("Discord webhook's ID.")
@ConfDefault.DefaultString("")
String id();

@AnnotationBasedSorter.Order(1)
@ConfComments("Dicsord webhook's secret token.")
@ConfDefault.DefaultString("")
String token();

@AnnotationBasedSorter.Order(2)
@ConfComments({
"How often to send messages (in seconds).",
"Should be a value between 1 and 10.",
Expand All @@ -31,6 +35,7 @@ static Map<String, String> defaultTextReplacements() {
@ConfDefault.DefaultInteger(5)
int sendRate();

@AnnotationBasedSorter.Order(3)
@ConfDefault.DefaultObject("defaultTextReplacements")
Map<String, String> textReplacements();
}

0 comments on commit 235add4

Please sign in to comment.