diff --git a/source/net/filebot/Main.java b/source/net/filebot/Main.java index d04ace50..97fee0b2 100644 --- a/source/net/filebot/Main.java +++ b/source/net/filebot/Main.java @@ -117,9 +117,18 @@ public class Main { System.exit(status); } - if (isHeadless()) { - log.info(String.format("%s / %s (headless)%n%n%s", getApplicationIdentifier(), getJavaRuntimeIdentifier(), args.usage())); - System.exit(1); + // CLI behaviour for console interactive usage + if (isHeadless() || System.console() != null) { + // print license to console if we have an interactive console + if (configureLicense(args)) { + System.exit(0); + } + + // exit with man page if we can't launch the GUI + if (isHeadless()) { + log.info(String.format("%s / %s (headless)%n%n%s", getApplicationIdentifier(), getJavaRuntimeIdentifier(), args.usage())); + System.exit(1); + } } // GUI mode => start user interface @@ -155,6 +164,23 @@ public class Main { } } + private static boolean configureLicense(ArgumentBean args) { + File file = args.getLicenseFile(); + + if (file == null || LICENSE != LicenseModel.PGPSignedMessage) { + return false; + } + + try { + License license = License.configure(file); + log.info(license + " has been activated."); + } catch (Throwable e) { + log.severe("License Error: " + e.getMessage()); + } + + return true; + } + private static void onStart(ArgumentBean args) throws Exception { // publish file arguments List files = args.getFiles(false); @@ -162,17 +188,8 @@ public class Main { SwingEventBus.getInstance().post(new FileTransferable(files)); } - // import license if started with license file - if (LicenseModel.PGPSignedMessage == LICENSE) { - args.getLicenseFile().ifPresent(f -> { - try { - License license = License.configure(f); - log.info(license + " has been activated."); - } catch (Throwable e) { - log.severe("License Error: " + e.getMessage()); - } - }); - } + // import license if launched with license file + configureLicense(args); // JavaFX is used for ProgressMonitor and GettingStartedDialog try { diff --git a/source/net/filebot/cli/ArgumentBean.java b/source/net/filebot/cli/ArgumentBean.java index c0c2642c..0a4493e1 100644 --- a/source/net/filebot/cli/ArgumentBean.java +++ b/source/net/filebot/cli/ArgumentBean.java @@ -351,8 +351,8 @@ public class ArgumentBean { }).orElseThrow(error("Illegal mode", mode)); } - public Optional getLicenseFile() { - return optional(license).map(File::new); + public File getLicenseFile() { + return license == null ? null : new File(license); } private final String[] args; diff --git a/source/net/filebot/cli/ArgumentProcessor.java b/source/net/filebot/cli/ArgumentProcessor.java index 8001badc..c8318423 100644 --- a/source/net/filebot/cli/ArgumentProcessor.java +++ b/source/net/filebot/cli/ArgumentProcessor.java @@ -21,17 +21,17 @@ public class ArgumentProcessor { // interactive mode enables basic selection and confirmation dialogs in the CLI CmdlineInterface cli = args.isInteractive() ? new CmdlineOperationsTextUI() : new CmdlineOperations(); + // execute simple command if (args.script == null) { - // execute command return runCommand(cli, args); - } else { - // execute user script - runScript(cli, args); - - // script finished successfully - log.finest("Done ヾ(@⌒ー⌒@)ノ"); - return 0; } + + // execute user script + runScript(cli, args); + + // script finished successfully + log.finest("Done ヾ(@⌒ー⌒@)ノ"); + return 0; } catch (Throwable e) { if (findCause(e, CmdlineException.class) != null) { log.log(Level.WARNING, findCause(e, CmdlineException.class).getMessage());