diff --git a/docs/1_usage.md b/docs/1_usage.md index a03abaa..2bde6de 100644 --- a/docs/1_usage.md +++ b/docs/1_usage.md @@ -40,13 +40,21 @@ Learn how to ReVanced CLI. revanced-patches.jar ``` -- ### ⚙️ Supply options to patches using ReVanced CLI +- ### ⚙️ Generate options from patches using ReVanced CLI - Some patches provide options. Currently, ReVanced CLI will generate and consume an `options.json` file at the location that is specified in `-o`. If the option is not specified, the options file will be generated in the current working directory. + Some patches accept options. + +- ```bash + java -jar revanced-cli.jar options \ + --overwrite \ + --update \ + revanced-patches.jar + ``` - The options file contains all options from supplied patch bundles. + > **Note**: A default `options.json` file will be automatically generated, if it does not exist + without any need of intervention. - > **Note**: The `options.json` file will be generated at the first time you use ReVanced CLI to patch an APK file for now. This will be changed in the future. + ```bash - ### 💉 Use ReVanced CLI to patch an APK file but install without root permissions diff --git a/src/main/kotlin/app/revanced/cli/command/Main.kt b/src/main/kotlin/app/revanced/cli/command/Main.kt index d33e412..e853138 100644 --- a/src/main/kotlin/app/revanced/cli/command/Main.kt +++ b/src/main/kotlin/app/revanced/cli/command/Main.kt @@ -33,7 +33,8 @@ object CLIVersionProvider : IVersionProvider { subcommands = [ ListPatchesCommand::class, PatchCommand::class, - UninstallCommand::class + UninstallCommand::class, + OptionsCommand::class, ] ) internal object Main \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/cli/command/OptionsCommand.kt b/src/main/kotlin/app/revanced/cli/command/OptionsCommand.kt new file mode 100644 index 0000000..0d0b020 --- /dev/null +++ b/src/main/kotlin/app/revanced/cli/command/OptionsCommand.kt @@ -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 + + @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") +} \ No newline at end of file