@@ -49,6 +49,13 @@ internal object ListPatchesCommand : Runnable {
49
49
)
50
50
private var withUniversalPatches: Boolean = true
51
51
52
+ @Option(
53
+ names = [" -i" , " --index" ],
54
+ description = [" List the index of of each patch in relation to the supplied patch bundles." ],
55
+ showDefaultValue = ALWAYS
56
+ )
57
+ private var withIndex: Boolean = true
58
+
52
59
@Option(
53
60
names = [" -f" , " --filter-package-name" ], description = [" Filter patches by package name." ]
54
61
)
@@ -77,34 +84,39 @@ internal object ListPatchesCommand : Runnable {
77
84
}
78
85
}
79
86
80
- fun Patch <* >.buildString () = buildString {
81
- append(" Name: $name " )
82
-
83
- if (withDescriptions) append(" \n Description: $description " )
84
-
85
- if (withOptions && options.isNotEmpty()) {
86
- appendLine(" \n Options:" )
87
- append(
88
- options.values.joinToString(" \n\n " ) { option ->
89
- option.buildString()
90
- }.prependIndent(" \t " )
91
- )
92
- }
93
-
94
- if (withPackages && compatiblePackages != null ) {
95
- appendLine(" \n Compatible packages:" )
96
- append(
97
- compatiblePackages!! .joinToString(" \n " ) { it.buildString() }.prependIndent(" \t " )
98
- )
87
+ fun IndexedValue <Patch <* >>.buildString () = let { (index, patch) ->
88
+ buildString {
89
+ if (withIndex) appendLine(" Index: $index " )
90
+
91
+ append(" Name: ${patch.name} " )
92
+
93
+ if (withDescriptions) append(" \n Description: ${patch.description} " )
94
+
95
+ if (withOptions && patch.options.isNotEmpty()) {
96
+ appendLine(" \n Options:" )
97
+ append(
98
+ patch.options.values.joinToString(" \n\n " ) { option ->
99
+ option.buildString()
100
+ }.prependIndent(" \t " )
101
+ )
102
+ }
103
+
104
+ if (withPackages && patch.compatiblePackages != null ) {
105
+ appendLine(" \n Compatible packages:" )
106
+ append(patch.compatiblePackages!! .joinToString(" \n " ) {
107
+ it.buildString()
108
+ }.prependIndent(" \t " ))
109
+ }
99
110
}
100
111
}
101
112
102
113
fun Patch <* >.filterCompatiblePackages (name : String ) = compatiblePackages?.any { it.name == name }
103
114
? : withUniversalPatches
104
115
105
- val patches = PatchBundleLoader .Jar (* patchBundles)
116
+ val patches = PatchBundleLoader .Jar (* patchBundles).withIndex().toList()
106
117
107
- val filtered = packageName?.let { patches.filter { patch -> patch.filterCompatiblePackages(it) } } ? : patches
118
+ val filtered =
119
+ packageName?.let { patches.filter { (_, patch) -> patch.filterCompatiblePackages(it) } } ? : patches
108
120
109
121
if (filtered.isNotEmpty()) logger.info(filtered.joinToString(" \n\n " ) { it.buildString() })
110
122
}
0 commit comments