Skip to content
This repository has been archived by the owner on Feb 11, 2023. It is now read-only.

Commit

Permalink
[R] Add example code
Browse files Browse the repository at this point in the history
  • Loading branch information
hykilpikonna authored Oct 4, 2018
1 parent 17aa49b commit ac99e33
Showing 1 changed file with 61 additions and 1 deletion.
62 changes: 61 additions & 1 deletion documentation/README.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<h5 align="center">
<a href="#basics">Basic Info</a>&nbsp;&nbsp;
<a href="#maven">Maven Import</a>&nbsp;&nbsp;
<a href="#development">Development</a>&nbsp;&nbsp;
<a href="#usage">Usage</a>&nbsp;&nbsp;
<a href="#license">License</a>
</h5>
<br>
Expand Down Expand Up @@ -55,3 +55,63 @@ Then you can add this library as dependency:
```

Make sure you reimport if you're using IntelliJ IDEA!

<br>

<a name="usage"></a>
Usage:
--------

#### 1. Create a HyConfig Object:

```java
// Pass in only the java.io.File object that stores the config file path.
// This will load automatically after the object is initialized.
// Read only will be enabled by default, use config.setEnableWrite(true); to enable write.
HyConfig config = new HyConfig(new File("./config.yml"));
```

#### 2. Use it:

```yml
# Example YML:
Test:
TestString: StringValue1
TestInt: 2
TestDouble: 3.5
TestStringList:
- hi
- there
```
```java
// Code to read Example YML

// Read Config
// Comment before each variable represents their value.

// "StringValue1"
String testString = config.getString("Test.TestString");

// 2
int testInt = config.getInt("Test.TestInt");

// ["hi", "there"]
List<String> testList = config.getStringList("Test.TestStringList");

// ["TestString", "TestInt", "TestDouble", "TestStringList"]
ArrayList<String> keysUnderTest = config.getKeys("Test");


// Write Config
// Set value requires enableWrite to be true, if not, calling save() won't do anything.
// All comments will be removed when saving.
config.setEnableWrite(true);
config.set("Test.TestSetString", "TestValue");
config.save();


// Enable Auto Backup
// This will take up a lot of space because it creates a new backup every time save() is called.
config.setBackupDir(new File("./backups/"));
```

0 comments on commit ac99e33

Please sign in to comment.