Skip to content

Commit

Permalink
* bfconvert and showinf now exit if an unknown flag or argument is sp…
Browse files Browse the repository at this point in the history
…ecified.

* bfconvert now prompts the user if the specified output file already exists.

Closes #524.
  • Loading branch information
melissalinkert committed Aug 10, 2010
1 parent dec9c62 commit d3c26f2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
27 changes: 25 additions & 2 deletions components/bio-formats/src/loci/formats/tools/ImageConverter.java
Expand Up @@ -24,6 +24,8 @@
package loci.formats.tools;

import java.awt.image.IndexColorModel;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

import loci.common.DebugTools;
Expand Down Expand Up @@ -101,12 +103,20 @@ else if (args[i].equals("-series")) {
}
catch (NumberFormatException exc) { }
}
else LOGGER.warn("Ignoring unknown command flag: {}", args[i]);
else {
LOGGER.error("Found unknown command flag: {}; exiting.", args[i]);
return false;
}
}
else {
if (in == null) in = args[i];
else if (out == null) out = args[i];
else LOGGER.warn("Ignoring unknown argument: {}", args[i]);
else {
LOGGER.error("Found unknown argument: {}; exiting.", args[i]);
LOGGER.error("You should specify exactly one input file and " +
"exactly one output file.");
return false;
}
}
}
}
Expand Down Expand Up @@ -161,6 +171,19 @@ else if (args[i].equals("-series")) {
return false;
}

if (new Location(out).exists()) {
LOGGER.warn("Output file {} exists.", out);
LOGGER.warn("Do you want to overwrite it? ([y]/n)");
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
String choice = r.readLine().trim().toLowerCase();
boolean overwrite = !choice.startsWith("n");
if (!overwrite) {
LOGGER.warn("Exiting; next time, please specify an output file that " +
"does not exist.");
return false;
}
}

if (map != null) Location.mapId(in, map);

long start = System.currentTimeMillis();
Expand Down
18 changes: 13 additions & 5 deletions components/bio-formats/src/loci/formats/tools/ImageInfo.java
Expand Up @@ -122,7 +122,7 @@ public class ImageInfo {

// -- ImageInfo methods --

public void parseArgs(String[] args) {
public boolean parseArgs(String[] args) {
id = null;
printVersion = false;
pixels = true;
Expand Down Expand Up @@ -152,7 +152,7 @@ public void parseArgs(String[] args) {
swapOrder = null;
shuffleOrder = null;
map = null;
if (args == null) return;
if (args == null) return false;
for (int i=0; i<args.length; i++) {
if (args[i].startsWith("-")) {
if (args[i].equals("-nopix")) pixels = false;
Expand Down Expand Up @@ -205,13 +205,20 @@ else if (args[i].equals("-shuffle")) {
}
else if (args[i].equals("-map")) map = args[++i];
else if (args[i].equals("-format")) format = args[++i];
else LOGGER.warn("Ignoring unknown command flag: {}", args[i]);
else {
LOGGER.error("Found unknown command flag: {}; exiting.", args[i]);
return false;
}
}
else {
if (id == null) id = args[i];
else LOGGER.warn("Ignoring unknown argument: {}", args[i]);
else {
LOGGER.error("Found unknown argument: {}; exiting.", args[i]);
return false;
}
}
}
return true;
}

public void printUsage() {
Expand Down Expand Up @@ -879,7 +886,8 @@ public boolean testRead(String[] args)
throws FormatException, ServiceException, IOException
{
DebugTools.enableLogging("INFO");
parseArgs(args);
boolean validArgs = parseArgs(args);
if (!validArgs) return false;
if (printVersion) {
LOGGER.info("Version: {}", FormatTools.VERSION);
LOGGER.info("SVN revision: {}", FormatTools.SVN_REVISION);
Expand Down

0 comments on commit d3c26f2

Please sign in to comment.