Skip to content

Commit 2b0105b

Browse files
committed
Correct formatting of usage helpers for undocumented.
1 parent 4c3410b commit 2b0105b

File tree

4 files changed

+53
-32
lines changed

4 files changed

+53
-32
lines changed

src/main/java/uk/co/spudsoft/params4j/ConfigurationProperty.java

+45-20
Original file line numberDiff line numberDiff line change
@@ -225,22 +225,35 @@ public boolean equals(Object obj) {
225225
*
226226
*/
227227
public void appendUsage(StringBuilder builder, int maxNameLen) {
228-
builder.append(" ")
229-
.append(name)
230-
.append(" ".repeat(maxNameLen + 1 - name.length()))
231-
.append(comment)
232-
.append('\n');
228+
229+
maxNameLen += 6;
230+
231+
builder.append(" ")
232+
.append(name);
233+
if (undocumented) {
234+
builder.append(".<***>");
235+
}
236+
builder.append(" ".repeat(maxNameLen + 1 - name.length() - (undocumented ? 6 : 0)))
237+
.append(comment)
238+
.append('\n');
233239

234-
String typeName = type.getSimpleName();
235-
builder.append(" ")
236-
.append(typeName);
240+
String typeName = type.getSimpleName();
241+
builder.append(" ")
242+
.append(typeName);
243+
244+
if (defaultValue != null) {
245+
builder.append(" ".repeat(typeName.length() + 10 > maxNameLen ? 1 : maxNameLen - typeName.length() - 3))
246+
.append("default: ")
247+
.append(defaultValue);
248+
}
249+
if (undocumented) {
250+
builder.append(" ".repeat(typeName.length() + 10 > maxNameLen ? 1 : maxNameLen - typeName.length() - 3))
251+
.append("This parameter is undocumented, consult the source for ")
252+
.append(type)
253+
.append(" for details of the values for <***>");
237254

238-
if (defaultValue != null) {
239-
builder.append(" ".repeat(typeName.length() + 4 > maxNameLen ? 1 : maxNameLen - typeName.length() - 3))
240-
.append("default: ")
241-
.append(defaultValue);
242-
}
243-
builder.append('\n');
255+
}
256+
builder.append("\n\n");
244257
}
245258

246259
/**
@@ -266,7 +279,7 @@ public void appendEnv(StringBuilder builder, int maxNameLen, String prefixStrip,
266279
prefixAdd = "";
267280
}
268281

269-
maxNameLen = maxNameLen - prefixStrip.length() + prefixAdd.length() + 1;
282+
maxNameLen = maxNameLen - prefixStrip.length() + prefixAdd.length() + 7;
270283

271284
String envVarName = name;
272285
if (envVarName.startsWith(prefixStrip)) {
@@ -279,21 +292,33 @@ public void appendEnv(StringBuilder builder, int maxNameLen, String prefixStrip,
279292
envVarName = envVarName.toUpperCase(Locale.ROOT);
280293

281294
builder.append(" ")
282-
.append(envVarName)
283-
.append(" ".repeat(maxNameLen + 1 - envVarName.length()))
295+
.append(envVarName);
296+
if (undocumented) {
297+
builder.append("_<***>");
298+
}
299+
builder.append(" ".repeat(maxNameLen + 1 - envVarName.length() - (undocumented ? 6 : 0)))
284300
.append(comment)
285301
.append('\n');
286302

287303
String typeName = type.getSimpleName();
288304
builder.append(" ")
289305
.append(typeName);
290-
306+
291307
if (defaultValue != null) {
292-
builder.append(" ".repeat(typeName.length() + 4 > maxNameLen ? 1 : maxNameLen - typeName.length() - 3))
308+
builder.append(" ".repeat(typeName.length() + 10 > maxNameLen ? 1 : maxNameLen - typeName.length() - 3))
293309
.append("default: ")
294310
.append(defaultValue);
295311
}
296-
builder.append('\n');
312+
313+
if (undocumented) {
314+
builder.append(" ".repeat(typeName.length() + 10 > maxNameLen ? 1 : maxNameLen - typeName.length() - 3))
315+
.append("This parameter is undocumented, consult the source for ")
316+
.append(type)
317+
.append(" for details of the values for <***>");
318+
319+
}
320+
321+
builder.append("\n\n");
297322
}
298323
}
299324

src/main/java/uk/co/spudsoft/params4j/Params4J.java

+4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ static <P> Params4JFactory<P> factory() {
6060
* @param defaultInstance An instance of the class to be examined, preloaded with default values.
6161
* @param prefix The prefix to be prepended to any determined property names to match the prefix specified in (for example) the CommandLineArgumentsGatherer.
6262
* @param terminalClasses List of regular expressions used to identify properties that are of terminal types - if the class is terminal it should be settable by Jackson from a single string value.
63+
* Examples of built-in terminal classes include java.time.LocalDateTime and java.time.Duration.
64+
* Terminal classes are documented, but their internals are not.
6365
* @param undocumentedClasses List of regular expressions used to identify properties that are of undocumented types - if the class is undocumented it will not be traversed further despite not being settable by Jackson.
66+
* Undocumented classes cannot be set directly and their internal properties are not output in generated documentation (usually because they haven't been processed by the JavadocCapturer).
67+
* There are no built-in undocumented classes, but a typical example of a class that should be undocumented is VertxOptions.
6468
* @return A list of properties that can be set.
6569
*/
6670
List<ConfigurationProperty> getDocumentation(P defaultInstance, String prefix, List<Pattern> terminalClasses, List<Pattern> undocumentedClasses);

src/main/java/uk/co/spudsoft/params4j/impl/Params4JImpl.java

+2-10
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,7 @@ private void changeNotificationHandler() {
259259
}
260260
}
261261

262-
private static boolean canBeEnvVar(String propName, Class<?> type, boolean undocumented) {
263-
logger.debug("{}/{}/{}", propName, type.getPackageName(), undocumented);
264-
if (type.isArray()) {
265-
return false;
266-
}
267-
if (undocumented) {
268-
String packageName = type.getPackageName();
269-
return "java.time".equals(packageName);
270-
}
262+
private static boolean canBeEnvVar(String propName) {
271263
if (propName.contains("[") || propName.contains("]")) {
272264
return false;
273265
}
@@ -514,7 +506,7 @@ private void outputTerminalField(
514506
}
515507
}
516508
ConfigurationProperty prop = ConfigurationProperty.builder()
517-
.canBeEnvVar(canBeEnvVar(propName, type, undocumented))
509+
.canBeEnvVar(canBeEnvVar(propName))
518510
.undocumented(undocumented)
519511
.comment(comment)
520512
.defaultValue(defaultValue == null ? null : defaultValue.toString())

src/test/resources/commentcap-expected.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
}, {
2424
"type": "uk.co.spudsoft.params4j.impl.HtmlAnchorElement",
2525
"name": "--alien",
26-
"canBeEnvVar": false,
26+
"canBeEnvVar": true,
2727
"undocumented": true,
2828
"comment": "alien value that cannot be documented further in this codebase",
2929
"defaultValue": null
3030
}, {
3131
"type": "uk.co.spudsoft.params4j.impl.HtmlAnchorElement",
3232
"name": "--documentedAlien",
33-
"canBeEnvVar": false,
33+
"canBeEnvVar": true,
3434
"undocumented": true,
3535
"comment": "configure the alien properties as documented at https://docs.oracle.com/en/java/javase/17/docs/api/jdk.xml.dom/org/w3c/dom/html/HTMLAnchorElement.html",
3636
"defaultValue": null

0 commit comments

Comments
 (0)