Skip to content

Commit

Permalink
Option -y to force headless mode
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgobbo committed Jun 10, 2021
1 parent 5b939e2 commit 57833a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/main/assembly/help/Startup Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@
</tr>
<tr>
<td>-a</td>
<td>tAuto close after executing file.</td>
<td>Auto close after executing file.</td>
</tr>
<tr>
<td>-y</td>
<td>Force headless mode.</td>
</tr>
<tr>
<td>-z</td>
<td>.</td>
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/ch/psi/pshell/ui/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ static public void main(String[] args) {

static public void init(String[] args) {
arguments = args;
if (isForcedHeadless()) {
System.setProperty("java.awt.headless", "true");
}

Level consoleLogLevel = Level.WARNING;
try {
consoleLogLevel = Level.parse(getArgumentValue("clog"));
Expand Down Expand Up @@ -353,6 +357,7 @@ static String getHelpMessage() {
sb.append("\n\t-n\tInterpreter is not started");
sb.append("\n\t-q\tQuiet mode");
sb.append("\n\t-a\tAuto close after executing file");
sb.append("\n\t-y\tHeadless mode");
sb.append("\n\t-z\tHome folder is volatile (created in tmp folder)");
sb.append("\n\t-home=<path>\tSet the home folder (default is ./home)");
sb.append("\n\t-outp=<path>\tSet the output folder (default is {home})");
Expand Down Expand Up @@ -695,10 +700,18 @@ static public boolean isDisabled() {
return getBoolArgumentValue("n");
}

static public boolean isHelpMessage() {
return hasArgument("h");
}

static public boolean isHeadless() {
return GraphicsEnvironment.isHeadless();
}

static public boolean isForcedHeadless() {
return getBoolArgumentValue("y") || isHelpMessage() ;
}

//Resources
static public String getResourceBundleValue(String key) {
return getResourceBundleValue(App.class, key);
Expand Down Expand Up @@ -789,7 +802,7 @@ static public class PshellProperties extends Config {
protected void startup() {
System.out.println("Version " + getApplicationBuildInfo());

if (hasArgument("h")) {
if (isHelpMessage()) {
System.out.println(getHelpMessage());
return;
}
Expand Down

0 comments on commit 57833a0

Please sign in to comment.