Skip to content

Commit 31da1fc

Browse files
committed
Add propertyExists() method
1 parent a3cd320 commit 31da1fc

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

src/main/kotlin/myaa/subkt/tasks/plugin.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,17 @@ fun Task.evaluate(expression: String) =
235235
fun Task.getRawMaybe(propertyName: String) =
236236
taskGroup.subs.getRawMaybe(propertyName, entry = entry)
237237

238+
/**
239+
* Returns true if the given property exists in the [Subs] object's [SubProperties] instance
240+
* for the given context.
241+
*
242+
* This function is run in a task context, using the [entry] and [release] values for this task.
243+
*
244+
* @param propertyName The property to find.
245+
*/
246+
fun Task.propertyExists(propertyName: String) =
247+
taskGroup.subs.propertyExists(propertyName, entry = entry)
248+
238249
/**
239250
* Searches for the given property in the [Subs] object's [SubProperties] instance,
240251
* and returns the raw string.
@@ -500,6 +511,20 @@ open class Subs(val project: Project) : ItemGroupContext() {
500511
fun getRawMaybe(propertyName: String, entry: String = "") =
501512
properties.match(propertyName, entry = entry, release = release.get())
502513

514+
/**
515+
* Returns true if the given property exists in the [Subs] object's [SubProperties] instance
516+
* for the given context.
517+
*
518+
* This function is run outside of a task context, using only [release] for lookup
519+
* unless an entry is manually specified.
520+
*
521+
* @sample myaa.subkt.tasks.samples.subsPropertyExistsSample
522+
* @param propertyName The property to find.
523+
* @param entry Optional manually specified entry for property lookup.
524+
*/
525+
fun propertyExists(propertyName: String, entry: String = "") =
526+
getRawMaybe(propertyName, entry = entry) != null
527+
503528
/**
504529
* Searches for the given property in the [Subs] object's [SubProperties] instance,
505530
* and returns the raw string.

src/main/kotlin/myaa/subkt/tasks/tasks.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,13 @@ class ValueClosure<T>(
497497
fun getRawMaybe(propertyName: String) =
498498
taskGroup.subs.getRawMaybe(propertyName, entry = entry)
499499

500+
501+
/**
502+
* Returns true if the given property exists. See [Task.propertyExists].
503+
*/
504+
fun propertyExists(propertyName: String) =
505+
taskGroup.subs.propertyExists(propertyName, entry = entry)
506+
500507
/**
501508
* Searches for the given property. See [Task.getRaw].
502509
*/

src/samples/kotlin/tasks.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,17 @@ fun Subs.subsEvaluateSample() {
414414
// Output: TV - $episode - $merge.out.get()
415415
}
416416

417+
fun Subs.subsPropertyExistsSample() {
418+
merge {
419+
from(get("dialogue"))
420+
421+
// only include OP if defined for the current episode
422+
if (propertyExists("op")) {
423+
from(get("op"))
424+
}
425+
}
426+
}
427+
417428
fun Subs.subsGetRawSample() {
418429
// property file: TV.*.value=hello{1..3}|test|$episode
419430
getRaw("value")

0 commit comments

Comments
 (0)