private String constructCmdUrl(String url, String user, String driver,
      boolean stripPasswd)  {
    StringBuilder command = new StringBuilder("!connect ");
    command.append(url);
    //if the url does not have a database name add the trailing '/'
    if(isTrailingSlashNeeded(url)) {
      command.append('/');
    }
    command.append(';');
    // if the username is not already available in the URL add the one provided
    if (Utils.parsePropertyFromUrl(url, JdbcConnectionParams.AUTH_USER) == null) {
      command.append(JdbcConnectionParams.AUTH_USER);
      command.append('=');
      command.append((user == null || user.length() == 0 ? "''" : user));
    }
    if (stripPasswd) {
      // if password is available in url it needs to be striped
      int startIndex = command.indexOf(JdbcConnectionParams.AUTH_PASSWD + "=")
          + JdbcConnectionParams.AUTH_PASSWD.length() + 2;
      if(startIndex != -1) {
        int endIndex = command.toString().indexOf(";", startIndex);
        command.replace(startIndex, (endIndex == -1 ? command.length() : endIndex),
          BeeLine.PASSWD_MASK);
      }
    }
    // if the driver is not already available in the URL add the one provided
    if (Utils.parsePropertyFromUrl(url, JdbcConnectionParams.PROPERTY_DRIVER) == null
        && driver != null) {
      command.append(';');
      command.append(JdbcConnectionParams.PROPERTY_DRIVER);
      command.append("=");
      command.append(driver);
    }
    return command.toString();
  }
This is an internal method used to create !connect command when -p option is used without
providing the password on the command line. Connect command returned should be ; separated
key-value pairs along with the url. We cannot use space separated !connect url user [password]
[driver] here since both password and driver are optional and there would be no way to
distinguish if the last string is password or driver

@param url connection url passed using -u argument on the command line
@param user username passed through command line
@param driver driver passed through command line -d option
@param stripPasswd when set to true generates a !connect command which strips the password for
         logging purposes
@return !connect command
beeline/src/java/org/apache/hive/beeline/BeeLine.java