diff --git a/README.md b/README.md index 52b0d24..4323200 100644 --- a/README.md +++ b/README.md @@ -3,16 +3,17 @@ ![main](https://github.com/uzzu/dotenv-gradle/workflows/main/badge.svg) [![ktlint](https://img.shields.io/badge/code%20style-%E2%9D%A4-FF4081.svg)](https://ktlint.github.io/) [![Gradle Plugin Portal](https://img.shields.io/maven-metadata/v/https/plugins.gradle.org/m2/co/uzzu/dotenv/gradle/co.uzzu.dotenv.gradle.gradle.plugin/maven-metadata.xml.svg?colorB=007ec6&label=gradlePluginPortal)](https://plugins.gradle.org/plugin/co.uzzu.dotenv.gradle) -**Provides a ( `.env`, `.env.template` ) variables into Project extension.** +**Provides dotenv (`.env`) and dotenv templates (`.env.template`) as variables in a Project extension.** ## How to use ### Setup -Apply this plugin to root project. This plugin is not registered to Maven Central. -[Read the Gradle Plugin Portal to setup plugin.](https://plugins.gradle.org/plugin/co.uzzu.dotenv.gradle) +Apply this plugin to the root project. [Read the Gradle Plugin Portal to setup the plugin.](https://plugins.gradle.org/plugin/co.uzzu.dotenv.gradle). -Don't need to apply this plugin to subprojects. +Note that this plugin is not registered to Maven Central. + +You do not need to apply this plugin to subprojects; the values are applied automatically. ### Create `.env` in the root directory of your gradle project @@ -23,11 +24,11 @@ FOO=foo BAR="bar" BAZ='baz' -# starting line comment out supported -; starting line comment out supported +# You can comment out lines with a # +; You can comment out lines with a ; ``` -Then, you will be able to use environment variable into your gradle scripts. +Then, you will be able to use the environment variables in your gradle scripts: ```Kotlin println(env.FOO.isPresent) // => true @@ -36,48 +37,50 @@ println(env.BAR.orNull()) // => bar println(env.BAZ.orElse("default baz")) // => baz ``` -**Don't commit `.env` file** +**Don't commit the `.env` file.** Ideally, add it to your `.gitignore` file. + +### API + +- `(Boolean) env.isPresent(name: String)`: Indicates that an environment variable with specified name is present. + +- `(String) env.fetch(name: String)`: Returns the environment variable of the given name. + +- `(String) env.fetch(name: String, defaultValue: String)`: Returns an environment variable, or specified default value if environment variable was not set. -### Create a `.env.template` file for script completion +- `(String?) env.fetchOrNull(name: String)`: Returns an environment variable, or `null` if the environment variable was not set. -If a `.env.template` file exists, this plugin refer it to create a environemnt variable properties in the `env` -extension. +- `(Map