https://github.com/apurebase/arkenv
Type-safe Kotlin configuration by delegates
https://github.com/apurebase/arkenv
cli command-line configuration environment-variables kotlin
Last synced: 7 months ago
JSON representation
Type-safe Kotlin configuration by delegates
- Host: GitHub
- URL: https://github.com/apurebase/arkenv
- Owner: aPureBase
- License: apache-2.0
- Created: 2018-10-11T14:29:52.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-01-17T19:10:38.000Z (over 3 years ago)
- Last Synced: 2023-07-27T12:06:14.307Z (almost 2 years ago)
- Topics: cli, command-line, configuration, environment-variables, kotlin
- Language: Kotlin
- Homepage: https://arkenv.io/
- Size: 826 KB
- Stars: 17
- Watchers: 3
- Forks: 2
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
[](https://search.maven.org/search?q=g:%22com.apurebase%22%20AND%20a:%22arkenv%22)
[](https://github.com/aPureBase/arkenv/actions/workflows/tests.yml)
[](https://gitlab.com/apurebase/arkenv/commits/master)
[](https://kotlinlang.slack.com/messages/CGF74HD19/)
[](https://github.com/KotlinBy/awesome-kotlin)
Type-safe Kotlin configuration `by` delegates.
Supports the most common external configuration sources, including:
* [Command line](https://arkenv.io/features/command-line/)
* [Environment Variables](https://arkenv.io/features/environment-variables/)
* [Properties](https://arkenv.io/features/properties/), [Yaml](https://arkenv.io/features/yaml/), and Spring-like [profiles](https://arkenv.io/features/profiles/)
* [`.env` files](https://arkenv.io/features/dot-env-files/)### 📦 Installation
Add [Maven Central](https://search.maven.org/search?q=arkenv) to your repositories and add Arkenv in Gradle:```groovy
repositories { mavenCentral() }
implementation "com.apurebase:arkenv:$arkenv_version"
implementation "com.apurebase:arkenv-yaml:$arkenv_version" // for yaml support
```### 🔨 Usage
#### 1. Define your arguments with the `argument` delegate.
```kotlin
object Arguments {
val port: Int by argument()
}
```or use constructor injection:
```kotlin
class Arguments(val port: Int)
```#### 2. Parse your arguments.
```kotlin
fun main(args: Array) {
Arkenv.parse(Arguments, args) // object or existing instance
Arkenv.parse(args) // constructor injection
}
```You can specify additional custom names for each `argument`.
The property's name is used as a fallback.
By default, Arkenv supports parsing command line arguments,
environment variables, and profiles.In the case of `port`, you can parse it like this:
* From command line with `--port 443`
* As an environment variable `PORT=80`
* In a profile, like `application-dev.properties`, add `port=5000`
To get started, we recommend reading about [the basics](https://arkenv.io/guides/the-basics)
for a quick tour of what's included.### 📃 Documentation
Please visit [https://arkenv.io/](https://arkenv.io/) for in-depth documentation.### 🤝 Contributing [](http://makeapullrequest.com)
##### Slack
Find the Arkenv channel in the [official Kotlin Slack](https://kotlinlang.slack.com/messages/CGF74HD19/).