Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
TheElectronWill committed Jun 28, 2018
1 parent 68dc15b commit 5d4f8b8
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,28 @@ It supports the following formats:
- [TOML](https://github.com/toml-lang/toml)
- [HOCON](https://github.com/typesafehub/config/blob/master/HOCON.md)

# Code examples
# How to use
- Code examples are available [here.](https://github.com/TheElectronWill/Night-Config/tree/master/examples/src/main/java)
*Note: these examples are for the last **stable** version, and may not work with the master branch.*
*Note: these examples are for the last **stable** version, and may not work with the master branch.*
- You can also read the [wiki](https://github.com/TheElectronWill/Night-Config/wiki).

## Sample
## Glimpse
```java
FileConfig config = FileConfig.builder("myConfig.toml").defaultResource("defaultConfig.toml").autosave().build();
config.load();
// Nice builder, default resource, autosave and much more (-> cf the wiki)
CommentedFileConfig config = FileConfig.builder("myConfig.toml").defaultResource("defaultConfig.toml").autosave().build();
config.load(); // This actually reads the config

String name = config.get("username");
int id = config.get("account.id");
int points = config.getOrElse("account.score", defaultScore);
String name = config.get("username"); // Generic return type!
int id = config.get("account.id"); // Compound path: key "id" in subconfig "account"
int points = config.getOrElse("account.score", defaultScore); // Default value

config.set("account.score", points*2);

String comment = config.getComment("user");
config.close();
// NightConfig saves the config's comments (for TOML and HOCON)

// config.save(); not needed here thanks to autosave()
config.close(); // Close the FileConfig once you're done with it :)
```


Expand Down

0 comments on commit 5d4f8b8

Please sign in to comment.