This repository has been archived by the owner on Apr 15, 2024. It is now read-only.
forked from inotia00/revanced-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
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
3 changed files
with
65 additions
and
6 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
50 changes: 50 additions & 0 deletions
50
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package app.revanced.cli.command | ||
|
||
import app.revanced.patcher.PatchBundleLoader | ||
import app.revanced.utils.Options | ||
import app.revanced.utils.Options.setOptions | ||
import picocli.CommandLine | ||
import picocli.CommandLine.Help.Visibility.ALWAYS | ||
import java.io.File | ||
|
||
@CommandLine.Command( | ||
name = "options", | ||
description = ["Generate options file from patches"], | ||
) | ||
internal object OptionsCommand : Runnable { | ||
@CommandLine.Parameters( | ||
description = ["Paths to patch bundles"], | ||
arity = "1..*" | ||
) | ||
lateinit var patchBundles: Array<File> | ||
|
||
@CommandLine.Option( | ||
names = ["-p", "--path"], | ||
description = ["Path to patch options JSON file"], | ||
showDefaultValue = ALWAYS | ||
) | ||
var path: File = File("options.json") | ||
|
||
@CommandLine.Option( | ||
names = ["-o", "--overwrite"], | ||
description = ["Overwrite existing options file"], | ||
showDefaultValue = ALWAYS | ||
) | ||
var overwrite: Boolean = false | ||
|
||
@CommandLine.Option( | ||
names = ["-u", "--update"], | ||
description = ["Update existing options by adding missing and removing non-existent options"], | ||
showDefaultValue = ALWAYS | ||
) | ||
var update: Boolean = false | ||
|
||
override fun run() = if (!path.exists() || overwrite) | ||
with(PatchBundleLoader.Jar(*patchBundles)) { | ||
if (update) setOptions(path, logger) | ||
|
||
Options.serialize(this, prettyPrint = true) | ||
.let(path::writeText) | ||
} | ||
else logger.error("Options file already exists, use --override to override it") | ||
} |