4343import org .scijava .plugin .Parameter ;
4444import org .scijava .plugin .Plugin ;
4545import org .scijava .run .RunService ;
46+ import org .scijava .startup .StartupService ;
4647
4748/**
4849 * Handles the {@code --run} command line argument.
@@ -55,6 +56,9 @@ public class RunArgument extends AbstractConsoleArgument {
5556 @ Parameter
5657 private RunService runService ;
5758
59+ @ Parameter
60+ private StartupService startupService ;
61+
5862 @ Parameter
5963 private ParseService parser ;
6064
@@ -78,22 +82,24 @@ public void handle(final LinkedList<String> args) {
7882 final String arg = getParam (args );
7983 if (arg != null ) args .removeFirst (); // argument list was given
8084
81- try {
82- if (arg == null ) runService .run (code );
83- else {
84- final Items items = parser .parse (arg );
85- if (items .isMap ()) runService .run (code , items .asMap ());
86- else if (items .isList ()) runService .run (code , items .toArray ());
85+ startupService .addOperation (() -> {
86+ try {
87+ if (arg == null ) runService .run (code );
8788 else {
88- throw new IllegalArgumentException ("Arguments are inconsistent. " +
89- "Please pass either a list of key/value pairs, " +
90- "or a list of values." );
89+ final Items items = parser .parse (arg );
90+ if (items .isMap ()) runService .run (code , items .asMap ());
91+ else if (items .isList ()) runService .run (code , items .toArray ());
92+ else {
93+ throw new IllegalArgumentException ("Arguments are inconsistent. " +
94+ "Please pass either a list of key/value pairs, " +
95+ "or a list of values." );
96+ }
9197 }
9298 }
93- }
94- catch ( final InvocationTargetException exc ) {
95- throw new RuntimeException ( exc );
96- }
99+ catch ( final InvocationTargetException exc ) {
100+ throw new RuntimeException ( exc );
101+ }
102+ });
97103 }
98104
99105 // -- Typed methods --
0 commit comments