-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
243 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 0 additions & 62 deletions
62
src/main/kotlin/app/revanced/cli/command/OptionsCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +0,0 @@ | ||
package app.revanced.cli.command | ||
|
||
import app.revanced.library.Options | ||
import app.revanced.library.Options.setOptions | ||
import app.revanced.patcher.patch.loadPatchesFromJar | ||
import picocli.CommandLine | ||
import picocli.CommandLine.Help.Visibility.ALWAYS | ||
import java.io.File | ||
import java.util.logging.Logger | ||
|
||
@CommandLine.Command( | ||
name = "options", | ||
description = ["Generate options file from patches."], | ||
) | ||
internal object OptionsCommand : Runnable { | ||
private val logger = Logger.getLogger(OptionsCommand::class.java.name) | ||
|
||
@CommandLine.Parameters( | ||
description = ["Paths to patch bundles."], | ||
arity = "1..*", | ||
) | ||
private lateinit var patchBundles: Set<File> | ||
|
||
@CommandLine.Option( | ||
names = ["-p", "--path"], | ||
description = ["Path to patch options JSON file."], | ||
showDefaultValue = ALWAYS, | ||
) | ||
private var filePath: File = File("options.json") | ||
|
||
@CommandLine.Option( | ||
names = ["-o", "--overwrite"], | ||
description = ["Overwrite existing options file."], | ||
showDefaultValue = ALWAYS, | ||
) | ||
private var overwrite: Boolean = false | ||
|
||
@CommandLine.Option( | ||
names = ["-u", "--update"], | ||
description = ["Update existing options by adding missing and removing non-existent options."], | ||
showDefaultValue = ALWAYS, | ||
) | ||
private var update: Boolean = false | ||
|
||
override fun run() = | ||
try { | ||
loadPatchesFromJar(patchBundles).let { patches -> | ||
val exists = filePath.exists() | ||
if (!exists || overwrite) { | ||
if (exists && update) patches.setOptions(filePath) | ||
|
||
Options.serialize(patches, prettyPrint = true).let(filePath::writeText) | ||
} else { | ||
throw OptionsFileAlreadyExistsException() | ||
} | ||
} | ||
} catch (ex: OptionsFileAlreadyExistsException) { | ||
logger.severe("Options file already exists, use --overwrite to override it") | ||
} | ||
|
||
class OptionsFileAlreadyExistsException : Exception() | ||
} | ||
Oops, something went wrong.