Skip to content

Commit

Permalink
global: Update README to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
TheElectronWill committed Apr 19, 2017
1 parent 40a7304 commit ea91668
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ NightConfig is managed with gradle. It is divided in several modules, the "core"
The project isn't available in a big repository (like Maven central) yet. You can use [jitpack](https://jitpack.io/#TheElectronWill/Night-Config) to build it from github more easily.

The repository has two branches:
- [stable-1.x](https://github.com/TheElectronWill/Night-Config/tree/stable-1.x) contains the stable version v1. Only bugfixes will occur on this branch, the API won't change.
- [master](https://github.com/TheElectronWill/Night-Config/tree/master) contains the latest in-development branch. Anything can change without notice!
- [stable-1.x](https://github.com/TheElectronWill/Night-Config/tree/stable-1.x) contains the
stable version 1. Only bugfixes will occur on this branch, the API won't break.
- [stable-2.x](https://github.com/TheElectronWill/Night-Config/tree/stable-2.x) contains the
stable version 2. Only bugfixes will occur on this branch, the API won't break.
- [master](https://github.com/TheElectronWill/Night-Config/tree/master) contains the latest
in-development branch. Anything can change without notice!

# Code examples
Read the [wiki](https://github.com/TheElectronWill/Night-Config/wiki) to learn how to use NightConfig.
Expand All @@ -27,8 +31,7 @@ Read the [wiki](https://github.com/TheElectronWill/Night-Config/wiki) to learn h

## Loading a TOML configuration from a file
```java
TomlConfig config = new TomlConfig();
config.readFrom(file);
TomlConfig config = new TomlParser().parse(file);
```

## Getting/Setting some values
Expand All @@ -44,12 +47,13 @@ config.setValue("list", list);

config.removeValue("a.b.c");
config.removeValue(Array.asList("127.0.0.1"));

config.setComment("a.b.c", "Night-Config v2 supports comments!");
```

## Saving a TOML configuration to a file
```java
config.writeTo(file);// Yes, that's it!
// And it works the same with JSON, HOCON and YAML configs.
config.write(file);// Yes, that's all!
```

## Automatically correcting a configuration, based on a specification
Expand All @@ -76,3 +80,24 @@ This will ensure that all the values respect the specification,
by replacing invalid values with the corresponding default value */
spec.correct(config);
```

## Converting configurations to plain objects
You can easily converts a config to a plain java object (and vice-versa).
For instance, if you have a class like this:
```java
class ConfigObject {
String name = "The_Name";
int id = 123_001;
Coordinates coords = new Coordinates(1, 2, 3);
}
```
With a class Coordinates:
```java
class Coordinates {
int x, y, z;
}
````
You can get an instance of ConfigObject from a config with minimum effort:
```java
ConfigObject object = new ObjectConverter().toObject(config, ConfigObject::new);
```

0 comments on commit ea91668

Please sign in to comment.