From d6460b777ad4fb9ba06574ef1616ce82624abb5e Mon Sep 17 00:00:00 2001 From: uzzu Date: Sun, 17 Dec 2023 23:12:04 +0900 Subject: [PATCH] Fix deprecation for example; Add example link --- examples/README.md | 1 + examples/basic/sub/build.gradle.kts | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/examples/README.md b/examples/README.md index dda342d..894ff99 100644 --- a/examples/README.md +++ b/examples/README.md @@ -2,4 +2,5 @@ - [Basic Usage](/examples/basic) - [Change `.env` filename](/examples/change_file) +- [Change `.env.template` filename](/examples/change_template_file) - [Hierarchical dotenv definitions](/examples/hierarchical_definitions) diff --git a/examples/basic/sub/build.gradle.kts b/examples/basic/sub/build.gradle.kts index 47ff8f9..a1631da 100644 --- a/examples/basic/sub/build.gradle.kts +++ b/examples/basic/sub/build.gradle.kts @@ -1,3 +1,10 @@ +val keys = listOf( + "FOO", + "BAR", + "BAZ", + "QUX" +) + println("""[$name] ${env.FOO.orElse("default_foo")}""") println("""[$name] ${env.BAR.orNull()}""") try { @@ -8,4 +15,12 @@ try { println("""[$name] ${env.QUX.value}""") // All environment variables which are merged with variables specified in .env files. -env.allVariables +print("[$name] #allVariables() (filtered by keys in .env.template and .env): ") +println(env.allVariables().filterKeys { keys.contains(it) }) + +// All environment variables which are merged with variables specified in .env files includes null. +// The Plugin set key if defined in .env template files, but it could not be retrieved as nullable value entries by using allVariables() +// By using allVariablesOrNull instead of allVariables, it is possible to retrieve all environment variables, including those that are only defined in the .env template (which means their values are null). +env.allVariablesOrNull() +print("[$name] #allVariablesOrNull() (filtered by keys in .env.template and .env): ") +println(env.allVariablesOrNull().filterKeys { keys.contains(it) })