Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
doc: add usage and api section
Browse files Browse the repository at this point in the history
  • Loading branch information
Eggflaw authored May 28, 2024
1 parent dc8f26a commit 4e32315
Showing 1 changed file with 75 additions and 3 deletions.
78 changes: 75 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,80 @@
# lune-dotenv
A simple dotenv parser for Lune
A dotenv parser for Lune

# TODO
- [ ] Basic values
lune-dotenv loads environtment variables from a `.env` file and adds them into `process.env`.
> [!WARNING]
> lune-dotenv is still in-development. Some features aren't implemented yet and there might be breaking changes to the API in the future.
* [Installtation](#installation)
* [Usage](#usage)
* [API](#api)
* [TODO](#todo)


## Installation
### Wally
Coming soon.

### Git submodules
```
git submodule add https://github.com/Eggflaw/lune-dotenv.git
```
## Usage
Create a `.env` file into the root directory of your project.
```env
OPENCLOUD_KEY=OPENCLOUDKEYHERE
SECRETS="SECRETS"
```
You can now load the `.env` file with lune-dotenv
```lua
local process = require("@lune/process")
local dotenv = require("Packages/lune-dotenv") -- Assuming you added lune-dotenv into Packages/

dotenv:load() -- Must come before accessing process.env
print(process.env.OPENCLOUD_KEY) -- Remove after you confirmed it's working

```
## API
### `dotenv:load(overwrite: boolean?, path: string?)`
Loads a `.env` file and add it into `process.env`

By default, `load` will find a `.env` file in the current working directory

If there is an environment variable with the same key name, lune-dotenv will not overwrite it.
<br>
Set `overwrite` to true to avoid this.

```lua

dotenv:load(false)
print(process.env.HOME) -- "/home/yourname"

--============--

dotenv:load(true)
print(process.env.HOME) -- "NEWHOME"

```

You can give `load` a custom path instead of finding a `.env` in the current directory
```lua
dotenv:load(false, "tests/envs/path.env")
print(process.env.CUSTOM_PATH)
```

### `dotenv:parse(str: string): { [string?]: string? }`
Parse `.env` content and convert it into a table. <br>
Use this if you don't want to load `.env` into `process.env`

```lua
local content = fs.readFile(".env")

local env = dotenv:parse(content)
print(env)
```

## TODO
- [x] Basic values
- [ ] Multiline values
- [ ] Comments
- [ ] Variable Substitution
Expand Down

0 comments on commit 4e32315

Please sign in to comment.