An open API service indexing awesome lists of open source software.

https://github.com/avionik-world/config-kit

Create easy Config Files with json or yaml
https://github.com/avionik-world/config-kit

config json jsonlib yaml

Last synced: 11 months ago
JSON representation

Create easy Config Files with json or yaml

Awesome Lists containing this project

README

          

# ConfigKit
With this project you can easily create a config file.

## Using ConfigKit in your plugin

### Maven
```xml


world.avionik
config-kit
1.0.1
provided

```

### Gradle
```groovy
dependencies {
compileOnly 'world.avionik:config-kit:1.0.1'
}
```

## How to create a ConfigLoader
First of all, you need to decide which format you want to use. We support Json and Yaml. Then you need a class that you save in the appropriate format. Then you have to think about which format you want to use. For example, let's take this config:
```kotlin
class TestConfig(
val firstString: String,
val secondList: List
)
```
**Note:** If you want to save as a Yaml file, you have to write via the class `@Serialisable` to avoid errors.

#### And this is how you can create the ConfigLoader
```kotlin
class TestConfigLoader : ConfigLoader(
File("config.json"), // Here you can set where the file should be saved
JsonFileFormatter(TestConfig::class.java), // Here you have to adapt your format. There are JsonFileFormatter and YamlFileFormatter
{ TestConfig("123", listOf("abc", "def")) }
)
```

## How to use the ConfigLoader
Once you have successfully created a ConfigLoader, various methods are available to you. These include `configLoader.load()`, which is used to retrieve the configuration.
If you want to save a configuration, you can use the `configLoader.save(config)` method.

## How to create the MultipleConfigLoader
Everything remains the same as with the ConfigLoader, but with one exception. The class needs the nameable implantation so that the files can be selected.
```kotlin
class KitConfig(
val name: String,
val secondList: List
) : Nameable {
override fun getName(): String = this.name
}
```
**Note:** If you want to save as a Yaml file, you have to write via the class `@Serialisable` to avoid errors.

#### And this is how you can create the MultipleConfigLoader
```kotlin
class TestConfigLoader : MultipleConfigLoader(
File("config/kits"), // All files are saved in this directory
JsonFileFormatter(KitConfig::class.java) // Here you have to adapt your format. There are JsonFileFormatter and YamlFileFormatter
)
```

## How to use the MultipleConfigLoader
With `configLoader.loadAll()` you can get all configs from this directory.