An advanced environment variable parsing library for Kotlin.

Overview

EnvSchema

An advanced environment variable parsing library for Kotlin.

Features

Supported features
  • Parsing of objects
  • Parsing of nested objects
  • Custom deserializers
Planned features
  • Parsing enums & lists
  • Returning and manipulating a modified clone of the object, instead of manipulating the current one

Gradle Dependency

") }">
repositories {
    maven("https://jitpack.io")
}

dependencies {
    implementation("com.github.CatDevz:EnvSchema:")
}

Example usage

Using the following schema & code as an example

import java.util.UUID

@EnvObject
data class Person(
    val uuid: UUID,
    val name: String,
    val age: Int,
    val sexuality: PersonSexuality,
    @EnvName("ETHNICITY") val race: String,
    @EnvIgnored val createdAt: String,
)

@EnvObject
data class PersonSexuality(
    val gender: String,
    val orientation: String,
)

fun main() {
    val currentPerson = Person(
        uuid = UUID.randomUUID(),
        name = "Johnny Appleseed",
        age = 24,
        sexuality = PersonSexuality(
            gender = "Male",
            orientation = "Heterosexual",
        ),
        race = "White",
        createdAt = "2022/11/23 09:27 PM",
    )
    
    // This will modify things even if they are final. The values on the object
    // passed in can be treated as their defaults.
    EnvSchema.load(currentPerson)
    
    println(currentPerson)
}

We can easily use the follow environment variables to modify the object

# We can set top level stuff easily
NAME="Jimmy"

# We can set nested objects by adding a '_' in between layers
SEXUALITY_GENDER="Female"

# We can change 'race' by using it's explicitly specified 'EnvName'
ETHNICITY="Asian"

# We can't change 'createdAt' no matter how hard we try
CREATED_AT="this won't work ;("

# More than just strings can be deserialized
UUID=61b19ab9-7df1-49e2-9d60-379db04f5c4f

License

This project is open source under the MIT license.

You might also like...
FlowExt is a Kotlin Multiplatform library, that provides many operators and extensions to Kotlin Coroutines Flow

FlowExt | Kotlinx Coroutines Flow Extensions | Kotlinx Coroutines Flow Extensions. Extensions to the Kotlin Flow library | kotlin-flow-extensions | Coroutines Flow Extensions | Kotlin Flow extensions | kotlin flow extensions | Flow extensions

Repo: Programming problems with solutions in Kotlin to help avid Kotlin learners to get a strong hold on Kotlin programming.

Kotlin_practice_problems Repo: Programming problems with solutions in Kotlin to help avid Kotlin learners to get a strong hold on Kotlin programming.

Mocking for Kotlin/Native and Kotlin Multiplatform using the Kotlin Symbol Processing API (KSP)

Mockative Mocking for Kotlin/Native and Kotlin Multiplatform using the Kotlin Symbol Processing API (KSP). Installation Mockative uses KSP to generate

Kotlin-oop - Repositório criado para ser utilizado pelo projeto de Kotlin OOP desenvolvido em Kotlin nas aulas feitas através da plataforma Alura.

Projeto React OOP Repositório criado para ser utilizado pelo projeto de Kotlin OOP desenvolvido em Kotlin nas aulas feitas através da plataforma Alura

Kotlin-koans - Kotlin Koans are a series of exercises to get you familiar with the Kotlin Syntax

kotlin-koans-edu Kotlin Koans are a series of exercises to get you familiar with

🔥The Android Startup library provides a straightforward, performant way to initialize components at the application startup. Both library developers and app developers can use Android Startup to streamline startup sequences and explicitly set the order of initialization.
🔥The Android Startup library provides a straightforward, performant way to initialize components at the application startup. Both library developers and app developers can use Android Startup to streamline startup sequences and explicitly set the order of initialization.

🔥The Android Startup library provides a straightforward, performant way to initialize components at the application startup. Both library developers and app developers can use Android Startup to streamline startup sequences and explicitly set the order of initialization.

Ksp-di-library - Small library for DI in KMM apps

DI-KSP Small library for DI in KMM apps. Uses KSP for processing DI annotations:

An library to help android developers working easly with activities and fragments (Kotlin version)
An library to help android developers working easly with activities and fragments (Kotlin version)

AFM An library to help android developer working easly with activities and fragments (Kotlin) Motivation Accelerate the process and abstract the logic

Kotlin Multiplatform String markup library
Kotlin Multiplatform String markup library

Thistle Kotlin multiplatform String markup library, inspired by SRML. Thistle is a common parser which produces an AST that can be rendered to a varie

Owner
Cody
[He/Him] 🧑‍💻 I'm a programmer, also known as a masochist. 🦀 Rust, Kotlin and TypeScript. 🐧 I use Artix btw.
Cody
Tiny library to ease the use of environment variables with support for .env files

asimov/environment Tiny library to ease the use of environment variables with support for .env files. Installation Gradle (Kotlin) repositories {

Nicolas Bottarini 1 Jan 8, 2022
Kotlin scripting environment based on TabooLib

Artifex Artifex 提供了完善的 Kotlin Script (.kts) 运行环境,且支持 TabooLib 全特性。 val compiledScript = Artifex.api().scriptCompiler().compile { // 传入源文件 it.

TABOO-PROJECT 19 Sep 11, 2022
Plugin and Desktop app for parsing layout xml into Composable code

composed-xml Inspired by - Recompose composed-xml is a tool for parsing Android layouts into Jetpack Compose code. It can work as both Desktop app or

Bacho Kurtanidze 9 Dec 26, 2022
A simple GUI frontend for the norns docker environment

This is a simple GUI frontend for the norns docker environment. It displays the virtual norns UI using the screenshot server and exposes OSC controls.

Will Winder 4 Jul 30, 2022
Android SDK development environment Docker image

AndroidSDK Android SDK development environment Docker image Goals It contains the complete Android SDK enviroment, is able to perform all regular Andr

Jing Li 1k Dec 30, 2022
AGStateMachineBuilder - a library for easy creation of state machines using advanced concepts of kotlin

This is a library for easy creation of state machines using advanced concepts of kotlin. As of 2/15/2022, this library only works in kotlin, but will be expanded to work in Java later (whenever I get bored enough to rewrite an entire code structure in java :/ )

Sanjay Mohan 1 Feb 19, 2022
Code for the Advanced Android Kotlin Testing Codelab 5.1-5.3

TO-DO Notes - Code for 5.1-5.3 Testing Codelab Code for the Advanced Android Kotlin Testing Codelab 5.1-5.3 Introduction TO-DO Notes is an app where y

Jorge M 1 Jun 7, 2022
MI Pad 2 tablet advanced boot options

LatteGO MI Pad 2 tablet advanced boot options Features Hidden target device checker Simple GUI Reboot options Shutdown Recovery Fastboot DNX Reboot Sl

null 4 Oct 26, 2022
🧮 Provides simple and advanced mathematical functions in a beautifully designed UI.

Calculator ?? Android App ?? Download the App ?? What is this App ✍️ This will basically provide simple and advanced mathematical functions in a beaut

Ayush Agnihotri 9 Jan 31, 2023
Small kotlin library for persisting _single instances_ of kotlin data classes

PerSista Small library for persisting single instances of kotlin data classes. NB: PerSista uses typeOf() internally which is marked as @ExperimentalS

Eric Donovan 5 Nov 13, 2022