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