Skip to content

Commit 4d223f2

Browse files
authored
fix: Use more logging verbosity when updating options.json (#72)
1 parent c3d9a31 commit 4d223f2

1 file changed

Lines changed: 50 additions & 9 deletions

File tree

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

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -478,29 +478,70 @@ internal object PatchCommand : Callable<Int> {
478478
val jsonPatchNames = patchOptionsBundle.patches.keys.map { it.lowercase() }.toSet()
479479

480480
val newPatches = compatiblePatchNames - jsonPatchNames
481+
val oldPatches = jsonPatchNames - compatiblePatchNames
481482
val removedPatches = jsonPatchNames - allMppPatchNames
482483

483-
// Check for new option keys within existing patches
484-
var patchesWithNewOptions = 0
485-
for ((patchName, snapshotEntry) in patchesSnapshot.patches) {
484+
// Check for new option keys within existing patches. For better messaging, store it as a map and show users which patch is outdated instead of just a number.
485+
val patchesWithNewOptions = mutableMapOf<String, Set<String>>()
486+
val patchesWithOldOptions = mutableMapOf<String, Set<String>>()
487+
488+
for ((patchName, _) in patchesSnapshot.patches) {
486489
if (patchName.lowercase() !in compatiblePatchNames) continue
487490
val jsonEntry = patchOptionsBundle.patches.entries
488491
.firstOrNull { it.key.equals(patchName, ignoreCase = true) }?.value
489492
?: continue
490-
val newOptionKeys = snapshotEntry.options.keys - jsonEntry.options.keys
491-
if (newOptionKeys.isNotEmpty()) patchesWithNewOptions++
493+
494+
// We compare from the patches list instead of the snapshot making it much better and accurate.
495+
// Snapshot keeps merging all patches with same names but different options making it a problem.
496+
val actualPatch = patches.find {
497+
it.name.equals(patchName, ignoreCase = true) &&
498+
(it.compatiblePackages == null || it.compatiblePackages!!.any {
499+
(name, _) -> name == packageName
500+
})
501+
}
502+
val actualOptionKeys = actualPatch?.options?.keys ?: emptySet()
503+
504+
// This is for new keys that are introduced in the new patch
505+
val newOptionKeys = actualOptionKeys - jsonEntry.options.keys
506+
if (newOptionKeys.isNotEmpty()) patchesWithNewOptions[patchName] = newOptionKeys
507+
508+
// This is for the old option keys that are not present in the new file
509+
val oldOptionKeys = jsonEntry.options.keys - actualOptionKeys
510+
if (oldOptionKeys.isNotEmpty()) patchesWithOldOptions[patchName] = oldOptionKeys
492511
}
493512

494-
if (newPatches.isNotEmpty() || removedPatches.isNotEmpty() || patchesWithNewOptions > 0) {
513+
if (newPatches.isNotEmpty() || oldPatches.isNotEmpty() || removedPatches.isNotEmpty() || patchesWithNewOptions.isNotEmpty() || patchesWithOldOptions.isNotEmpty()) {
495514
logger.warning("Your options file is out of date with the current patches:")
496515
if (newPatches.isNotEmpty()) {
497-
logger.warning(" ${newPatches.size} new patches not in your options file, default patch values will be applied")
516+
logger.warning(" ${newPatches.size} new patches not in your options file, default patch values will be applied. New patches are:")
517+
newPatches.forEach {
518+
logger.warning(" - $it")
519+
}
498520
}
521+
499522
if (removedPatches.isNotEmpty()) {
500523
logger.warning(" ${removedPatches.size} patches in your options file no longer exist and will be ignored")
501524
}
502-
if (patchesWithNewOptions > 0) {
503-
logger.warning(" $patchesWithNewOptions patches have new options not in your file, default patch values will be applied")
525+
526+
if (oldPatches.isNotEmpty()) {
527+
logger.warning(" ${oldPatches.size} patches in your options file are not compatible with the app:")
528+
oldPatches.forEach {
529+
logger.warning(" - $it")
530+
}
531+
}
532+
533+
if (patchesWithNewOptions.isNotEmpty()) {
534+
patchesWithNewOptions.forEach {
535+
(patch, key) ->
536+
logger.warning(" \"$patch\" has new options: ${key.joinToString(", ")}")
537+
}
538+
}
539+
540+
if (patchesWithOldOptions.isNotEmpty()) {
541+
patchesWithOldOptions.forEach {
542+
(patch, key) ->
543+
logger.warning(" \"$patch\" has old options: ${key.joinToString(", ")} that were removed.")
544+
}
504545
}
505546
logger.warning(" Use --options-update parameter to sync, or use 'options-create' command to regenerate.")
506547
}

0 commit comments

Comments
 (0)