Skip to content

Commit 5e453f2

Browse files
authored
Revert "[remkop#802][remkop#1284] DOC: more javadoc for interactive option echo and prompt"
This reverts commit e358448.
1 parent 90077f3 commit 5e453f2

File tree

1 file changed

+51
-56
lines changed

1 file changed

+51
-56
lines changed

src/main/java/picocli/CommandLine.java

Lines changed: 51 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3883,13 +3883,11 @@ public enum ScopeType {
38833883
Class<? extends Iterable<String>> completionCandidates() default NoCompletionCandidates.class;
38843884

38853885
/**
3886-
* Set {@code interactive=true} to make this option prompt the end user for a value (like a password).
3886+
* Set {@code interactive=true} if this option will prompt the end user for a value (like a password).
38873887
* Only supported for single-value options and {@code char[]} arrays (no collections, maps or other array types).
3888-
* When running on Java 6 or greater and {@link Option#echo() echo = false} (the default),
3889-
* this will use the {@link Console#readPassword()} API to get a value without echoing input to the console,
3890-
* otherwise it will simply read a value from {@code System.in}.
3888+
* When running on Java 6 or greater and echo attribute is false, this will use the {@link Console#readPassword()} API to get a value without echoing input to the console.
38913889
* <p>
3892-
* For passwords, best security practice is to use type {@code char[]} instead of {@code String}, and to to null out the array after use.
3890+
* Best security practice is to use type {@code char[]} instead of {@code String}, and to to null out the array after use.
38933891
* </p><p>
38943892
* When defined with {@code arity = "0..1"}, the option can also take a value from the command line.
38953893
* (The user will still be prompted if no option parameter was specified on the command line.)
@@ -3900,20 +3898,20 @@ public enum ScopeType {
39003898
*/
39013899
boolean interactive() default false;
39023900

3903-
/** Use this attribute to control whether user input for an interactive option is echoed to the console or not.
3904-
* If {@code echo = true}, the user input is echoed to the console.
3905-
* This attribute is ignored when {@code interactive = false} (the default).
3906-
* @return whether the user input for an interactive option should be echoed to the console or not
3907-
* @see OptionSpec#echo()
3908-
* @since 4.6 */
3901+
/**
3902+
* Use this attribute to control a user input is echo-ed to the console or not. If {@code echo=true}, a input is echo-ed to the console.
3903+
* This attribute is ignored when interactive attribute is false.
3904+
* @return whether the user input is echo-ed to the console or not
3905+
* @since 4.X
3906+
*/
39093907
boolean echo() default false;
39103908

3911-
/** Use this attribute to customize the text displayed to the end user for an interactive option when asking for user input.
3912-
* When omitted, the displayed text is derived from the option name and the first description line.
3913-
* This attribute is ignored when {@code interactive = false} (the default).
3914-
* @return the text to display to the end user for an interactive option when asking for user input
3915-
* @see OptionSpec#prompt()
3916-
* @since 4.6 */
3909+
/**
3910+
* Use this attribute to customize the text displayed to the end user for an interactive option.
3911+
* This attribute is ignored when interactive attribute is false.
3912+
* @return text will be displayed to the end user
3913+
* @since 4.X
3914+
*/
39173915
String prompt() default "";
39183916

39193917
/** ResourceBundle key for this option. If not specified, (and a ResourceBundle {@linkplain Command#resourceBundle() exists for this command}) an attempt
@@ -4176,29 +4174,26 @@ public enum ScopeType {
41764174
/**
41774175
* Set {@code interactive=true} if this positional parameter will prompt the end user for a value (like a password).
41784176
* Only supported for single-value positional parameters (not arrays, collections or maps).
4179-
* When running on Java 6 or greater and {@link Option#echo() echo = false} (the default),
4180-
* this will use the {@link Console#readPassword()} API to get a value without echoing input to the console,
4181-
* otherwise it will simply read a value from {@code System.in}.
4177+
* When running on Java 6 or greater and echo attribute is false, this will use the {@link Console#readPassword()} API to get a value without echoing input to the console.
41824178
* @return whether this positional parameter prompts the end user for a value to be entered on the command line
41834179
* @since 3.5
41844180
*/
41854181
boolean interactive() default false;
41864182

4187-
/** Use this attribute to control whether user input for an interactive positional parameter is echoed to the console or not.
4188-
* If {@code echo = true}, the user input is echoed to the console.
4189-
* This attribute is ignored when {@code interactive = false} (the default).
4190-
* @return whether the user input for an interactive positional parameter should be echoed to the console or not
4191-
* @see PositionalParamSpec#echo()
4192-
* @since 4.6 */
4183+
/**
4184+
* Use this attribute to control a user input is echo-ed to the console or not. If {@code echo=true}, a input is echo-ed to the console.
4185+
* This attribute is ignored when interactive attribute is false.
4186+
* @return whether the user input is echo-ed to the console or not
4187+
* @since 4.X
4188+
*/
41934189
boolean echo() default false;
41944190

4195-
/** Use this attribute to customize the text displayed to the end user for an interactive positional parameter when asking for user input.
4196-
* When omitted, the displayed text is derived from the positional parameter's
4197-
* position (index) and the first description line.
4198-
* This attribute is ignored when {@code interactive = false} (the default).
4199-
* @return the text to display to the end user for an interactive positional parameter when asking for user input
4200-
* @see PositionalParamSpec#prompt()
4201-
* @since 4.6 */
4191+
/**
4192+
* Use this attribute to customize the text displayed to the end user for an interactive option.
4193+
* This attribute is ignored when interactive attribute is false.
4194+
* @return text will be displayed to the end user
4195+
* @since 4.X
4196+
*/
42024197
String prompt() default "";
42034198

42044199
/** ResourceBundle key for this option. If not specified, (and a ResourceBundle {@linkplain Command#resourceBundle() exists for this command}) an attempt
@@ -8435,18 +8430,13 @@ public boolean required() {
84358430
return required && defaultValue() == null && defaultValueFromProvider() == null;
84368431
}
84378432
/** Returns whether this option will prompt the user to enter a value on the command line.
8438-
* @see Parameters#interactive()
84398433
* @see Option#interactive() */
84408434
public boolean interactive() { return interactive; }
8441-
/** Returns whether the user input is echoed to the console or not for an interactive option or positional parameter when asking for user input.
8442-
* @see Option#echo()
8443-
* @see Parameters#echo()
8444-
* @since 4.6 */
8435+
/** Returns whether the user input is echo-ed to the console or not.
8436+
* @see Option#echo() */
84458437
public boolean echo() { return echo; }
8446-
/** Returns the text displayed to the end user for an interactive option or positional parameter when asking for user input.
8447-
* @see Option#prompt()
8448-
* @see Parameters#prompt()
8449-
* @since 4.6 */
8438+
/** Returns the text displayed to the end user for an interactive option.
8439+
* @see Option#prompt() */
84508440
public String prompt() { return prompt; }
84518441

84528442
/** Returns the description of this option or positional parameter, after all variables have been rendered,
@@ -9122,15 +9112,11 @@ private static String inferLabel(String label, String fieldName, ITypeInfo typeI
91229112
/** Returns whether this option prompts the user to enter a value on the command line.
91239113
* @see Option#interactive() */
91249114
public boolean interactive() { return interactive; }
9125-
/** Returns whether the user input is echoed to the console or not for an interactive option or positional parameter when asking for user input.
9126-
* @see Option#echo()
9127-
* @see Parameters#echo()
9128-
* @since 4.6 */
9115+
/** Returns whether the user input is echo-ed to the console or not.
9116+
* @see Option#echo() */
91299117
public boolean echo() { return echo; }
9130-
/** Returns the text displayed to the end user for an interactive option or positional parameter when asking for user input.
9131-
* @see Option#prompt()
9132-
* @see Parameters#prompt()
9133-
* @since 4.6 */
9118+
/** Returns the text displayed to the end user for an interactive option.
9119+
* @see Option#prompt() */
91349120
public String prompt() { return prompt; }
91359121

91369122
/** Returns the description of this option, used when generating the usage documentation.
@@ -9259,10 +9245,10 @@ private static String inferLabel(String label, String fieldName, ITypeInfo typeI
92599245
/** Sets whether this option prompts the user to enter a value on the command line, and returns this builder. */
92609246
public T interactive(boolean interactive) { this.interactive = interactive; return self(); }
92619247

9262-
/** Sets whether the user input is echoed to the console or not for an interactive option or positional parameter. */
9248+
/** Sets whether the user input is echo-ed to the console or not. */
92639249
public T echo(boolean echo) { this.echo = echo; return self(); }
92649250

9265-
/** Sets the text displayed to the end user for an interactive option or positional parameter when asking for user input. */
9251+
/** Sets the text displayed to the end user for an interactive option. */
92669252
public T prompt(String prompt) { this.prompt = prompt; return self(); }
92679253

92689254
/** Sets the description of this option, used when generating the usage documentation, and returns this builder.
@@ -13446,7 +13432,7 @@ private int applyValueToSingleValuedField(ArgSpec argSpec,
1344613432
consumed = 0;
1344713433
}
1344813434
}
13449-
// if argSpec is interactive, we may need to read the password from the console:
13435+
// if argSpec is interactive and echo is false, we may need to read the password from the console:
1345013436
// - if arity = 0 : ALWAYS read from console
1345113437
// - if arity = 0..1: ONLY read from console if user specified a non-option value
1345213438
if (argSpec.interactive() && (arity.max == 0 || !optionalValueExists)) {
@@ -13846,8 +13832,8 @@ private int addUserInputToList(ArgSpec argSpec, List<Object> result, int consume
1384613832
char[] input = readUserInput(argSpec);
1384713833
String inputString = new String(input);
1384813834
if (tracer.isInfo()) {
13849-
String value = argSpec.echo() ? input + " (interactive value)" : "*** (masked interactive value)";
13850-
tracer.info("Adding %s to %s for %s on %s%n", value, argSpec.toString(), argDescription, argSpec.scopeString());
13835+
tracer.info("Adding %s to %s for %s on %s%n",
13836+
getLoggableMaskedInteractiveValue(argSpec, inputString), argSpec.toString(), argDescription, argSpec.scopeString());
1385113837
}
1385213838
String maskedValue = getMaskedValue(argSpec, inputString);
1385313839
parseResultBuilder.addStringValue(argSpec, maskedValue);
@@ -13861,6 +13847,13 @@ private int addUserInputToList(ArgSpec argSpec, List<Object> result, int consume
1386113847
consumed++;
1386213848
return consumed;
1386313849
}
13850+
private String getLoggableMaskedInteractiveValue(ArgSpec argSpec, String input) {
13851+
if (argSpec.echo()) {
13852+
return input + " (interactive value)";
13853+
} else {
13854+
return "*** (masked interactive value)";
13855+
}
13856+
}
1386413857
private String getMaskedValue(ArgSpec argSpec, String input) {
1386513858
return argSpec.echo() ? input : "***";
1386613859
}
@@ -14098,7 +14091,9 @@ private boolean assertNoMissingParameters(ArgSpec argSpec, Range arity, Stack<St
1409814091

1409914092
char[] readUserInput(ArgSpec argSpec) {
1410014093
String name = argSpec.isOption() ? ((OptionSpec) argSpec).longestName() : "position " + position;
14101-
String prompt = !empty(argSpec.prompt()) ? argSpec.prompt() : String.format("Enter value for %s (%s): ", name, str(argSpec.description(), 0));
14094+
String prompt = argSpec.prompt() != null && argSpec.prompt().length() != 0 ?
14095+
argSpec.prompt() :
14096+
String.format("Enter value for %s (%s): ", name, str(argSpec.description(), 0));
1410214097
try {
1410314098
if (tracer.isDebug()) {tracer.debug("Reading value for %s from console...%n", name);}
1410414099
char[] result = argSpec.echo() ? readUserInputWithEchoing(prompt) : readPassword(prompt);

0 commit comments

Comments
 (0)