Skip to content

Commit

Permalink
[all] Force Unix standard for naming the CLI options.
Browse files Browse the repository at this point in the history
see #1037

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Dec 8, 2020
1 parent 75dbde2 commit 41983c5
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
Expand Up @@ -161,7 +161,7 @@ public void sreChanged(ISREInstall sre) {
index = Arrays.asList(logOptValues).indexOf(selectedValue);
}
}
final String logOptStr = CliUtilities.getCommandLineOption(logOpt, Messages.MainLaunchConfigurationTab_16);
final String logOptStr = CliUtilities.getUnixCommandLineOption(logOpt, Messages.MainLaunchConfigurationTab_16);
this.logLevelLabel.setText(MessageFormat.format(Messages.MainLaunchConfigurationTab_15, logOptStr));
this.logLevelLabel.setData(logOpt);
this.logLevelCombo.setItems(logOptValues);
Expand Down
Expand Up @@ -93,7 +93,7 @@ protected String getProgramArguments(ILaunchConfiguration configuration, ISREIns
final String logOption = getConfigurationAccessor().getLogArgumentName(configuration);
final String logValue = getConfigurationAccessor().getLogArgumentValue(configuration);
if (!Strings.isNullOrEmpty(logOption) && !Strings.isNullOrEmpty(logValue)) {
final String fullOption = CliUtilities.getCommandLineOption(logOption, logValue);
final String fullOption = CliUtilities.getUnixCommandLineOption(logOption, logValue);
if (!Strings.isNullOrEmpty(fullOption)) {
options = join(options, fullOption);
}
Expand Down
Expand Up @@ -223,4 +223,65 @@ public static String getCommandLineDefinition(String name, String value) {
return buf.toString();
}

/** Replies the option prefixed with the characters to be used as option prefix on the command line.
* This function is for Unix.
*
* @param name the name of the option.
* @return the command-line option.
* @since 0.12
*/
public static String getUnixCommandLineOption(String name) {
if (name.length() > 1) {
return getUnixCommandLineLongOptionPrefix() + name;
}
return getUnixCommandLineShortOptionPrefix() + name;
}

/** Replies the option prefixed with the characters to be used as option prefix on the command line and postfixed
* with the given boolean value.
* This function is for Unix.
*
* @param name the name of the option.
* @param value the value to put in the command-line option.
* @return the command-line option.
* @since 0.12
*/
public static String getUnixCommandLineOption(String name, String value) {
assert !Strings.isNullOrEmpty(name);
assert !Strings.isNullOrEmpty(value);
final StringBuilder buf = new StringBuilder();
buf.append(getUnixCommandLineOption(name));
buf.append(EQUAL_SIGN).append(value);
return buf.toString();
}

/** Replies the characters to be used as short-option prefix on the command line.
* This function is for Unix.
*
* @return the command-line option prefix.
* @since 0.12
*/
public static String getUnixCommandLineShortOptionPrefix() {
return UNIX_SOPT;
}

/** Replies the characters to be used as long-option prefix on the command line on Unix.
*
* @return the command-line option prefix.
* @since 0.12
*/
public static String getUnixCommandLineLongOptionPrefix() {
return UNIX_LOPT;
}

/** Replies the characters to be used to mark the last option on the command line.
* This function is for Unix.
*
* @return the command-line option prefix.
* @since 0.12
*/
public static String getUnixCommandLineLastOptionPrefix() {
return UNIX_LOPT;
}

}
Expand Up @@ -117,13 +117,13 @@ public Map<String, String> getAvailableCommandLineOptions() {
//options.put(SRECommandLineOptions.CLI_EMBEDDED, formatCommandLineOption(null, null));
// Root context configuration
options.put(SRECommandLineOptions.CLI_DEFAULT_CONTEXT_ID,
CliUtilities.getCommandLineOption(BootConfigModule.BOOT_TYPE_OPTION, RootContextType.DEFAULT.toJsonString()));
CliUtilities.getUnixCommandLineOption(BootConfigModule.BOOT_TYPE_OPTION, RootContextType.DEFAULT.toJsonString()));
options.put(SRECommandLineOptions.CLI_RANDOM_CONTEXT_ID,
CliUtilities.getCommandLineOption(BootConfigModule.BOOT_TYPE_OPTION, RootContextType.RANDOM.toJsonString()));
CliUtilities.getUnixCommandLineOption(BootConfigModule.BOOT_TYPE_OPTION, RootContextType.RANDOM.toJsonString()));
options.put(SRECommandLineOptions.CLI_BOOT_AGENT_CONTEXT_ID,
CliUtilities.getCommandLineOption(BootConfigModule.BOOT_TYPE_OPTION, RootContextType.BOOT_AGENT_NAME.toJsonString()));
CliUtilities.getUnixCommandLineOption(BootConfigModule.BOOT_TYPE_OPTION, RootContextType.BOOT_AGENT_NAME.toJsonString()));
// Option for disabling the command-line options.
options.put(SRECommandLineOptions.CLI_NO_MORE_OPTION, CliUtilities.getCommandLineLastOptionPrefix());
options.put(SRECommandLineOptions.CLI_NO_MORE_OPTION, CliUtilities.getUnixCommandLineLastOptionPrefix());
return Collections.unmodifiableMap(options);
}

Expand Down

0 comments on commit 41983c5

Please sign in to comment.