* make sure application arguments can be accessed at anytime at runtime
This commit is contained in:
parent
208f8f1ed8
commit
5030f6926e
|
@ -68,20 +68,16 @@ import org.w3c.dom.NodeList;
|
|||
|
||||
public class Main {
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String... arguments) {
|
||||
public static void main(String[] argumentArray) {
|
||||
try {
|
||||
// parse arguments
|
||||
final ArgumentProcessor cli = new ArgumentProcessor();
|
||||
final ArgumentBean args = cli.parse(arguments);
|
||||
final ArgumentBean args = ArgumentBean.parse(argumentArray);
|
||||
|
||||
if (args.printHelp() || args.printVersion() || (!(args.runCLI() || args.clearCache() || args.clearUserData()) && isHeadless())) {
|
||||
System.out.format("%s / %s%n%n", getApplicationIdentifier(), getJavaRuntimeIdentifier());
|
||||
|
||||
if (args.printHelp() || (!args.printVersion() && isHeadless())) {
|
||||
cli.printHelp(args);
|
||||
ArgumentBean.printHelp(args);
|
||||
}
|
||||
|
||||
// just print help message or version string and then exit
|
||||
|
@ -165,6 +161,9 @@ public class Main {
|
|||
System.setProperty("application.rename.history", "false"); // don't keep history of --action test rename operations
|
||||
}
|
||||
|
||||
// make sure we can access application arguments at any time
|
||||
Settings.setApplicationArgumentArray(argumentArray);
|
||||
|
||||
// initialize analytics
|
||||
Analytics.setEnabled(System.getProperty("application.analytics") == null ? true : Boolean.parseBoolean(System.getProperty("application.analytics")));
|
||||
HistorySpooler.getInstance().setPersistentHistoryEnabled(System.getProperty("application.rename.history") == null ? true : Boolean.parseBoolean(System.getProperty("application.rename.history")));
|
||||
|
@ -190,7 +189,7 @@ public class Main {
|
|||
}
|
||||
}
|
||||
|
||||
int status = cli.process(args, new CmdlineOperations());
|
||||
int status = new ArgumentProcessor().process(args, new CmdlineOperations());
|
||||
System.exit(status);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.ResourceBundle;
|
|||
import java.util.prefs.BackingStoreException;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import net.sourceforge.filebot.cli.ArgumentBean;
|
||||
import net.sourceforge.filebot.util.ExceptionUtilities;
|
||||
import net.sourceforge.filebot.util.PreferencesList;
|
||||
import net.sourceforge.filebot.util.PreferencesMap;
|
||||
|
@ -177,4 +178,18 @@ public final class Settings {
|
|||
return joinBy(" ", name, version, headless);
|
||||
}
|
||||
|
||||
private static String[] applicationArgumentArray;
|
||||
|
||||
protected static void setApplicationArgumentArray(String[] args) {
|
||||
applicationArgumentArray = args;
|
||||
}
|
||||
|
||||
public static ArgumentBean getApplicationArguments() {
|
||||
try {
|
||||
return ArgumentBean.parse(applicationArgumentArray);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,15 +6,18 @@ import static net.sourceforge.filebot.util.FileUtilities.*;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.sourceforge.filebot.Language;
|
||||
|
||||
import org.kohsuke.args4j.Argument;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
import org.kohsuke.args4j.CmdLineParser;
|
||||
import org.kohsuke.args4j.Option;
|
||||
import org.kohsuke.args4j.spi.ExplicitBooleanOptionHandler;
|
||||
|
||||
|
@ -117,10 +120,10 @@ public class ArgumentBean {
|
|||
public boolean help = false;
|
||||
|
||||
@Option(name = "--def", usage = "Define script variables", handler = BindingsHandler.class)
|
||||
public List<Entry<String, String>> bindings;
|
||||
public Map<String, String> bindings = new LinkedHashMap<String, String>();
|
||||
|
||||
@Argument
|
||||
public List<String> arguments;
|
||||
public List<String> arguments = new ArrayList<String>();
|
||||
|
||||
public boolean runCLI() {
|
||||
return rename || getSubtitles || getMissingSubtitles || check || list || mediaInfo || extract || script != null;
|
||||
|
@ -181,7 +184,7 @@ public class ArgumentBean {
|
|||
|
||||
private final String[] array;
|
||||
|
||||
public ArgumentBean(String... array) {
|
||||
private ArgumentBean(String... array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
|
@ -189,4 +192,15 @@ public class ArgumentBean {
|
|||
return unmodifiableList(asList(array));
|
||||
}
|
||||
|
||||
public static ArgumentBean parse(String[] args) throws CmdLineException {
|
||||
ArgumentBean bean = new ArgumentBean(args);
|
||||
CmdLineParser parser = new CmdLineParser(bean);
|
||||
parser.parseArgument(args);
|
||||
return bean;
|
||||
}
|
||||
|
||||
public static void printHelp(ArgumentBean argumentBean) {
|
||||
new CmdLineParser(argumentBean).printUsage(System.out);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,22 +31,8 @@ import net.sourceforge.filebot.cli.ScriptShell.Script;
|
|||
import net.sourceforge.filebot.cli.ScriptShell.ScriptProvider;
|
||||
import net.sourceforge.filebot.web.CachedResource;
|
||||
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
import org.kohsuke.args4j.CmdLineParser;
|
||||
|
||||
public class ArgumentProcessor {
|
||||
|
||||
public void printHelp(ArgumentBean argumentBean) {
|
||||
new CmdLineParser(argumentBean).printUsage(System.out);
|
||||
}
|
||||
|
||||
public ArgumentBean parse(String[] args) throws CmdLineException {
|
||||
ArgumentBean bean = new ArgumentBean(args);
|
||||
CmdLineParser parser = new CmdLineParser(bean);
|
||||
parser.parseArgument(args);
|
||||
return bean;
|
||||
}
|
||||
|
||||
public int process(ArgumentBean args, CmdlineInterface cli) {
|
||||
Analytics.trackView(ArgumentProcessor.class, "FileBot CLI");
|
||||
CLILogger.setLevel(args.getLogLevel());
|
||||
|
|
|
@ -134,7 +134,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
|||
if (sxe > (max * 0.65) || cws > (max * 0.65)) {
|
||||
return renameSeries(files, action, conflictAction, outputDir, format, TheTVDB, query, SortOrder.forName(sortOrder), filter, locale, strict); // use default episode db
|
||||
} else {
|
||||
return renameMovie(files, action, conflictAction, outputDir, format, TMDb, query, filter, locale, strict); // use default movie db
|
||||
return renameMovie(files, action, conflictAction, outputDir, format, TheMovieDB, query, filter, locale, strict); // use default movie db
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -167,7 +167,7 @@ public class GroovyPad extends JFrame {
|
|||
DefaultScriptProvider scriptProvider = new DefaultScriptProvider(true);
|
||||
scriptProvider.setBaseScheme(new URI("fn", "%s", null));
|
||||
|
||||
return new ScriptShell(new CmdlineOperations(), new ArgumentBean(), AccessController.getContext(), scriptProvider);
|
||||
return new ScriptShell(new CmdlineOperations(), ArgumentBean.parse(new String[0]), AccessController.getContext(), scriptProvider);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue