mirror of
https://github.com/nasa/trick.git
synced 2025-05-30 06:04:29 +00:00
refs #257 Ignore -psn_* arguments
This commit is contained in:
parent
6f20aa4b8b
commit
68a25a74ae
@ -8,6 +8,7 @@ import java.awt.Rectangle;
|
|||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import javax.swing.AbstractAction;
|
import javax.swing.AbstractAction;
|
||||||
@ -313,7 +314,7 @@ public abstract class RunTimeTrickApplication extends TrickApplication {
|
|||||||
parseArguments(arguments, new OptionParser());
|
parseArguments(arguments, new OptionParser());
|
||||||
}
|
}
|
||||||
catch (Exception exception) {
|
catch (Exception exception) {
|
||||||
System.out.println(exception);
|
exception.printStackTrace();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,7 +336,7 @@ public abstract class RunTimeTrickApplication extends TrickApplication {
|
|||||||
* @param arguments the arguments
|
* @param arguments the arguments
|
||||||
* @param optionParser the option parser to use
|
* @param optionParser the option parser to use
|
||||||
*/
|
*/
|
||||||
protected void parseArguments(String[] arguments, OptionParser optionParser) {
|
protected OptionSet parseArguments(String[] arguments, OptionParser optionParser) {
|
||||||
OptionSpec<String> hostSpec = optionParser.accepts(hostKey, "The name of the machine to connect to.")
|
OptionSpec<String> hostSpec = optionParser.accepts(hostKey, "The name of the machine to connect to.")
|
||||||
.withRequiredArg().ofType(String.class);
|
.withRequiredArg().ofType(String.class);
|
||||||
|
|
||||||
@ -354,10 +355,12 @@ public abstract class RunTimeTrickApplication extends TrickApplication {
|
|||||||
.withRequiredArg().ofType(DisconnectBehavior.class);
|
.withRequiredArg().ofType(DisconnectBehavior.class);
|
||||||
|
|
||||||
OptionSpec<Double> minimumCyclePeriodSpec = optionParser.accepts(minimumCyclePeriodKey,
|
OptionSpec<Double> minimumCyclePeriodSpec = optionParser.accepts(minimumCyclePeriodKey,
|
||||||
"Minimum update cycle period (in seconds).").withRequiredArg().ofType(Double.class);
|
"Minimum update cycle period (in seconds).")
|
||||||
|
.withRequiredArg().ofType(Double.class);
|
||||||
|
|
||||||
OptionSpec<Double> cyclePeriodSpec = optionParser.accepts(cyclePeriodKey,
|
OptionSpec<Double> cyclePeriodSpec = optionParser.accepts(cyclePeriodKey,
|
||||||
"Update cycle period (in seconds).").withRequiredArg().ofType(Double.class);
|
"Update cycle period (in seconds).")
|
||||||
|
.withRequiredArg().ofType(Double.class);
|
||||||
|
|
||||||
OptionSpec<Integer> xSpec = optionParser.accepts(xKey, "X position of the window.")
|
OptionSpec<Integer> xSpec = optionParser.accepts(xKey, "X position of the window.")
|
||||||
.withRequiredArg().ofType(Integer.class);
|
.withRequiredArg().ofType(Integer.class);
|
||||||
@ -373,11 +376,13 @@ public abstract class RunTimeTrickApplication extends TrickApplication {
|
|||||||
|
|
||||||
optionParser.accepts("help", "Print this help message.");
|
optionParser.accepts("help", "Print this help message.");
|
||||||
|
|
||||||
OptionSet options = optionParser.parse(arguments);
|
// Mac application bundles launched via "open" are sometimes passed a "process serial number" of the form -psn_X_YYYYYYY. Ignore it.
|
||||||
|
ArrayList<String> sanitizedArguments = new ArrayList<>(Arrays.asList(arguments));
|
||||||
|
sanitizedArguments.removeIf(element -> element.startsWith("-psn_"));
|
||||||
|
OptionSet options = optionParser.parse(sanitizedArguments.toArray(new String[sanitizedArguments.size()]));
|
||||||
if (options.has("help") || !options.nonOptionArguments().isEmpty()) {
|
if (options.has("help") || !options.nonOptionArguments().isEmpty()) {
|
||||||
try {
|
try {
|
||||||
System.out.println(
|
System.out.println("Options may be abbreviated and use a single hyphen if unambiguous.");
|
||||||
"Options may be abbreviated and use a single hyphen if unambiguous.");
|
|
||||||
optionParser.printHelpOn(System.out);
|
optionParser.printHelpOn(System.out);
|
||||||
}
|
}
|
||||||
catch (IOException e) {}
|
catch (IOException e) {}
|
||||||
@ -436,6 +441,7 @@ public abstract class RunTimeTrickApplication extends TrickApplication {
|
|||||||
trickProperties.setProperty(heightKey, (options.valueOf(heightSpec).toString()));
|
trickProperties.setProperty(heightKey, (options.valueOf(heightSpec).toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -635,7 +635,7 @@ public class TVApplication extends RunTimeTrickApplication implements VariableLi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void parseArguments(String[] arguments, OptionParser optionParser) {
|
protected OptionSet parseArguments(String[] arguments, OptionParser optionParser) {
|
||||||
// Add class-specific arguments to the parser before allowing the superclass to parse.
|
// Add class-specific arguments to the parser before allowing the superclass to parse.
|
||||||
OptionSpec<String> autoOpenFileSpec = optionParser.accepts(autoOpenFileKey,
|
OptionSpec<String> autoOpenFileSpec = optionParser.accepts(autoOpenFileKey,
|
||||||
"File to open at startup.").withRequiredArg().ofType(String.class);
|
"File to open at startup.").withRequiredArg().ofType(String.class);
|
||||||
@ -649,11 +649,7 @@ public class TVApplication extends RunTimeTrickApplication implements VariableLi
|
|||||||
optionParser.accepts(stripChartsOnlyKey, "Display strip charts only.");
|
optionParser.accepts(stripChartsOnlyKey, "Display strip charts only.");
|
||||||
|
|
||||||
// The superclass handles all malformed arguments.
|
// The superclass handles all malformed arguments.
|
||||||
super.parseArguments(arguments, optionParser);
|
OptionSet options = super.parseArguments(arguments, optionParser);
|
||||||
|
|
||||||
// This repeats some of the parsing done by the superclass, but there's
|
|
||||||
// not a clean way of passing the results down, so live with it for now.
|
|
||||||
OptionSet options = optionParser.parse(arguments);
|
|
||||||
|
|
||||||
if (options.has(autoOpenFileKey)) {
|
if (options.has(autoOpenFileKey)) {
|
||||||
trickProperties.setProperty(autoOpenFileKey, options.valueOf(autoOpenFileSpec));
|
trickProperties.setProperty(autoOpenFileKey, options.valueOf(autoOpenFileSpec));
|
||||||
@ -666,6 +662,8 @@ public class TVApplication extends RunTimeTrickApplication implements VariableLi
|
|||||||
}
|
}
|
||||||
|
|
||||||
stripChartsOnly = options.has(stripChartsOnlyKey);
|
stripChartsOnly = options.has(stripChartsOnlyKey);
|
||||||
|
|
||||||
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user