-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #69 - use AsciiTable to print options
Signed-off-by: Sebastian Hoß <mail@shoss.de>
- Loading branch information
Showing
6 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
yosql-cli/src/main/java/de/xn__ho_hia/yosql/cli/YoSqlHelpFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package de.xn__ho_hia.yosql.cli; | ||
|
||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
import de.vandermeer.asciitable.AsciiTable; | ||
import de.vandermeer.asciitable.CWC_LongestWordMin; | ||
import de.vandermeer.asciithemes.TA_GridThemes; | ||
import de.vandermeer.skb.interfaces.transformers.textformat.TextAlignment; | ||
import joptsimple.HelpFormatter; | ||
import joptsimple.OptionDescriptor; | ||
|
||
class YoSqlHelpFormatter implements HelpFormatter { | ||
|
||
@Override | ||
@SuppressWarnings("nls") | ||
public String format(final Map<String, ? extends OptionDescriptor> options) { | ||
final AsciiTable at = new AsciiTable(); | ||
at.setTextAlignment(TextAlignment.JUSTIFIED_LEFT); | ||
at.getRenderer().setCWC(new CWC_LongestWordMin(new int[] { 30, 70, 20 })); | ||
at.getContext().setGridTheme(TA_GridThemes.FULL); | ||
|
||
at.addRule(); | ||
at.addRow("NAME", "DESCRIPTION", "DEFAULTS"); | ||
for (final Entry<String, ? extends OptionDescriptor> entry : options.entrySet()) { | ||
final String parameterName = entry.getKey(); | ||
if (!parameterName.contains("arguments") && !"help".equalsIgnoreCase(parameterName)) { | ||
at.addRule(); | ||
final OptionDescriptor value = entry.getValue(); | ||
at.addRow(parameterName, value.argumentDescription(), value.defaultValues().stream() | ||
.filter(Objects::nonNull) | ||
.map(Object::toString) | ||
.filter(string -> !"\u0000".equals(string)) | ||
.collect(Collectors.joining(", "))); | ||
} | ||
} | ||
at.addRule(); | ||
|
||
return at.render() + "\n"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
PROBLEM_DURING_OPTION_PARSING=Error while parsing one of the specified options!\n\n\t{0}\n\nMaybe you meant {1}? If not, here are all possible values we currently allow:\n | ||
PROBLEM_DURING_OPTION_PARSING=Error while parsing one of the specified options!\n\n\t{0}\n\nMaybe you meant {1}?\n\nHere are all possible values we currently allow:\n |