Skip to content
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

chore: made rendering of lists less noisy #1748

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/main/java/dev/jbang/cli/Alias.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ class AliasList extends BaseAliasCommand {
@CommandLine.Mixin
FormatMixin formatMixin;

private static final int INDENT_SIZE = 3;

@Override
public Integer doCall() {
PrintStream out = System.out;
Expand Down Expand Up @@ -233,7 +235,7 @@ static void printAliasesWithOrigin(PrintStream out, String catalogName, Catalog
} else {
catalogs.forEach(cat -> {
out.println(ConsoleOutput.bold(cat.resourceRef));
cat.aliases.forEach(a -> printAlias(out, a, 3));
cat.aliases.forEach(a -> printAlias(out, a, 1));
});
}
}
Expand Down Expand Up @@ -280,32 +282,31 @@ private static AliasOut getAliasOut(String catalogName, Catalog catalog, String
}

private static void printAlias(PrintStream out, AliasOut alias, int indent) {
out.print(Util.repeat(" ", indent));
String prefix = Util.repeat(" ", alias.fullName.length() + indent);
String prefix1 = Util.repeat(" ", indent * INDENT_SIZE);
String prefix2 = Util.repeat(" ", (indent + 1) * INDENT_SIZE);
String prefix3 = Util.repeat(" ", (indent + 2) * INDENT_SIZE);
out.println(prefix1 + ConsoleOutput.yellow(alias.fullName));
if (alias.description != null) {
out.println(ConsoleOutput.yellow(alias.fullName) + " = " + alias.description);
if (Util.isVerbose())
out.println(prefix + ConsoleOutput.faint(" (" + alias.scriptRef + ")"));
} else {
out.println(ConsoleOutput.yellow(alias.fullName) + " = " + alias.scriptRef);
out.println(prefix2 + alias.description);
}
out.println(prefix2 + ConsoleOutput.faint(alias.scriptRef));
if (alias.arguments != null) {
out.println(prefix + ConsoleOutput.cyan(" Arguments: ") + String.join(" ", alias.arguments));
out.println(prefix3 + ConsoleOutput.cyan(" Arguments: ") + String.join(" ", alias.arguments));
}
if (alias.javaVersion != null) {
out.println(prefix + ConsoleOutput.cyan(" Java Version: ") + alias.javaVersion);
out.println(prefix3 + ConsoleOutput.cyan(" Java Version: ") + alias.javaVersion);
}
if (alias.mainClass != null) {
out.println(prefix + ConsoleOutput.cyan(" Main Class: ") + alias.mainClass);
out.println(prefix3 + ConsoleOutput.cyan(" Main Class: ") + alias.mainClass);
}
if (alias.enablePreview != null) {
out.println(prefix + ConsoleOutput.cyan(" Enable Preview: ") + alias.enablePreview);
out.println(prefix3 + ConsoleOutput.cyan(" Enable Preview: ") + alias.enablePreview);
}
if (alias.javaOptions != null) {
out.println(prefix + ConsoleOutput.cyan(" Java Options: ") + String.join(" ", alias.javaOptions));
out.println(prefix3 + ConsoleOutput.cyan(" Java Options: ") + String.join(" ", alias.javaOptions));
}
if (alias.properties != null) {
out.println(prefix + ConsoleOutput.magenta(" Properties: ") + alias.properties);
out.println(prefix3 + ConsoleOutput.magenta(" Properties: ") + alias.properties);
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/dev/jbang/cli/Catalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ class CatalogList extends BaseCatalogCommand {
@CommandLine.Mixin
FormatMixin formatMixin;

private static final int INDENT_SIZE = 3;

@Override
public Integer doCall() {
PrintStream out = System.out;
Expand Down Expand Up @@ -237,7 +239,7 @@ static void printCatalogsWithOrigin(PrintStream out, String catalogName, dev.jba
} else {
catalogs.forEach(cat -> {
out.println(ConsoleOutput.bold(cat.resourceRef));
cat.catalogs.forEach(c -> printCatalogRef(out, c, 3));
cat.catalogs.forEach(c -> printCatalogRef(out, c, 1));
});
}
}
Expand Down Expand Up @@ -297,14 +299,13 @@ private static CatalogRefOut getCatalogRefOut(String catalogName, dev.jbang.cata
}

private static void printCatalogRef(PrintStream out, CatalogRefOut catalogRef, int indent) {
out.print(Util.repeat(" ", indent));
String prefix1 = Util.repeat(" ", indent * INDENT_SIZE);
String prefix2 = Util.repeat(" ", (indent + 1) * INDENT_SIZE);
out.println(prefix1 + ConsoleOutput.yellow(catalogRef.fullName));
if (catalogRef.description != null) {
out.println(ConsoleOutput.yellow(catalogRef.fullName) + " = " + catalogRef.description);
out.println(Util.repeat(" ", catalogRef.fullName.length() + indent) + " ("
+ catalogRef.catalogRef + ")");
} else {
out.println(ConsoleOutput.yellow(catalogRef.fullName) + " = " + catalogRef.catalogRef);
out.println(prefix2 + catalogRef.description);
}
out.println(prefix2 + catalogRef.catalogRef);
}
}

Expand Down
22 changes: 13 additions & 9 deletions src/main/java/dev/jbang/cli/Template.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ class TemplateList extends BaseTemplateCommand {
@CommandLine.Mixin
FormatMixin formatMixin;

private static final int INDENT_SIZE = 3;

@Override
public Integer doCall() {
PrintStream out = System.out;
Expand Down Expand Up @@ -351,7 +353,7 @@ static void printTemplatesWithOrigin(PrintStream out, String catalogName, Catalo
} else {
catalogs.forEach(cat -> {
out.println(ConsoleOutput.bold(cat.resourceRef));
cat.templates.forEach(t -> printTemplate(out, t, 3));
cat.templates.forEach(t -> printTemplate(out, t, 1));
});
}
}
Expand Down Expand Up @@ -403,27 +405,29 @@ private static TemplateOut getTemplateOut(String catalogName, Catalog catalog, S
}

private static void printTemplate(PrintStream out, TemplateOut template, int indent) {
String prefix1 = Util.repeat(" ", indent * INDENT_SIZE);
String prefix2 = Util.repeat(" ", (indent + 1) * INDENT_SIZE);
String prefix3 = Util.repeat(" ", (indent + 2) * INDENT_SIZE);
out.print(Util.repeat(" ", indent));
out.println(prefix1 + ConsoleOutput.yellow(template.fullName));
if (template.description != null) {
out.println(ConsoleOutput.yellow(template.fullName) + " = " + template.description);
} else {
out.println(ConsoleOutput.yellow(template.fullName) + " = ");
out.println(prefix2 + template.description);
}
if (template.fileRefs != null) {
out.println(prefix2 + "Files:");
for (FileRefOut fro : template.fileRefs) {
out.print(Util.repeat(" ", indent));
if (fro.resolved.equals(fro.destination)) {
out.println(" " + fro.resolved);
out.println(prefix3 + fro.resolved);
} else {
out.println(" " + fro.destination + " (from " + fro.resolved + ")");
out.println(prefix3 + fro.destination + " (from " + fro.resolved + ")");
}
}
}
if (template.properties != null) {
out.println(prefix2 + "Properties:");
for (Map.Entry<String, TemplateProperty> entry : template.properties.entrySet()) {
out.print(Util.repeat(" ", indent));
StringBuilder propertyLineBuilder = new StringBuilder()
.append(Util.repeat(" ", indent + 4))
.append(prefix3)
.append(ConsoleOutput.cyan(entry.getKey()))
.append(" = ");
if (entry.getValue().getDescription() != null) {
Expand Down
Loading