Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve command line help message format (DAT-12853) #3829

Merged
merged 12 commits into from
Feb 22, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ private CommandLine buildPicoCommandLine() {

commandLine.setExecutionExceptionHandler((ex, commandLine1, parseResult) -> LiquibaseCommandLine.this.handleException(ex));

commandLine.setUsageHelpAutoWidth(true);

return commandLine;
}

Expand Down Expand Up @@ -767,15 +769,9 @@ private void addSubcommand(CommandDefinition commandDefinition, CommandLine root
}

String shortDescription = commandDefinition.getShortDescription();
String displayDescription = shortDescription;
String legacyCommand = commandName[commandName.length - 1];
String camelCaseCommand = StringUtil.toCamelCase(legacyCommand);
if (!legacyCommand.equals(camelCaseCommand)) {
displayDescription = "\n" + shortDescription + "\n[deprecated: " + camelCaseCommand + "]";
}

subCommandSpec.usageMessage()
.header(StringUtil.trimToEmpty(displayDescription) + "\n")
.header(StringUtil.trimToEmpty(shortDescription) + "\n")
.description(StringUtil.trimToEmpty(commandDefinition.getLongDescription()));

subCommandSpec.optionsCaseInsensitive(true);
Expand All @@ -796,36 +792,32 @@ private void addSubcommand(CommandDefinition commandDefinition, CommandLine root

String argDisplaySuffix = "";
String argName = argNames[i];
String camelCaseArg = StringUtil.toCamelCase(argName.substring(2));
if (!argName.equals("--" + camelCaseArg)) {
argDisplaySuffix = "\n[deprecated: --" + camelCaseArg + "]";
}

//
// Determine if this is a group command and set the property/environment display strings accordingly
//
String description;
if (commandDefinition.getName().length > 1) {
String propertyStringToPresent = "\n(liquibase.command." +
StringUtil.join(commandDefinition.getName(), ".") + "." + def.getName() + ")";
String propertyStringToPresent = "\n(defaults file: 'liquibase.command." +
StringUtil.join(commandDefinition.getName(), ".") + "." + def.getName() + "'";
String envStringToPresent =
toEnvVariable("\n(liquibase.command." + StringUtil.join(commandDefinition.getName(), ".") +
"." + def.getName()) + ")" + argDisplaySuffix;
toEnvVariable("environment variable: 'liquibase.command." + StringUtil.join(commandDefinition.getName(), ".") +
"." + def.getName()) + "')" + argDisplaySuffix;
description = propertyStringToPresent + envStringToPresent;
} else {
description =
"\n(liquibase.command." + def.getName() + " OR liquibase.command." +
StringUtil.join(commandDefinition.getName(), ".") + "." + def.getName() + ")\n" +
"(" + toEnvVariable("liquibase.command." + def.getName()) + " OR " +
toEnvVariable("liquibase.command." + StringUtil.join(commandDefinition.getName(), ".") +
"." + def.getName()) + ")" + argDisplaySuffix;
String propertyStringToPresent = "\n(defaults file: 'liquibase.command." + def.getName() + "' OR 'liquibase.command." +
StringUtil.join(commandDefinition.getName(), ".") + "." + def.getName() + "'";
String envStringToPresent = ", environment variable: '" + toEnvVariable("liquibase.command." + def.getName()) + "' OR '" +
toEnvVariable("liquibase.command." + StringUtil.join(commandDefinition.getName(), ".") +
"." + def.getName()) + "')" + argDisplaySuffix;
description = propertyStringToPresent + envStringToPresent;
}

if (def.getDefaultValue() != null) {
if (def.getDefaultValueDescription() == null) {
description = "\nDEFAULT: " + def.getDefaultValue() + "\n" + description;
description = "\nDEFAULT: " + def.getDefaultValue() + description;
} else {
description = "\nDEFAULT: " + def.getDefaultValueDescription() + "\n" + description;
description = "\nDEFAULT: " + def.getDefaultValueDescription() + description;
}
}

Expand Down Expand Up @@ -995,8 +987,8 @@ private void addGlobalArguments(CommandLine commandLine) {
final CommandLine.Model.OptionSpec.Builder optionBuilder = CommandLine.Model.OptionSpec.builder(argNames[i])
.required(false)
.type(String.class);
String description = "(" + def.getKey() + ")\n"
+ "(" + toEnvVariable(def.getKey()) + ")";
String description = "(defaults file: '" + def.getKey() + "', environment variable: '"
+ toEnvVariable(def.getKey()) + "')";

if (def.getDefaultValue() != null) {
if (def.getDefaultValueDescription() == null) {
Expand All @@ -1009,14 +1001,6 @@ private void addGlobalArguments(CommandLine commandLine) {
if (def.getDescription() != null) {
description = def.getDescription() + "\n" + description;
}
if (i == 0) {
String primaryArg = argNames[i];
String camelCaseArg = StringUtil.toCamelCase(primaryArg.substring(2));
if (!primaryArg.equals("--" + camelCaseArg)) {
description = "\n" + description +
"\n[deprecated: --" + camelCaseArg + "]";
}
}

optionBuilder.description(description + "\n");

Expand Down