I'm currently using import org.apache.commons.cli
Let's say I have a command line parser like:
private static commandLineParser(Options options, String[] strings) throws ParseException {
options.addOption("u", "username", true, "Login Username");
options.addOption("p", "password", true, "Login Password");
// Some other options
CommandLineParser parser = new DefaultParser();
return parser.parse(options, strings);
}
and my main function:
public static void main(String args[]) {
Options options = new Options();
CommandLine cmd = null;
try {
cmd = commandLineParser(options, args);
//some helpFormatter stuff to make the options human-readable
} catch (ParseException e) {
e.printStackTrace();
System.exit(2);
}
//calling my main program
doSomething(cmd)
}
For obvious reasons I want to omit the password from the command line, since it would be visible in both the history and the process list. However my main program expects an object of type CommandLine. Is there any way to parse a password with a similar behaviour as console.readPassword() or even call this function and add it to the CommandLine object?
I've already tried to search for a combination of commons-cli and password parsing but was not successful.