Skip to content
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
2 changes: 1 addition & 1 deletion examples/pets-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<version.picocli>4.7.6</version.picocli>
<version.jackson>2.18.2</version.jackson>
<version.junit>5.14.1</version.junit>
<version.prettytable>1.1.0</version.prettytable>
<version.prettytable>1.2.0</version.prettytable>

<!-- Checkstyle -->
<version.plugin.checkstyle>3.6.0</version.plugin.checkstyle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
import java.util.Set;
import java.util.concurrent.Callable;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.util.DefaultIndenter;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.databind.ObjectMapper;

import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Model.CommandSpec;
Expand All @@ -25,9 +20,8 @@
import picocli.CommandLine.ParentCommand;
import picocli.CommandLine.ScopeType;
import picocli.CommandLine.Spec;
import rickwporter.prettytable.PrettyTable;
import rickwporter.prettytable.PrettyObject;
import rickwporter.prettytable.OutputFormat;
import rickwporter.prettytable.TableBuilder;

@Command(
name = "pets",
Expand Down Expand Up @@ -142,34 +136,9 @@ protected int usage(String message) {
return CommandLine.ExitCode.USAGE;
}

public String renderJson(Object body) {
DefaultIndenter indent = new DefaultIndenter(" ", "\n");
DefaultPrettyPrinter printer = new DefaultPrettyPrinter()
.withArrayIndenter(indent)
.withObjectIndenter(indent);
try {
return new ObjectMapper().writer(printer).writeValueAsString(body);
} catch (JsonProcessingException ex) {
throw new IllegalStateException("Could not render JSON", ex);
}
}

private String render(Object body) {
if (body == null) {
return "";
}
if (body instanceof String || body instanceof Number || body instanceof Boolean) {
return String.valueOf(body);
}
if (this.parent.format == OutputFormat.JSON) {
return this.renderJson(body);
}

PrettyTable table = new TableBuilder().build(this.parent.format, body);
if (table == null) {
return "";
}
return table.toString();
PrettyObject pretty = new PrettyObject();
return pretty.render(this.parent.format, body);
}

protected int show(Object body) {
Expand Down
Loading