Skip to content

Commit

Permalink
Add setPrintToConsole method to CommandRunner class in the `jpro-in…
Browse files Browse the repository at this point in the history
…ternal-util` module
  • Loading branch information
besidev committed Apr 5, 2024
1 parent 0f3ce73 commit 19b6e40
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
### 0.2.16-SNAPSHOT (TBD)

### Features
* Added `setPrintToConsole` method to CommandRunner class in the `jpro-internal-util` module. This method can be used
to set the print output of the command runner to the console. This is useful for debugging purposes.

----------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class CommandRunner {
private final List<String> secretArgs = new ArrayList<>();
private final StringBuffer processOutput = new StringBuffer();
private boolean interactive = false;
private boolean printToConsole = false;

/**
* Initializes CommandRunner with default logger and command line arguments.
Expand Down Expand Up @@ -52,6 +53,16 @@ public void setInteractive(boolean interactive) {
this.interactive = interactive;
}

/**
* When set to true, it will enable the process output to be
* printed to the console. By default, is false
*
* @param printToConsole a boolean that sets the print to console mode
*/
public void setPrintToConsole(boolean printToConsole) {
this.printToConsole = printToConsole;
}

/**
* Adds a command line argument to the list of existing list of
* command line arguments
Expand Down Expand Up @@ -261,6 +272,9 @@ private Thread mergeProcessOutput(final InputStream inputStream) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
reader.lines().forEach(line -> {
processOutput.append(line).append("\n");
if (printToConsole) {
System.out.println(line);
}
logger.debug(line);
});
} catch (IOException ex) {
Expand Down

0 comments on commit 19b6e40

Please sign in to comment.