Skip to content

Latest commit

 

History

History
118 lines (87 loc) · 2.77 KB

README.md

File metadata and controls

118 lines (87 loc) · 2.77 KB
Transparent

coma

coma is an automatic config management library for Java. With coma you can automatically create and migrate config files without having to manually manage them in your project.

Installation

Maven

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

<dependency>
    <groupId>com.github.metaphoriker</groupId>
    <artifactId>coma</artifactId>
    <version>VERSION</version>
</dependency>

Gradle

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

dependencies {
    implementation 'com.github.metaphoriker:coma:VERSION'
}

Configuration

Here is a simple test configuration. The values are automatically loaded from the configuration file if it exists, otherwise the default values are used for first generation.

@Configuration(fileName = "test-config", type = ConfigurationType.YAML)
class TestConfiguration extends BaseConfiguration {

    @Key("test-string")
    @Comment("Test string configuration")
    private String testString = "defaultValue";

    @Key("test-int")
    @Comment("Test integer configuration")
    private int testInt = 123;

    @Key("test-double")
    @Comment({"Test double configuration", "Multi-line comment!"})
    private double testDouble = 123.456;

    @Key("test-long")
    @Comment("Test long configuration")
    private long testLong = 1234567890L;

    @Key("test-float")
    @Comment("Test float configuration")
    private float testFloat = 123.456f;

    @Key("test-list")
    @Comment("Test list configuration")
    private List<String> testList = List.of("item1", "item2", "item3");

    @Key("test-boolean")
    @Comment("Test boolean configuration")
    private boolean testBoolean = true;
}

After that you can initialize the configuration and use it like this:

public static void main(String[] args) {
    TestConfiguration config = new TestConfiguration();
    config.initialize(); // loads the configuration from file or creates a new one
}

Which results in this configuration file:

# Configuration File
# Generated by coma

# Test string configuration
test-string: "defaultValue"

# Test integer configuration
test-int: 123

# Test double configuration
# Multi-line comment!
test-double: 123.456

# Test long configuration
test-long: 1234567890

# Test float configuration
test-float: 100.0

# Test list configuration
test-list: ["item1","item2","item3"]

# Test boolean configuration
test-boolean: true