33 * https://github.com/MorpheApp/morphe-cli
44 *
55 * Original hard forked code:
6- * https://github.com/revanced /revanced-cli
6+ * https://github.com/ReVanced /revanced-cli/tree/731865e167ee449be15fff3dde7a476faea0c2de
77 */
88
99package app.morphe.cli.command
1010
1111import app.morphe.patcher.patch.Package
1212import app.morphe.patcher.patch.Patch
1313import app.morphe.patcher.patch.loadPatchesFromJar
14+ import picocli.CommandLine
1415import picocli.CommandLine.Command
1516import picocli.CommandLine.Option
17+ import picocli.CommandLine.Spec
18+ import picocli.CommandLine.Model.CommandSpec
1619import picocli.CommandLine.Help.Visibility.ALWAYS
1720import java.io.File
1821import java.util.logging.Logger
@@ -28,11 +31,22 @@ internal object ListPatchesCommand : Runnable {
2831 // Patches is now flag based rather than position based
2932 @Option(
3033 names = [" --patches" ],
31- description = [" One or more paths to MPP files. " ],
34+ description = [" Path to a MPP file or a GitHub repo url such as https://github.com/MorpheApp/morphe-patches " ],
3235 arity = " 1..*" ,
3336 required = true
3437 )
35- private lateinit var patchFiles: Set <File >
38+ @Suppress(" unused" )
39+ private fun setPatchesFile (patchesFiles : Set <File >) {
40+ this .patchesFiles = checkFileExistsOrIsUrl(patchesFiles, spec)
41+ }
42+ private var patchesFiles = emptySet<File >()
43+
44+ @Option(
45+ names = [" --prerelease" ],
46+ description = [" Fetch the latest dev pre-release instead of the stable main release from the repo provided in --patches." ],
47+ showDefaultValue = ALWAYS ,
48+ )
49+ private var prerelease: Boolean = false
3650
3751 @Option(
3852 names = [" --out" ],
@@ -47,6 +61,12 @@ internal object ListPatchesCommand : Runnable {
4761 )
4862 private var withDescriptions: Boolean = true
4963
64+ @Option(
65+ names = [" -t" , " --temporary-files-path" ],
66+ description = [" Path to store temporary files." ],
67+ )
68+ private var temporaryFilesPath: File ? = null
69+
5070 @Option(
5171 names = [" -p" , " --with-packages" ],
5272 description = [" List the packages the patches are compatible with." ],
@@ -88,6 +108,9 @@ internal object ListPatchesCommand : Runnable {
88108 )
89109 private var packageName: String? = null
90110
111+ @Spec
112+ private lateinit var spec: CommandSpec
113+
91114 override fun run () {
92115 fun Package.buildString (): String {
93116 val (name, versions) = this
@@ -157,7 +180,23 @@ internal object ListPatchesCommand : Runnable {
157180 compatiblePackageName == name
158181 } ? : withUniversalPatches
159182
160- val patches = loadPatchesFromJar(patchFiles).withIndex().toList()
183+
184+ val temporaryFilesPath = temporaryFilesPath ? : File (" " ).absoluteFile.resolve(" morphe-temporary-files" )
185+
186+ try {
187+ patchesFiles = PatchFileResolver .resolve(
188+ patchesFiles,
189+ prerelease,
190+ temporaryFilesPath
191+ )
192+ } catch (e: IllegalArgumentException ) {
193+ throw CommandLine .ParameterException (
194+ spec.commandLine(),
195+ e.message ? : " Failed to resolve patch URL"
196+ )
197+ }
198+
199+ val patches = loadPatchesFromJar(patchesFiles).withIndex().toList()
161200
162201 val filtered = packageName?.let {
163202 patches.filter { (_, patch) ->
@@ -172,7 +211,7 @@ internal object ListPatchesCommand : Runnable {
172211 val finalOutput = filtered.joinToString(" \n\n " ) {it.buildString()}
173212
174213 if (filtered.isEmpty()) {
175- logger.warning(" No compatible patches found in: $patchFiles " )
214+ logger.warning(" No compatible patches found in: $patchesFiles " )
176215 } else {
177216 if (outputFile == null ) {
178217 logger.info(finalOutput)
0 commit comments