Skip to content

Commit bb00a53

Browse files
prateek-whoAzyrRuthless
authored andcommitted
fix: Use more logging verbosity when updating options.json (MorpheApp#72)
1 parent a6a6baa commit bb00a53

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
@@ -490,29 +490,70 @@ internal object PatchCommand : Callable<Int> {
490490
val jsonPatchNames = patchOptionsBundle.patches.keys.map { it.lowercase() }.toSet()
491491

492492
val newPatches = compatiblePatchNames - jsonPatchNames
493+
val oldPatches = jsonPatchNames - compatiblePatchNames
493494
val removedPatches = jsonPatchNames - allMppPatchNames
494495

495-
// Check for new option keys within existing patches
496-
var patchesWithNewOptions = 0
497-
for ((patchName, snapshotEntry) in patchesSnapshot.patches) {
496+
// 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.
497+
val patchesWithNewOptions = mutableMapOf<String, Set<String>>()
498+
val patchesWithOldOptions = mutableMapOf<String, Set<String>>()
499+
500+
for ((patchName, _) in patchesSnapshot.patches) {
498501
if (patchName.lowercase() !in compatiblePatchNames) continue
499502
val jsonEntry = patchOptionsBundle.patches.entries
500503
.firstOrNull { it.key.equals(patchName, ignoreCase = true) }?.value
501504
?: continue
502-
val newOptionKeys = snapshotEntry.options.keys - jsonEntry.options.keys
503-
if (newOptionKeys.isNotEmpty()) patchesWithNewOptions++
505+
506+
// We compare from the patches list instead of the snapshot making it much better and accurate.
507+
// Snapshot keeps merging all patches with same names but different options making it a problem.
508+
val actualPatch = patches.find {
509+
it.name.equals(patchName, ignoreCase = true) &&
510+
(it.compatiblePackages == null || it.compatiblePackages!!.any {
511+
(name, _) -> name == packageName
512+
})
513+
}
514+
val actualOptionKeys = actualPatch?.options?.keys ?: emptySet()
515+
516+
// This is for new keys that are introduced in the new patch
517+
val newOptionKeys = actualOptionKeys - jsonEntry.options.keys
518+
if (newOptionKeys.isNotEmpty()) patchesWithNewOptions[patchName] = newOptionKeys
519+
520+
// This is for the old option keys that are not present in the new file
521+
val oldOptionKeys = jsonEntry.options.keys - actualOptionKeys
522+
if (oldOptionKeys.isNotEmpty()) patchesWithOldOptions[patchName] = oldOptionKeys
504523
}
505524

506-
if (newPatches.isNotEmpty() || removedPatches.isNotEmpty() || patchesWithNewOptions > 0) {
525+
if (newPatches.isNotEmpty() || oldPatches.isNotEmpty() || removedPatches.isNotEmpty() || patchesWithNewOptions.isNotEmpty() || patchesWithOldOptions.isNotEmpty()) {
507526
logger.warning("Your options file is out of date with the current patches:")
508527
if (newPatches.isNotEmpty()) {
509-
logger.warning(" ${newPatches.size} new patches not in your options file, default patch values will be applied")
528+
logger.warning(" ${newPatches.size} new patches not in your options file, default patch values will be applied. New patches are:")
529+
newPatches.forEach {
530+
logger.warning(" - $it")
531+
}
510532
}
533+
511534
if (removedPatches.isNotEmpty()) {
512535
logger.warning(" ${removedPatches.size} patches in your options file no longer exist and will be ignored")
513536
}
514-
if (patchesWithNewOptions > 0) {
515-
logger.warning(" $patchesWithNewOptions patches have new options not in your file, default patch values will be applied")
537+
538+
if (oldPatches.isNotEmpty()) {
539+
logger.warning(" ${oldPatches.size} patches in your options file are not compatible with the app:")
540+
oldPatches.forEach {
541+
logger.warning(" - $it")
542+
}
543+
}
544+
545+
if (patchesWithNewOptions.isNotEmpty()) {
546+
patchesWithNewOptions.forEach {
547+
(patch, key) ->
548+
logger.warning(" \"$patch\" has new options: ${key.joinToString(", ")}")
549+
}
550+
}
551+
552+
if (patchesWithOldOptions.isNotEmpty()) {
553+
patchesWithOldOptions.forEach {
554+
(patch, key) ->
555+
logger.warning(" \"$patch\" has old options: ${key.joinToString(", ")} that were removed.")
556+
}
516557
}
517558
logger.warning(" Use --options-update parameter to sync, or use 'options-create' command to regenerate.")
518559
}

0 commit comments

Comments
 (0)