private boolean batch;
private String file = null;
private String command;
public ClientConfig(String[] args) throws IOException {
Properties shellCfg = new Properties(new File(System.getProperty("karaf.etc"), "org.apache.karaf.shell.cfg"));
host = shellCfg.getProperty("sshHost", "localhost");
port = Integer.parseInt(shellCfg.getProperty("sshPort", "8101"));
level = SimpleLogger.WARN;
retryAttempts = 0;
retryDelay = 2;
batch = false;
file = null;
user = null;
password = null;
StringBuilder commandBuilder = new StringBuilder();
for (int i = 0; i < args.length; i++) {
if (args[i].charAt(0) == '-') {
if (args[i].equals("-a")) {
port = Integer.parseInt(args[++i]);
} else if (args[i].equals("-h")) {
host = args[++i];
} else if (args[i].equals("-u")) {
user = args[++i];
} else if (args[i].equals("-v")) {
level++;
} else if (args[i].equals("-r")) {
retryAttempts = Integer.parseInt(args[++i]);
} else if (args[i].equals("-d")) {
retryDelay = Integer.parseInt(args[++i]);
} else if (args[i].equals("-b")) {
batch = true;
} else if (args[i].equals("-f")) {
file = args[++i];
} else if (args[i].equals("--help")) {
showHelp();
} else {
System.err.println("Unknown option: " + args[i]);
System.err.println("Run with --help for usage");
System.exit(1);
}
} else {
commandBuilder.append(args[i]);
commandBuilder.append(' ');
}
}
command = commandBuilder.toString();
Properties usersCfg = new Properties(new File(System.getProperty("karaf.etc") + "/users.properties"));
if (!usersCfg.isEmpty()) {
if (user == null) {
user = (String) usersCfg.keySet().iterator().next();
}
password = (String) usersCfg.getProperty(user);
if (password != null && password.contains(ROLE_DELIMITER)) {
password = password.substring(0, password.indexOf(ROLE_DELIMITER));
}
}