use of com.commercetools.project.sync.exception.CliException in project commercetools-project-sync by commercetools.
the class CliRunner method processCliArguments.
private static CompletionStage<Void> processCliArguments(@Nonnull final CommandLine commandLine, @Nonnull final Options cliOptions, @Nonnull final SyncerFactory syncerFactory) {
final Option[] options = commandLine.getOptions();
if (options.length == 0) {
return exceptionallyCompletedFuture(new CliException("Please pass at least 1 option to the CLI."));
} else {
final Option option = Arrays.stream(options).filter(o -> !SYNC_PROJECT_SYNC_CUSTOM_OBJECTS_OPTION_LONG.equals(o.getLongOpt())).findAny().orElse(null);
if (option == null) {
return exceptionallyCompletedFuture(new CliException(format("Please pass at least 1 more option other than %s to the CLI.", SYNC_PROJECT_SYNC_CUSTOM_OBJECTS_OPTION_LONG)));
}
final String optionName = option.getOpt();
CompletionStage<Void> resultCompletionStage = CompletableFuture.completedFuture(null);
if (SYNC_MODULE_OPTION_SHORT.equalsIgnoreCase(optionName)) {
resultCompletionStage = processSyncOptionAndExecute(commandLine, syncerFactory);
}
if (HELP_OPTION_SHORT.equalsIgnoreCase(optionName)) {
printHelpToStdOut(cliOptions);
}
if (VERSION_OPTION_SHORT.equalsIgnoreCase(optionName)) {
printApplicationVersion();
}
return resultCompletionStage;
}
}
use of com.commercetools.project.sync.exception.CliException in project commercetools-project-sync by commercetools.
the class CliRunner method processSyncOptionAndExecute.
@Nonnull
private static CompletionStage<Void> processSyncOptionAndExecute(@Nonnull final CommandLine commandLine, @Nonnull final SyncerFactory syncerFactory) {
final String[] syncOptionValues = commandLine.getOptionValues(SYNC_MODULE_OPTION_SHORT);
final String runnerNameValue = commandLine.getOptionValue(RUNNER_NAME_OPTION_SHORT);
final boolean isFullSync = commandLine.hasOption(FULL_SYNC_OPTION_SHORT);
final boolean isSyncProjectSyncCustomObjects = commandLine.hasOption(SYNC_PROJECT_SYNC_CUSTOM_OBJECTS_OPTION_LONG);
final boolean isProductQueryParametersOptionPresent = commandLine.hasOption(PRODUCT_QUERY_PARAMETERS_OPTION);
final ProductSyncCustomRequest productSyncCustomRequest;
try {
productSyncCustomRequest = isProductQueryParametersOptionPresent ? parseProductQueryParametersOption(commandLine.getOptionValue(PRODUCT_QUERY_PARAMETERS_OPTION)) : null;
} catch (CliException e) {
return exceptionallyCompletedFuture(e);
}
return syncerFactory.sync(syncOptionValues, runnerNameValue, isFullSync, isSyncProjectSyncCustomObjects, productSyncCustomRequest);
}
use of com.commercetools.project.sync.exception.CliException in project commercetools-project-sync by commercetools.
the class ProductSyncCustomRequest method parseProductQueryParametersOption.
public static ProductSyncCustomRequest parseProductQueryParametersOption(String customRequest) {
final ObjectMapper objectMapper = new ObjectMapper();
final ProductSyncCustomRequest productSyncCustomRequest;
try {
productSyncCustomRequest = objectMapper.readValue(customRequest, ProductSyncCustomRequest.class);
} catch (IOException | IllegalArgumentException e) {
throw new CliException(e.getMessage());
}
return productSyncCustomRequest;
}
Aggregations