refactor: add FileOption alias for PathOption

This commit is contained in:
Sculas 2022-09-06 22:34:46 +02:00
parent 392164862c
commit bb97af4d86
No known key found for this signature in database
GPG key ID: 1530BFF96D1EEB89

View file

@ -2,6 +2,7 @@
package app.revanced.patcher.patch
import java.io.File
import java.nio.file.Path
import kotlin.reflect.KProperty
@ -195,14 +196,31 @@ sealed class PatchOption<T>(
* A [PatchOption] representing a [Path].
* @see PatchOption
*/
class PathOption<T: Path>(
sealed class PathOption(
key: String,
default: T?,
default: Path?,
title: String,
description: String,
required: Boolean = false,
validator: (T?) -> Boolean = { true }
) : PatchOption<T>(
validator: (Path?) -> Boolean = { true }
) : PatchOption<Path>(
key, default, title, description, required, validator
)
/**
* A [PathOption] of type [File].
* @see PathOption
*/
class FileOption(
key: String,
default: File?,
title: String,
description: String,
required: Boolean = false,
validator: (File?) -> Boolean = { true }
) : PathOption(
key, default?.toPath(), title, description, required, {
validator(it?.toFile())
}
)
}