public ClientConfig()

in client/src/main/java/org/apache/karaf/client/ClientConfig.java [49:214]


    public ClientConfig(String[] args) throws Exception {
        File karafEtc = new File(System.getProperty("karaf.etc"));
        PropertiesLoader.loadSystemProperties(new File(karafEtc, "system.properties"));
        Properties configProps = PropertiesLoader.loadConfigProperties(new File(karafEtc, "config.properties"));
        configuration = loadProps(new File(karafEtc, "org.apache.karaf.shell.cfg"), configProps);

        host = getString("sshHost", "localhost");
        if (host.contains("0.0.0.0")) {
            host = "localhost";
        }
        port = getInt("sshPort", 8101);
        level = getInt("logLevel", 0);
        retryAttempts = 0;
        retryDelay = 2;
        idleTimeout = getLong("sshIdleTimeout", 1800000L);
        batch = false;
        file = null;
        user = null;
        password = null;
        StringBuilder commandBuilder = new StringBuilder();
        boolean endOfOptionsMarkerReached = false;
        
        for (int i = 0; i < args.length; i++) {
            if (!endOfOptionsMarkerReached && args[i].charAt(0) == '-') {
                switch (args[i]) {
                    case "-a":
                        if (args.length <= ++i) {
                            System.err.println("miss the port");
                            System.exit(1);
                        } else {
                            port = Integer.parseInt(args[i]);
                        }
                        break;
                    case "-h":
                        if (args.length <= ++i) {
                            System.err.println("miss the host");
                            System.exit(1);
                        } else {
                            host = args[i];
                        }
                        break;
                    case "-u":
                        if (args.length <= ++i) {
                            System.err.println("miss the user");
                            System.exit(1);
                        } else {
                            user = args[i];
                            interactiveMode = true;
                            password = null;//get chance to input the password with interactive way
                        }
                        break;
                    case "-v":
                        level++;
                        break;
                    case "-l":
                        if (args.length <= ++i) {
                            System.err.println("miss the log level");
                            System.exit(1);
                        } else {
                            int levelValue = Integer.parseInt(args[i]);
                            if (levelValue < 0 || levelValue > 4) {
                                System.err.println("log level can only be 0, 1, 2, 3, or 4");
                                System.exit(1);
                            } else {
                                level = levelValue;
                            }
                        }
                        break;
                    case "-r":
                        if (args.length <= ++i) {
                            System.err.println("miss the attempts");
                            System.exit(1);
                        } else {
                            retryAttempts = Integer.parseInt(args[i]);
                        }

                        break;
                    case "-p":
                        if (args.length <= ++i) {
                            System.err.println("miss the password");
                            System.exit(1);
                        } else {
                            password = args[i];
                            interactiveMode = false;
                            inputPassword = true;
                        }
                        break;
                    case "-d":
                        if (args.length <= ++i) {
                            System.err.println("miss the delay in seconds");
                            System.exit(1);
                        } else {
                            retryDelay = Integer.parseInt(args[i]);
                        }
                        break;
                    case "-b":
                        batch = true;
                        break;
                    case "-f":
                        if (args.length <= ++i) {
                            System.err.println("miss the commands file");
                            System.exit(1);
                        } else {
                            file = args[i];
                        }
                        break;
                    case "-k":
                        if (args.length <= ++i) {
                            System.err.println("miss the key file");
                            System.exit(1);
                        } else {
                            keyFile = args[i];
                        }
                        break;
                    case "-t":
                        if (args.length <= ++i) {
                            System.err.println("miss the idle timeout");
                            System.exit(1);
                        } else {
                            idleTimeout = Long.parseLong(args[i]);
                        }
                        break;
                    case "--help":
                        showHelp();
                        break;
                    case "--":
                        endOfOptionsMarkerReached = true;
                        break;
                    default:
                        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();

        File userPropertiesFile = new File(karafEtc,"users.properties");
        if (userPropertiesFile.exists()) {
	        Map<String, String> usersCfg = PropertiesLoader.loadPropertiesFile(userPropertiesFile.toURI().toURL(), false);
	        if (!usersCfg.isEmpty()) {
	            Set<String> users = new LinkedHashSet<>();
	            for (String user : usersCfg.keySet()) {
	                if (!user.startsWith(GROUP_PREFIX)) {
	                    users.add(user);
	                }
	            }
	            if (user == null) {
	                if (users.iterator().hasNext()) {
	                    user = users.iterator().next();
	                }
	            }
	            if (interactiveMode && !inputPassword) {
	                password = null;
	            } else if (!inputPassword) {
	                password = usersCfg.get(user);
	                if (password != null && password.contains(ROLE_DELIMITER)) {
	                    password = password.substring(0, password.indexOf(ROLE_DELIMITER));
	                }
	            }
	        }
        }
    }