Skip to content

Commit

Permalink
feat: add lines() to access stdin per line (#1244)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxandersen authored Feb 18, 2022
1 parent 9c0b0ca commit 2ccc5a1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/dev/jbang/cli/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ List<String> generateCommandLineList(Source src, RunContext ctx) throws IOExcept
"import java.math.BigDecimal;\n";
Util.writeString(tempFile.toPath(),
defaultImports + generateArgs(ctx.getArguments(), ctx.getProperties()) +
generateStdInputHelper() +
generateMain(ctx.getMainClass()));
if (ctx.getMainClass() != null) {
if (!ctx.getMainClass().contains(".")) {
Expand Down Expand Up @@ -416,6 +417,12 @@ static String generateArgs(List<String> args, Map<String, String> properties) {
return buf;
}

static String generateStdInputHelper() {
String buf = "\nStream<String> lines() { return new BufferedReader(new InputStreamReader(System.in)).lines(); }\n";
buf += "/open PRINTING\n";
return buf;
}

/**
* Helper class to peek ahead at `--debug` to pickup --debug=5000, --debug 5000,
* --debug *:5000 as debug parameters but not --debug somefile.java
Expand Down

0 comments on commit 2ccc5a1

Please sign in to comment.