package jalview.bin.argparser;
+import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import jalview.bin.argparser.Arg.Opt;
+import jalview.util.FileUtils;
/**
* Helper class to allow easy extraction of information about specific argument
ArgValues avs = this.getArgValues(a);
return avs == null ? null : avs.getId(id);
}
+
+ /*
+ * This method returns the basename of the first --open or --opennew value.
+ * Used primarily for substitutions in output filenames.
+ */
+ public String getBasename()
+ {
+ return getDirOrBasename(false);
+ }
+
+ /*
+ * This method returns the dirname of the first --open or --opennew value.
+ * Used primarily for substitutions in output filenames.
+ */
+ public String getDirname()
+ {
+ return getDirOrBasename(true);
+ }
+
+ public String getDirOrBasename(boolean dirname)
+ {
+ String filename = null;
+ String openVal = getValue(Arg.OPEN);
+ String opennewVal = getValue(Arg.OPENNEW);
+ if (openVal != null)
+ filename = openVal;
+ if (filename == null && opennewVal != null)
+ filename = opennewVal;
+ if (filename == null)
+ return null;
+
+ File file = new File(filename);
+ return dirname ? FileUtils.getDirname(file)
+ : FileUtils.getBasename(file);
+ }
}