From f3c256a1b8ff23a012e200b31ebce540055ec777 Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Mon, 15 Jan 2024 15:36:56 -0600 Subject: [PATCH 1/2] Unset "help" flag on "-p" option This should fix unexpected behavior when "-p" is used with other (potentially invalid) options. --- src/main/java/com/glencoesoftware/bioformats2raw/Converter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java b/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java index 03240ad..4cc96d5 100644 --- a/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java +++ b/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java @@ -401,7 +401,6 @@ public void setLogLevel(String level) { @Option( names = {"-p", "--progress"}, description = "Print progress bars during conversion", - help = true, defaultValue = "false" ) public void setProgressBars(boolean useProgressBars) { From 699ee76616fdfa3a6de6304967add0fb765350a2 Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Mon, 15 Jan 2024 15:38:14 -0600 Subject: [PATCH 2/2] Add explicit "--help" option --- .../bioformats2raw/Converter.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java b/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java index 4cc96d5..1e72ccc 100644 --- a/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java +++ b/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java @@ -138,6 +138,7 @@ public class Converter implements Callable { private volatile String logLevel; private volatile boolean progressBars = false; private volatile boolean printVersion = false; + private volatile boolean help = false; private volatile int maxWorkers; private volatile int maxCachedTiles; @@ -423,6 +424,21 @@ public void setPrintVersionOnly(boolean versionOnly) { printVersion = versionOnly; } + /** + * Configure whether to print help and exit without converting. + * + * @param helpOnly whether or not to print help and exit + */ + @Option( + names = "--help", + description = "Print usage information and exit", + usageHelp = true, + defaultValue = "false" + ) + public void setHelp(boolean helpOnly) { + help = helpOnly; + } + /** * Set the maximum number of workers to use for converting tiles. * Defaults to 4 or the number of detected CPUs, whichever is smaller. @@ -917,6 +933,13 @@ public boolean getPrintVersionOnly() { return printVersion; } + /** + * @return true if only usage info is displayed + */ + public boolean getHelp() { + return help; + } + /** * @return maximum number of worker threads */ @@ -1094,6 +1117,10 @@ public Integer call() throws Exception { LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); root.setLevel(Level.toLevel(logLevel)); + if (help) { + return -1; + } + if (printVersion) { String version = Optional.ofNullable( this.getClass().getPackage().getImplementationVersion()