Updating error message on number conversion to remind uses that Unix shell quoting can come into play. #91
This commit is contained in:
parent
5da84ae082
commit
745895d553
|
@ -19,20 +19,29 @@
|
||||||
*/
|
*/
|
||||||
package io.github.applecommander.acx.converter;
|
package io.github.applecommander.acx.converter;
|
||||||
|
|
||||||
|
import com.webcodepro.applecommander.util.Host;
|
||||||
import picocli.CommandLine.ITypeConverter;
|
import picocli.CommandLine.ITypeConverter;
|
||||||
|
|
||||||
/** Add support for "$801" and "0x801" instead of just decimal like 2049. */
|
/** Add support for "$801" and "0x801" instead of just decimal like 2049. */
|
||||||
public class IntegerTypeConverter implements ITypeConverter<Integer> {
|
public class IntegerTypeConverter implements ITypeConverter<Integer> {
|
||||||
@Override
|
@Override
|
||||||
public Integer convert(String value) {
|
public Integer convert(String value) {
|
||||||
if (value == null) {
|
try {
|
||||||
return null;
|
if (value == null) {
|
||||||
} else if (value.startsWith("$")) {
|
return null;
|
||||||
return Integer.valueOf(value.substring(1), 16);
|
} else if (value.startsWith("$")) {
|
||||||
} else if (value.startsWith("0x") || value.startsWith("0X")) {
|
return Integer.valueOf(value.substring(1), 16);
|
||||||
return Integer.valueOf(value.substring(2), 16);
|
} else if (value.startsWith("0x") || value.startsWith("0X")) {
|
||||||
} else {
|
return Integer.valueOf(value.substring(2), 16);
|
||||||
return Integer.valueOf(value);
|
} else {
|
||||||
|
return Integer.valueOf(value);
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
String msg = ex.getMessage();
|
||||||
|
if (Host.isLinux() || Host.isMacosx()) {
|
||||||
|
msg += " (check shell quoting if using '$')";
|
||||||
|
}
|
||||||
|
throw new NumberFormatException(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue