-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable tldr to format the output as a json #20
Conversation
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
charset = utf-8 | ||
|
||
[*.{kt,kts,gradle}] | ||
indent_style = space | ||
indent_size = 2 | ||
ij_kotlin_name_count_to_use_star_import = 2147483647 | ||
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647 | ||
ij_kotlin_packages_to_use_import_on_demand = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding it here to avoid people having to manually configure it
@@ -115,7 +85,7 @@ private fun partitionDifferences( | |||
removedVersion != null -> { | |||
mutableRemovedMap.remove(artifact) | |||
upgrades.add( | |||
VersionedDependency(artifact, "$version, (changed from $removedVersion)")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing it to store the otherVersion
in field of VersionedDependency
to decouple printing logic from business logic
@@ -133,20 +103,4 @@ private fun partitionDifferences( | |||
) | |||
} | |||
|
|||
private fun StringBuilder.writeList(title: String, list: List<VersionedDependency>, newLineBeforeTitle: Boolean = false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just moved to the printer.kt file
@@ -65,7 +65,7 @@ fun upgradeEffects(old: String, new: String, collapseKeys: List<String>): String | |||
if (index > 0) { | |||
appendLine() | |||
} | |||
append("Changing ${effects.first.artifact} to ${effects.first.version} will also change:") | |||
append("Changing ${effects.first.artifact} to ${effects.first.version}${effects.first.alternativeVersion?.let { ", (changed from $it)"}} will also change:") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is to stay backward compatible and print on the same way as before
|
||
private val old by argument("old.txt").path(mustExist = true) | ||
private val new by argument("new.txt").path(mustExist = true) | ||
|
||
override fun run() { | ||
val oldContents = old.readText() | ||
val newContents = new.readText() | ||
print(tldr(oldContents, newContents, collapse)) | ||
print(tldr(oldContents, newContents), collapse, outputType = output.toOutputType()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this print is the new print, it allows to decouple the output of tldr function and the printing logic
private fun writeJson(versionDifferences: VersionDifferences, collapse: List<String>): String = buildString { | ||
val (added, removed, upgraded) = versionDifferences | ||
append("{") | ||
writeJsonObject("new_dependencies", added, trailingComma = true) | ||
writeJsonObject("removed_dependencies", removed, trailingComma = true) | ||
writeJsonObject("upgraded_dependencies", collapseDependencies(upgraded, collapse)) | ||
append("}") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the new function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't add any third party since this json is quite simple and adding a third party dependency doesn't add much value for this use case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this!
This patch adds the capability to get the tldr output in json format.
b97a5ce
to
25929ea
Compare
This patch adds the capability to get the tldr output in json format.