Skip to content

Commit

Permalink
Command 'slurp --format=TEXT <file>' reads file lines to ArrayList
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Apr 30, 2021
1 parent 8041ffc commit 8ed2b9a
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public enum Command {SHOW
private static final String VAR_PATH = "PATH";
private static final String[] OPTION_HELP = {"-?", "--help"};
private static final String OPTION_VERBOSE = "-v";
private static final String SLURP_FORMAT_TEXT = "TEXT";
private static final String END_HELP = "END_HELP";
private static final int HELP_MAX_SIZE = 30;
private final ScriptEngine engine;
Expand Down Expand Up @@ -930,9 +931,17 @@ private Object slurpcmd(CommandInput input) {
try {
Path path = Paths.get(arg);
if (path.toFile().exists()) {
out = slurp(path, encoding, format);
if (!format.equals(SLURP_FORMAT_TEXT)) {
out = slurp(path, encoding, format);
} else {
out = Files.readAllLines(Paths.get(arg), encoding);
}
} else {
out = engine.deserialize(arg, format);
if (!format.equals(SLURP_FORMAT_TEXT)) {
out = engine.deserialize(arg, format);
} else {
out = arg.split("\n");
}
}
} catch (Exception e) {
out = engine.deserialize(arg, format);
Expand Down Expand Up @@ -1147,7 +1156,9 @@ private List<Completer> slurpCompleter(String command) {
List<OptDesc> optDescs = commandOptions("slurp");
for (OptDesc o : optDescs) {
if (o.shortOption() != null && o.shortOption().equals("-f")) {
o.setValueCompleter(new StringsCompleter(engine.getDeserializationFormats()));
List<String> formats = new ArrayList<>(engine.getDeserializationFormats());
formats.add(SLURP_FORMAT_TEXT);
o.setValueCompleter(new StringsCompleter(formats));
break;
}
}
Expand Down

0 comments on commit 8ed2b9a

Please sign in to comment.