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
- Host: GitHub
- URL: https://github.com/avionik-world/config-kit
- Owner: avionik-world
- Created: 2024-03-17T15:26:20.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-20T18:20:15.000Z (over 2 years ago)
- Last Synced: 2024-03-20T19:53:03.665Z (over 2 years ago)
- Topics: config, json, jsonlib, yaml
- Language: Kotlin
- Homepage:
- Size: 73.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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.