protected static getRequiredCredentialValuesQuestions()

in src/models/connectionCredentials.ts [123:196]


    protected static getRequiredCredentialValuesQuestions(
        credentials: IConnectionCredentials,
        promptForDbName: boolean,
        isPasswordRequired: boolean,
        defaultProfileValues?: IConnectionCredentials): IQuestion[] {

        let connectionStringSet: () => boolean = () => Boolean(credentials.connectionString);

        let questions: IQuestion[] = [
            // Server or connection string must be present
            {
                type: QuestionTypes.input,
                name: LocalizedConstants.serverPrompt,
                message: LocalizedConstants.serverPrompt,
                placeHolder: LocalizedConstants.serverPlaceholder,
                default: defaultProfileValues ? defaultProfileValues.host : undefined,
                shouldPrompt: (answers) => utils.isEmpty(credentials.host),
                validate: (value) => ConnectionCredentials.validateRequiredString(LocalizedConstants.serverPrompt, value),
                onAnswered: (value) => ConnectionCredentials.processServerOrConnectionString(value, credentials)
            },
            // Database name is not required, prompt is optional
            {
                type: QuestionTypes.input,
                name: LocalizedConstants.databasePrompt,
                message: LocalizedConstants.databasePrompt,
                placeHolder: LocalizedConstants.databasePlaceholder,
                default: defaultProfileValues ? defaultProfileValues.dbname : undefined,
                shouldPrompt: (answers) => !connectionStringSet() && promptForDbName,
                onAnswered: (value) => credentials.dbname = value
            },
            // Username must be present
            {
                type: QuestionTypes.input,
                name: LocalizedConstants.usernamePrompt,
                message: LocalizedConstants.usernamePrompt,
                placeHolder: LocalizedConstants.usernamePlaceholder,
                default: defaultProfileValues ? defaultProfileValues.user : undefined,
                shouldPrompt: (answers) => !connectionStringSet() && ConnectionCredentials.shouldPromptForUser(credentials),
                validate: (value) => ConnectionCredentials.validateRequiredString(LocalizedConstants.usernamePrompt, value),
                onAnswered: (value) => credentials.user = value
            },
            // Password may or may not be necessary
            {
                type: QuestionTypes.password,
                name: LocalizedConstants.passwordPrompt,
                message: LocalizedConstants.passwordPrompt,
                placeHolder: LocalizedConstants.passwordPlaceholder,
                shouldPrompt: (answers) => !connectionStringSet() && ConnectionCredentials.shouldPromptForPassword(credentials),
                validate: (value) => {
                    if (isPasswordRequired) {
                        return ConnectionCredentials.validateRequiredString(LocalizedConstants.passwordPrompt, value);
                    }
                    return undefined;
                },
                onAnswered: (value) => {
                    credentials.password = value;
                    if (typeof((<IConnectionProfile>credentials)) !== 'undefined') {
                        (<IConnectionProfile>credentials).emptyPasswordInput = utils.isEmpty(credentials.password);
                    }
                }
            },
            // Port
            {
                type: QuestionTypes.input,
                name: LocalizedConstants.portPrompt,
                message: LocalizedConstants.portPrompt,
                placeHolder: LocalizedConstants.portPlaceHolder,
                default: '5432',
                shouldPrompt: (answers) => !connectionStringSet() && ConnectionCredentials.shouldPromptForPort(credentials),
                onAnswered: (value) => credentials.port = value
            }
        ];
        return questions;
    }