private Action<ExecutionListener> createAction(
      CommandLineParser parser,
      final ParsedCommandLine commandLine,
      CommandLineConverter<StartParameter> startParameterConverter,
      final ServiceRegistry loggingServices) {
    if (commandLine.hasOption(HELP)) {
      return new ActionAdapter(new ShowUsageAction(parser));
    }
    if (commandLine.hasOption(VERSION)) {
      return new ActionAdapter(new ShowVersionAction());
    }
    if (commandLine.hasOption(GUI)) {
      return new ActionAdapter(new ShowGuiAction());
    }

    final StartParameter startParameter = new StartParameter();
    startParameterConverter.convert(commandLine, startParameter);
    DaemonParameters daemonParameters = constructDaemonParameters(startParameter);
    if (commandLine.hasOption(FOREGROUND)) {
      ForegroundDaemonConfiguration conf =
          new ForegroundDaemonConfiguration(
              daemonParameters.getUid(),
              daemonParameters.getBaseDir(),
              daemonParameters.getIdleTimeout());
      return new ActionAdapter(new ForegroundDaemonMain(conf));
    }

    if (commandLine.hasOption(STOP)) {
      return stopAllDaemons(daemonParameters, loggingServices);
    }
    if (useDaemon(commandLine, daemonParameters)) {
      return runBuildWithDaemon(commandLine, daemonParameters, loggingServices);
    }
    if (canUseCurrentProcess(daemonParameters)) {
      return runBuildInProcess(loggingServices, startParameter);
    }
    return runBuildInSingleUseDaemon(commandLine, daemonParameters, loggingServices);
  }
 private boolean useDaemon(ParsedCommandLine commandLine, DaemonParameters daemonParameters) {
   boolean useDaemon = daemonParameters.isEnabled();
   useDaemon = useDaemon || commandLine.hasOption(DAEMON);
   useDaemon = useDaemon && !commandLine.hasOption(NO_DAEMON);
   return useDaemon;
 }