Skip to content

Commit

Permalink
MID-8842 ninja - required params vs help fix
Browse files Browse the repository at this point in the history
(cherry picked from commit 899b8e0)
  • Loading branch information
1azyman committed Sep 19, 2023
1 parent d5b9e95 commit f2ba3ac
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
public class ExportMiningOptions extends BaseMiningOptions implements BasicExportOptions {

private static final String DELIMITER = ",";
public static final String P_OUTPUT = "-O";
public static final String P_OUTPUT = "-o";
public static final String P_OUTPUT_LONG = "--output";
public static final String P_OVERWRITE = "-ow";
public static final String P_OVERWRITE = "-O";
public static final String P_OVERWRITE_LONG = "--overwrite";
public static final String P_PREFIX_APPLICATION = "-arp";
public static final String P_PREFIX_APPLICATION_LONG = "--application-role-prefix";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import java.nio.file.attribute.PosixFilePermission;
import java.util.Set;

import com.evolveum.midpoint.ninja.util.ConsoleFormat;

import org.apache.commons.io.FileUtils;

import com.evolveum.midpoint.ninja.action.Action;
import com.evolveum.midpoint.ninja.impl.NinjaException;
import com.evolveum.midpoint.ninja.util.ConsoleFormat;
import com.evolveum.midpoint.ninja.util.InputParameterException;
import com.evolveum.midpoint.ninja.util.NinjaUtils;

public class UpgradeInstallationAction extends Action<UpgradeInstallationOptions, Void> {
Expand All @@ -29,7 +29,7 @@ public String getOperationName() {
public Void execute() throws Exception {
final File distributionDirectory = options.getDistributionDirectory();
if (distributionDirectory == null) {
throw new NinjaException("Undefined distribution directory");
throw new InputParameterException("Undefined distribution directory option " + UpgradeInstallationOptions.P_DISTRIBUTION_DIRECTORY);
}

final boolean backupFiles = options.isBackup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class UpgradeInstallationOptions {

public static final String P_INSTALLATION_DIRECTORY = "--installation-directory";

@Parameter(names = { P_DISTRIBUTION_DIRECTORY }, descriptionKey = "upgradeInstallation.distributionDirectory", required = true)
@Parameter(names = { P_DISTRIBUTION_DIRECTORY }, descriptionKey = "upgradeInstallation.distributionDirectory")
private File distributionDirectory;

@Parameter(names = { P_BACKUP_INSTALLATION_DIRECTORY }, descriptionKey = "upgradeInstallation.backupInstallationDirectory")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

package com.evolveum.midpoint.ninja.impl;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.beust.jcommander.DefaultUsageFormatter;
import com.beust.jcommander.JCommander;
Expand All @@ -27,12 +29,18 @@ public NinjaUsageFormatter(JCommander commander) {
public void appendCommands(StringBuilder out, int indentCount, int descriptionIndent, String indent) {
out.append(indent + "\n Commands:\n\n");

int maxCommandNameLength = commander.getRawCommands().keySet().stream()
.map(pn -> pn.getDisplayName().length())
List<String> commandNames = commander.getRawCommands().keySet().stream()
.map(pn -> pn.getDisplayName()).sorted().collect(Collectors.toList());

int maxCommandNameLength = commandNames.stream()
.map(name -> name.length())
.max(Integer::compareTo).orElse(0);

// The magic value 3 is the number of spaces between the name of the option and its description
for (Map.Entry<JCommander.ProgramName, JCommander> commands : commander.getRawCommands().entrySet()) {
for ( String commandName : commandNames) {
Map.Entry<JCommander.ProgramName, JCommander> commands = commander.getRawCommands().entrySet().stream()
.filter(entry -> entry.getKey().getDisplayName().equals(commandName)).findFirst().orElse(null);

Object arg = commands.getValue().getObjects().get(0);
Parameters p = arg.getClass().getAnnotation(Parameters.class);

Expand Down

0 comments on commit f2ba3ac

Please sign in to comment.