From 8ed2b9a667b6058ebb0e6970032496025f5a663e Mon Sep 17 00:00:00 2001 From: mattirn Date: Fri, 30 Apr 2021 08:54:12 +0200 Subject: [PATCH] Command 'slurp --format=TEXT ' reads file lines to ArrayList --- .../jline/console/impl/ConsoleEngineImpl.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/console/src/main/java/org/jline/console/impl/ConsoleEngineImpl.java b/console/src/main/java/org/jline/console/impl/ConsoleEngineImpl.java index c95b8cce7..af028e095 100644 --- a/console/src/main/java/org/jline/console/impl/ConsoleEngineImpl.java +++ b/console/src/main/java/org/jline/console/impl/ConsoleEngineImpl.java @@ -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; @@ -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); @@ -1147,7 +1156,9 @@ private List slurpCompleter(String command) { List optDescs = commandOptions("slurp"); for (OptDesc o : optDescs) { if (o.shortOption() != null && o.shortOption().equals("-f")) { - o.setValueCompleter(new StringsCompleter(engine.getDeserializationFormats())); + List formats = new ArrayList<>(engine.getDeserializationFormats()); + formats.add(SLURP_FORMAT_TEXT); + o.setValueCompleter(new StringsCompleter(formats)); break; } }