Create and return an injector configured using the specified command line arguments.

@param commandName command name, used in usage string
@param args command line arguments
@return an injector configured using the specified command line arguments
550601
protected static final Injector init(final String commandName, final String[] args) {
        String usage = commandName + USAGE_PARAMS;
        Switch about = new Switch("a", "about", "display about message");
        Switch help = new Switch("h", "help", "display help message");
        final StringArgument namespace = new StringArgument("s", "namespace", "namespace", true);
        final FileArgument glstringFile = new FileArgument("g", "glstrings", "glstring input file", false);
        final FileArgument identifierFile = new FileArgument("i", "identifiers", "identifier output file", false);
        final StringArgument client = new StringArgument("c", "client", "client implementation, json or xml, default json", false);

        ArgumentList arguments = new ArgumentList(about, help, namespace, glstringFile, identifierFile, client);
        CommandLine commandLine = new CommandLine(args);
        try
        {
            CommandLineParser.parse(commandLine, arguments);
            if (about.wasFound()) {
                About.about(System.out);
                System.exit(0);
            }
            if (help.wasFound()) {
                Usage.usage(usage, null, commandLine, arguments, System.out);
                System.exit(0);
            }
        }
        catch (CommandLineParseException e) {
            if (about.wasFound()) {
                About.about(System.out);
                System.exit(0);
            }
            if (help.wasFound()) {
                Usage.usage(usage, null, commandLine, arguments, System.out);
                System.exit(0);
            }
            Usage.usage(usage, e, commandLine, arguments, System.err);
            System.exit(-1);
        }

        return Guice.createInjector(new CacheGlClientModule(), new AbstractModule() {
            @Override
            protected void configure() {
                bind(String.class).annotatedWith(Namespace.class).toInstance(namespace.getValue());

                if (glstringFile.wasFound()) {
                    bind(File.class).annotatedWith(GlstringFile.class).toInstance(glstringFile.getValue());
                }
                else {
                    bind(File.class).annotatedWith(GlstringFile.class).toProvider(Providers.of((File) null));
                }

                if (identifierFile.wasFound()) {
                    bind(File.class).annotatedWith(IdentifierFile.class).toInstance(identifierFile.getValue());
                }
                else {
                    bind(File.class).annotatedWith(IdentifierFile.class).toProvider(Providers.of((File) null));
                }

                bind(HttpClient.class).to(RestAssuredHttpClient.class);

                if ("xml".equals(client.getValue("json"))) {
                    bind(GlClient.class).to(XmlGlClient.class);
                }
                else {
                    bind(GlClient.class).to(JsonGlClient.class);
                }
            }
        });
    }
807455
public static void main(String[] args) {

    ArgumentProcessor<Configuration> argProcessor = new ArgumentProcessor<Configuration>("");

    argProcessor.addOption("verbose", 'V', new BooleanFieldOption<Configuration>("verbose"));
    argProcessor.addOption("host", 'h', new StringFieldOption<Configuration>("host"));
    argProcessor.addOption("username", 'u', new StringFieldOption<Configuration>("username"));
    argProcessor.addOption("password", 'p', new StringFieldOption<Configuration>("password"));

    argProcessor.addCommand("verify", new VerifyCommand());
    argProcessor.addCommand("sync", new SynchronizeCommand());
    argProcessor.addCommand("idle", new SetIdleTimeCommand());
    argProcessor.addCommand("script", new ScriptCommand());
    argProcessor.addCommand("connect", new ConnectCommand());

    argProcessor.setDefaultCommand(UnrecognizedCommand.getInstance());

    argProcessor.process(args, new Configuration());

  }
681738
function Injector(obj){
  var services = {};
  var get = name => {
    if(!(name in services)){
      const err = new Error(`[injector] service "${name}" not found`);
      return Promise.reject(err);
    }
    return services[name];
  };
  if(typeof obj === 'object')
    services = obj;
  if(typeof obj === 'function')
    get = obj;
  function resolve(name) {
    let service = get(name);
    if(typeof service === 'function')
      service = invoke(service);
    return service;
  };
  function invoke(fn, that){
    return Promise
    .all(getParameterNames(fn).map(resolve))
    .then(params => fn.apply(that, params));
  }
  return invoke;
}
94285
static public IParserInput getInstance(
            final char commandPrefix,
            final File args)
                    throws IOException
    {
        return getInstance(commandPrefix, false, args);
    }
46248
private void injectArguments(final List<Element> arguments, final MethodIdentifier identifier) {
        final boolean staticMethod = identifier.isStaticMethod();
        final int startIndex = staticMethod ? 0 : 1;
        final int endIndex = staticMethod ? arguments.size() - 1 : arguments.size();

        IntStream.rangeClosed(startIndex, endIndex).forEach(i -> localVariables.put(i, arguments.get(staticMethod ? i : i - 1)));
    }
854534
public Object create(String name, Object... args)
    throws ClassNotFoundException,
           NoSuchMethodException,
           IllegalAccessException,
           InstantiationException,
           InvocationTargetException
    {
//StringBuilder sb = new StringBuilder("DefaultObjectFactory.create(").append(name).append(',');
//for (Object arg: args) {
//sb.append(arg.getClass().getName()).append(' ');
//}
//sb.append(')');
//System.err.println(sb);
        try {
            Class<?> type = Class.forName(name);
/*
            Constructor<?>[] constructors = type.getConstructors();
            for (Constructor<?> constructor: constructors) {
                Class<?>[] ptypes = constructor.getParameterTypes();
                if (ptypes.length == args.length) {
                    try {
                        return constructor.newInstance(args);
                    } catch (IllegalArgumentException x) {
                        // ignore and try the next one
                    } catch (IllegalAccessException x) {
                        throw x;
                    } catch (InstantiationException x) {
                        throw x;
                    } catch (InvocationTargetException x) {
                        throw x;
                    }
                }
            }
            throw new NoSuchMethodException("Can't locate a desired constructor in " + name);
*/
//System.err.println("DefaultObjectFactory.create: successful");
            return Beans.create(type, args);
        } catch (ClassNotFoundException x) {
            throw x;
        }
    }
515051
@SuppressWarnings("unchecked")
	private T createInstance(final String className, final Object... arguments) {
		try {
			Class<?> implementation = Class.forName(className, false, classLoader);
			if (service.isAssignableFrom(implementation)) {
				return (T) implementation.getDeclaredConstructor(argumentTypes).newInstance(arguments);
			} else {
				InternalLogger.log(Level.ERROR, "Class '" + className + "' does not implement servcie interface '" + service + "'");
			}
		} catch (ClassNotFoundException ex) {
			InternalLogger.log(Level.ERROR, "Service implementation '" + className + "' not found");
		} catch (NoSuchMethodException ex) {
			InternalLogger.log(Level.ERROR, "Service implementation '" + className + "' has no matching constructor");
		} catch (InstantiationException ex) {
			InternalLogger.log(Level.ERROR, "Service implementation '" + className + "' is not instantiable");
		} catch (IllegalAccessException ex) {
			InternalLogger.log(Level.ERROR, "Constructor of service implementation '" + className + "' is not accessible");
		} catch (IllegalArgumentException ex) {
			InternalLogger.log(Level.ERROR, "Illegal arguments for constructor of service implementation '" + className + "'");
		} catch (InvocationTargetException ex) {
			InternalLogger.log(Level.ERROR, ex.getTargetException(), "Failed creating service implementation '" + className + "'");
		}

		return null;
	}
1110744
public static ITargetIdentifier field(final String fieldName) {
		return new ITargetIdentifier() {
			public IDependencyInjector of(final Object target) {
				return new FieldInjector(target, fieldName);
			}
		};
	}
520006
public static function createNewObject($className, $args = null)
    {
        $mock = self::getMock(self::$injectedObjects, 'object', $className);
        if ($mock !== null)
        {
            return $mock;
        }

        if ($args === null)
        {
            return new $className();
        }

        // we need to pass arguments which requires reflection
        $reflection = new ReflectionClass($className);
        return $reflection->newInstanceArgs($args);
    }
306937
@SuppressWarnings("unchecked")
    public static DataProviderFactory create(final Object... args) {
        // Find the implementation for the DataProviderFactory.
        final Class<? extends DataProviderFactory> dataProviderClass = findDataProviderImpl();

        // Find the constructor that matches the arguments passed.
        final DataProviderFactory factory;
        try {
            Constructor<? extends DataProviderFactory> dataProviderConstructor = null;
            final Constructor[] constructors = dataProviderClass.getDeclaredConstructors();
            for (final Constructor constructor : constructors) {
                final Class<?>[] params = constructor.getParameterTypes();
                boolean matches = false;

                // Ensure that all the argument match
                if (args.length == params.length) {
                    matches = true;
                    for (int i = 0; i < params.length; i++) {
                        if (!params[i].isAssignableFrom(args[i].getClass())) {
                            matches = false;
                        }
                    }
                }

                // If the constructor matches then break the loop, as we've found the matching constructor
                if (matches) {
                    dataProviderConstructor = constructor;
                    break;
                }
            }

            // Make sure a constructor was found
            if (dataProviderConstructor != null) {
                factory = dataProviderConstructor.newInstance(args);
            } else {
                factory = null;
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return factory;
    }
154899
@SuppressWarnings("static-method")
	@Provides
	@Singleton
	public HelpGenerator provideHelpGenerator(
			ApplicationMetadata metadata, Injector injector, Terminal terminal) {
		int maxColumns = terminal.getColumns();
		if (maxColumns < TTY_MIN_COLUMNS) {
			maxColumns = TTY_DEFAULT_COLUMNS;
		}
		String argumentSynopsis;
		try {
			argumentSynopsis = injector.getInstance(Key.get(String.class, ApplicationArgumentSynopsis.class));
		} catch (Exception exception) {
			argumentSynopsis = null;
		}
		String detailedDescription;
		try {
			detailedDescription = injector.getInstance(Key.get(String.class, ApplicationDetailedDescription.class));
		} catch (Exception exception) {
			detailedDescription = null;
		}
		return new SynopsisHelpGenerator(metadata, argumentSynopsis, detailedDescription, maxColumns);
	}
759247
public static void main(final String[] args) throws BindException, InjectionException {
    final int tcpBeginPort = args.length > 0 ? Integer.parseInt(args[0]) : DEFAULT_TCP_BEGIN_PORT;
    final int tcpRangeCount = args.length > 1 ? Integer.parseInt(args[1]) : DEFAULT_TCP_RANGE_COUNT;
    final int tcpTryCount = args.length > 2 ? Integer.parseInt(args[2]) : DEFAULT_TCP_RANGE_TRY_COUNT;

    final Configuration runtimeConf = getRuntimeConfiguration(tcpBeginPort, tcpRangeCount, tcpTryCount);
    final Configuration driverConf = getDriverConfiguration();

    final LauncherStatus status = DriverLauncher
        .getLauncher(runtimeConf)
        .run(driverConf, JOB_TIMEOUT);
    LOG.log(Level.INFO, "REEF job completed: {0}", status);
  }
584818
private void executeMvnCommand(final String... args)
            throws CommandLineException, MojoFailureException {
        executeCommand(cmdMvn, true, argLine, args);
    }
345145
public static void setInjector(String applicationName, PaxWicketInjector newInjector) {
        synchronized (instance.injectorMap) {
            instance.injectorMap.put(applicationName, newInjector);
        }
        LOGGER.debug("registered Injector for application {}", applicationName);
    }
1358406
public void cli(String[] args) {
        CommandLineParser cli = new CommandLineParser();
        cli.addOption(NamedOption.builder()
                .name("data")
                .description("Data to use for training or testing")
                .required(true)
                .type(Resource.class)
                .build());
        cli.addOption(NamedOption.builder()
                .name("format")
                .description("Format for reading data")
                .defaultValue("JSON_OPL")
                .type(String.class)
                .build());
        cli.addOption(NamedOption.builder()
                .name("corpusType")
                .description("Type of corpus to create (e.g. in-memory)")
                .defaultValue("IN_MEMORY")
                .type(CorpusType.class)
                .build());
        cli.addOption(NamedOption.builder()
                .name("mode")
                .description("Train/Test/Split")
                .defaultValue("TEST")
                .type(Mode.class)
                .build());
        cli.addOption(NamedOption.builder()
                .name("model")
                .description("Model to save/load")
                .type(Resource.class)
                .required(true)
                .build());
        cli.addOption(NamedOption.builder()
                .name("undersample")
                .description("Undersample")
                .type(Boolean.class)
                .required(false)
                .defaultValue(false)
                .build());
        cli.addOption(NamedOption.builder()
                .name("oversample")
                .description("Oversample")
                .type(Boolean.class)
                .required(false)
                .defaultValue(false)
                .build());
        cli.parse(args);
        Hermes.initializeApplication(args);

        Dataset<Instance> data = getDataset(cli.get("data"), cli.get("format"), cli.get("corpusType"),
                cli.get("undersample"),
                cli.get("oversample"));

        Mode mode = cli.get("mode");
        switch (mode) {
            case TEST:
                try {
                    this.classifier = Cast.<BasicTextClassifier>as(TextClassifier.read(cli.get("model"))).classifier;
                } catch (Exception e) {
                    throw Throwables.propagate(e);
                }
                test(data);
                break;
            case SPLIT:
                TrainTestSplit<Instance> split = Iterables.getFirst(data.split(0.8), null);
                train(split.getTrain());
                test(split.getTest());
                break;
            case TRAIN:
                train(data);
                try {
                    write(cli.get("model"));
                } catch (Exception e) {
                    throw Throwables.propagate(e);
                }
                break;
            case CV3:
            case CV10:
                TrainTestSet<Instance> folds = data.fold(mode == Mode.CV3 ? 3 : 10);
                ClassifierEvaluation evaluation = new ClassifierEvaluation();
                for (TrainTestSplit<Instance> fold : folds) {
                    train(fold.getTrain());
                    evaluation.merge(test(fold.getTest(), false));
                }
                evaluation.output(System.out);
                break;
            default:
                System.err.println("Unknown option");
        }
    }
253452
public static void main(final String[] args) {
		EnvironmentInformation.logEnvironmentInfo(LOG, "Command Line Client", args);

		// 1. find the configuration directory
		final String configurationDirectory = getConfigurationDirectoryFromEnv();

		// 2. load the global configuration
		final Configuration configuration = GlobalConfiguration.loadConfiguration(configurationDirectory);

		// 3. load the custom command lines
		final List<CustomCommandLine<?>> customCommandLines = loadCustomCommandLines(
			configuration,
			configurationDirectory);

		try {
			final CliFrontend cli = new CliFrontend(
				configuration,
				customCommandLines);

			SecurityUtils.install(new SecurityConfiguration(cli.configuration));
			int retCode = SecurityUtils.getInstalledContext()
					.runSecured(() -> cli.parseParameters(args));
			System.exit(retCode);
		}
		catch (Throwable t) {
			final Throwable strippedThrowable = ExceptionUtils.stripException(t, UndeclaredThrowableException.class);
			LOG.error("Fatal error while running command line interface.", strippedThrowable);
			strippedThrowable.printStackTrace();
			System.exit(31);
		}
	}
533556
public static void main(final String[] args) {

        // describe all instances in aws-mock
        List<Instance> allInstances = describeAllInstances();
        for (Instance i : allInstances) {
            System.out.println(i.getInstanceId() + " - " + i.getState().getName());
        }

        // describe specifiled instances in aws-mock
        List<Instance> someInstances = describeInstances(Arrays.asList("i-12345678", "i=abcdef00"));
        for (Instance i : someInstances) {
            System.out.println(i.getInstanceId() + " - " + i.getState().getName());
        }
    }