Skip to content

Commit 0c53a2d

Browse files
laur89oSumAtrIX
andauthored
fix: Group mount and install options into an argument group (#364)
Co-authored-by: oSumAtrIX <[email protected]>
1 parent a0189ae commit 0c53a2d

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

src/main/kotlin/app/revanced/cli/command/PatchCommand.kt

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,27 @@ internal object PatchCommand : Runnable {
115115
this.outputFilePath = outputFilePath?.absoluteFile
116116
}
117117

118-
@CommandLine.Option(
119-
names = ["-i", "--install"],
120-
description = ["Serial of the ADB device to install to. If not specified, the first connected device will be used."],
121-
// Empty string to indicate that the first connected device should be used.
122-
fallbackValue = "",
123-
arity = "0..1",
124-
)
125-
private var deviceSerial: String? = null
126-
127-
@CommandLine.Option(
128-
names = ["--mount"],
129-
description = ["Install the patched APK file by mounting."],
130-
showDefaultValue = ALWAYS,
131-
)
132-
private var mount: Boolean = false
118+
@ArgGroup(exclusive = false, multiplicity = "0..1")
119+
internal var installation: Installation? = null
120+
121+
internal class Installation {
122+
@CommandLine.Option(
123+
names = ["-i", "--install"],
124+
required = true,
125+
description = ["Serial of the ADB device to install to. If not specified, the first connected device will be used."],
126+
fallbackValue = "", // Empty string is used to select the first of connected devices.
127+
arity = "0..1",
128+
)
129+
internal var deviceSerial: String? = null
130+
131+
@CommandLine.Option(
132+
names = ["--mount"],
133+
required = false,
134+
description = ["Install the patched APK file by mounting."],
135+
showDefaultValue = ALWAYS,
136+
)
137+
internal var mount: Boolean = false
138+
}
133139

134140
@CommandLine.Option(
135141
names = ["--keystore"],
@@ -245,11 +251,11 @@ internal object PatchCommand : Runnable {
245251
keyStoreFilePath ?: outputFilePath.parentFile
246252
.resolve("${outputFilePath.nameWithoutExtension}.keystore")
247253

248-
val installer = if (deviceSerial != null) {
249-
val deviceSerial = deviceSerial!!.ifEmpty { null }
254+
val installer = if (installation?.deviceSerial != null) {
255+
val deviceSerial = installation?.deviceSerial!!.ifEmpty { null }
250256

251257
try {
252-
if (mount) {
258+
if (installation?.mount == true) {
253259
AdbRootInstaller(deviceSerial)
254260
} else {
255261
AdbInstaller(deviceSerial)
@@ -332,7 +338,7 @@ internal object PatchCommand : Runnable {
332338
apk.copyTo(temporaryFilesPath.resolve(apk.name), overwrite = true).apply {
333339
patcherResult.applyTo(this)
334340
}.let { patchedApkFile ->
335-
if (!mount) {
341+
if (installation?.mount != true) {
336342
ApkUtils.signApk(
337343
patchedApkFile,
338344
outputFilePath,
@@ -355,7 +361,7 @@ internal object PatchCommand : Runnable {
355361

356362
// region Install.
357363

358-
deviceSerial?.let {
364+
installation?.deviceSerial?.let {
359365
runBlocking {
360366
when (val result = installer!!.install(Installer.Apk(outputFilePath, packageName))) {
361367
RootInstallerResult.FAILURE -> logger.severe("Failed to mount the patched APK file")

0 commit comments

Comments
 (0)