Source:
public static void start(String... args) { LOGGER.debug("Registering commands with CommandRepository"); CommandRepository commandRepository = new CommandRepository(); commandRepository.addAll( new HashSet<>( Arrays.asList( MAIN, new ActivateCommand(), new AttachCommand(), new DetachCommand(), new ImportCommand(), new ExportCommand(), new GetCommand(), new SetCommand(), new UnsetCommand(), new DiagnosticCommand(), new RepairCommand(), new LogCommand() ) ) ); LOGGER.debug("Parsing command-line arguments"); CustomJCommander jCommander = parseArguments(commandRepository, args); MAIN.run(); ConcurrencySizing concurrencySizing = new ConcurrencySizing(); Duration connectionTimeout = Duration.ofMillis(MAIN.getConnectionTimeout().getQuantity(TimeUnit.MILLISECONDS)); Duration requestTimeout = Duration.ofMillis(MAIN.getRequestTimeout().getQuantity(TimeUnit.MILLISECONDS)); Duration entityOperationTimeout = Duration.ofMillis(MAIN.getEntityOperationTimeout().getQuantity(TimeUnit.MILLISECONDS)); DiagnosticServiceProvider diagnosticServiceProvider = new DiagnosticServiceProvider("CONFIG-TOOL", connectionTimeout, requestTimeout, MAIN.getSecurityRootDirectory()); MultiDiagnosticServiceProvider multiDiagnosticServiceProvider = new ConcurrentDiagnosticServiceProvider(diagnosticServiceProvider, connectionTimeout, concurrencySizing); NomadEntityProvider nomadEntityProvider = new NomadEntityProvider( "CONFIG-TOOL", Duration.ofMillis(30000), new NomadEntity.Settings().setRequestTimeout(entityOperationTimeout), MAIN.getSecurityRootDirectory()); NomadManager<NodeContext> nomadManager = new NomadManager<>(new NomadEnvironment(), multiDiagnosticServiceProvider, nomadEntityProvider); RestartService restartService = new RestartService(diagnosticServiceProvider, concurrencySizing); StopService stopService = new StopService(diagnosticServiceProvider, concurrencySizing); LOGGER.debug("Injecting services in CommandRepository"); commandRepository.inject(diagnosticServiceProvider, multiDiagnosticServiceProvider, nomadManager, restartService, stopService); jCommander.getAskedCommand().map(command -> { if (command.isHelp()) { jCommander.printUsage(); return true; } command.validate(); command.run(); return true; }).orElseGet(() -> { jCommander.usage(); return false; }); }

Target:
public static void start(String... args) { LOGGER.debug("Registering commands with CommandRepository"); CommandRepository commandRepository = new CommandRepository(); commandRepository.addAll( new HashSet<>( Arrays.asList( MAIN, new ActivateCommand(), new AttachCommand(), new DetachCommand(), new ImportCommand(), new ExportCommand(), new GetCommand(), new SetCommand(), new UnsetCommand(), new DiagnosticCommand(), new RepairCommand(), new LogCommand() ) ) ); LOGGER.debug("Parsing command-line arguments"); CustomJCommander jCommander = parseArguments(commandRepository, args); MAIN.validate(); MAIN.run(); ConcurrencySizing concurrencySizing = new ConcurrencySizing(); Duration connectionTimeout = Duration.ofMillis(MAIN.getConnectionTimeout().getQuantity(TimeUnit.MILLISECONDS)); Duration requestTimeout = Duration.ofMillis(MAIN.getRequestTimeout().getQuantity(TimeUnit.MILLISECONDS)); Duration entityOperationTimeout = Duration.ofMillis(MAIN.getEntityOperationTimeout().getQuantity(TimeUnit.MILLISECONDS)); Duration entityConnectionTimeout = Duration.ofMillis(MAIN.getEntityConnectionTimeout().getQuantity(TimeUnit.MILLISECONDS)); DiagnosticServiceProvider diagnosticServiceProvider = new DiagnosticServiceProvider("CONFIG-TOOL", connectionTimeout, requestTimeout, MAIN.getSecurityRootDirectory()); MultiDiagnosticServiceProvider multiDiagnosticServiceProvider = new ConcurrentDiagnosticServiceProvider(diagnosticServiceProvider, connectionTimeout, concurrencySizing); NomadEntityProvider nomadEntityProvider = new NomadEntityProvider( "CONFIG-TOOL", entityConnectionTimeout, new NomadEntity.Settings().setRequestTimeout(entityOperationTimeout), MAIN.getSecurityRootDirectory()); NomadManager<NodeContext> nomadManager = new NomadManager<>(new NomadEnvironment(), multiDiagnosticServiceProvider, nomadEntityProvider); RestartService restartService = new RestartService(diagnosticServiceProvider, concurrencySizing); StopService stopService = new StopService(diagnosticServiceProvider, concurrencySizing); LOGGER.debug("Injecting services in CommandRepository"); commandRepository.inject(diagnosticServiceProvider, multiDiagnosticServiceProvider, nomadManager, restartService, stopService); jCommander.getAskedCommand().map(command -> { if (command.isHelp()) { jCommander.printUsage(); return true; } command.validate(); command.run(); return true; }).orElseGet(() -> { jCommander.usage(); return false; }); }