Document --status, --stop and --purge in -h/--help #249

This commit is contained in:
Peter Palaga
2020-12-08 22:15:58 +01:00
parent dc25d0ca1f
commit e5e2a1cd86
4 changed files with 50 additions and 19 deletions

View File

@@ -26,7 +26,6 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.Properties; import java.util.Properties;
import java.util.function.Consumer; import java.util.function.Consumer;
@@ -43,6 +42,15 @@ import java.util.stream.Stream;
*/ */
public enum Environment { public enum Environment {
/**
* Delete log files under the <code>mvnd.registry</code> directory that are older than <code>mvnd.logPurgePeriod</code>
*/
PURGE(null, null, null, OptionType.VOID, Flags.OPTIONAL, "--purge"),
/** Prints the status of daemon instances registered in the registry specified by <code>mvnd.registry</code> */
STATUS(null, null, null, OptionType.VOID, Flags.OPTIONAL, "--status"),
/** Stop all daemon instances registered in the registry specified by <code>mvnd.registry</code> */
STOP(null, null, null, OptionType.VOID, Flags.OPTIONAL, "--stop"),
// //
// Log properties // Log properties
// //
@@ -216,7 +224,11 @@ public enum Environment {
Environment(String property, String environmentVariable, Object default_, OptionType type, int flags, Environment(String property, String environmentVariable, Object default_, OptionType type, int flags,
String... options) { String... options) {
this.property = Objects.requireNonNull(property); if (property == null && options.length == 0) {
throw new IllegalArgumentException(
"An " + Environment.class.getSimpleName() + " entry must have property or options set");
}
this.property = property;
this.environmentVariable = environmentVariable; this.environmentVariable = environmentVariable;
this.default_ = default_ != null ? default_.toString() : null; this.default_ = default_ != null ? default_.toString() : null;
this.flags = flags; this.flags = flags;
@@ -346,7 +358,8 @@ public enum Environment {
} }
return Stream.of(values) return Stream.of(values)
.filter(env -> !env.isInternal()) .filter(env -> !env.isInternal())
.sorted(Comparator.comparing(Environment::getProperty)) .sorted(Comparator.<Environment, String> comparing(env -> env.property != null ? env.property : "")
.thenComparing(env -> !env.options.isEmpty() ? env.options.get(0) : ""))
.map(env -> new DocumentedEnumEntry<>(env, props.getProperty(env.name()))); .map(env -> new DocumentedEnumEntry<>(env, props.getProperty(env.name())));
} }

View File

@@ -49,7 +49,9 @@ public enum OptionType {
/** A local file system path */ /** A local file system path */
PATH, PATH,
/** A string */ /** A string */
STRING; STRING,
/** No value */
VOID;
public String normalize(String value) { public String normalize(String value) {
return value; return value;
@@ -65,6 +67,7 @@ public enum OptionType {
throw new RuntimeException("Could not read " + cliOptionsPath, e); throw new RuntimeException("Could not read " + cliOptionsPath, e);
} }
return Stream.of(values) return Stream.of(values)
.filter(opt -> opt != VOID)
.sorted(Comparator.comparing(OptionType::name)) .sorted(Comparator.comparing(OptionType::name))
.map(env -> new DocumentedEnumEntry<>(env, props.getProperty(env.name()))); .map(env -> new DocumentedEnumEntry<>(env, props.getProperty(env.name())));
} }

View File

@@ -70,24 +70,40 @@ public class MvndHelpFormatter {
int indentPos = help.length() + indent.length(); int indentPos = help.length() + indent.length();
int lineEnd = help.length() + HelpFormatter.DEFAULT_WIDTH; int lineEnd = help.length() + HelpFormatter.DEFAULT_WIDTH;
spaces(help, HelpFormatter.DEFAULT_LEFT_PAD); spaces(help, HelpFormatter.DEFAULT_LEFT_PAD);
help final String property = env.getProperty();
.append("-D") if (property != null) {
.append(env.getProperty()) help
.append("=<") .append("-D")
.append(env.getType().name().toLowerCase(Locale.ROOT)) .append(property);
.append('>'); if (env.getType() != OptionType.VOID) {
help
.append("=<")
.append(env.getType().name().toLowerCase(Locale.ROOT))
.append('>');
}
}
final List<String> opts = env.getOptions(); final List<String> opts = env.getOptions();
if (!opts.isEmpty()) { if (!opts.isEmpty()) {
for (String opt : opts) { if (property != null) {
help help.append(';');
.append(',') }
.append(opt); boolean first = true;
for (String opt : opts) {
if (first) {
first = false;
} else {
help.append(',');
}
help.append(opt);
}
if (env.getType() != OptionType.VOID) {
help
.append(" <")
.append(env.getType().name().toLowerCase(Locale.ROOT))
.append('>');
} }
help
.append(" <")
.append(env.getType().name().toLowerCase(Locale.ROOT))
.append('>');
} }
help.append(' '); help.append(' ');

View File

@@ -20,7 +20,6 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.assertj.core.api.Assertions; import org.assertj.core.api.Assertions;
import org.mvndaemon.mvnd.common.DaemonInfo; import org.mvndaemon.mvnd.common.DaemonInfo;
import org.mvndaemon.mvnd.common.DaemonRegistry; import org.mvndaemon.mvnd.common.DaemonRegistry;