Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: --exclusive switch #78

Merged
merged 4 commits into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/kotlin/app/revanced/cli/command/MainCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ internal object MainCommand : Runnable {
@Option(names = ["-e", "--exclude"], description = ["Explicitly exclude patches"])
var excludedPatches = arrayOf<String>()

@Option(names = ["--default-exclude"], description = ["Make all patches excluded by default"])
bogadana marked this conversation as resolved.
Show resolved Hide resolved
var defaultExclude = false

@Option(names = ["-i", "--include"], description = ["Include patches"])
var includedPatches = arrayOf<String>()

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/app/revanced/cli/patcher/Patcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal object Patcher {
// merge files like necessary integrations
patcher.mergeFiles()
// add patches, but filter incompatible or excluded patches
patcher.addPatchesFiltered(excludePatches = args.excludedPatches.isNotEmpty())
patcher.addPatchesFiltered()
// apply patches
patcher.applyPatchesVerbose()

Expand Down
8 changes: 3 additions & 5 deletions src/main/kotlin/app/revanced/utils/patcher/Patcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import app.revanced.patcher.extensions.PatchExtensions.patchName
import app.revanced.patcher.patch.Patch
import app.revanced.patcher.util.patch.implementation.JarPatchBundle

fun Patcher.addPatchesFiltered(
excludePatches: Boolean = false
) {
fun Patcher.addPatchesFiltered() {
val packageName = this.data.packageMetadata.packageName
val packageVersion = this.data.packageMetadata.packageVersion

Expand All @@ -27,10 +25,10 @@ fun Patcher.addPatchesFiltered(

val args = MainCommand.args.pArgs!!

if (excludePatches && args.excludedPatches.contains(patchName)) {
if (args.excludedPatches.contains(patchName)) {
logger.info("$prefix: Explicitly excluded")
return@patch
} else if (!patch.include && !args.includedPatches.contains(patchName)) {
} else if ((!patch.include || args.defaultExclude) && !args.includedPatches.contains(patchName)) {
logger.info("$prefix: Explicitly excluded")
return@patch
}
Expand Down