# All files / src/systemTools prompt.js

92.77% Statements 77/83
74.51% Branches 38/51
100% Functions 6/6
98.31% Lines 58/59

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    783x
    3x
    3x
    3x

    3x

    22x
    11x
    11x
    1x

    1x
    1x

    10x

    37x
    37x
    37x
    37x
    37x
    37x
    37x

    37x
    37x
    37x
    32x
    480x
    480x
    480x
    480x

    5x
    5x
    6x
    6x
    6x
    6x
    6x
    6x
    6x

    37x
    37x
    37x
    37x
    37x
    37x
    3x

    3x
    2954x
    2954x
    2954x
    2950x
    2950x

    4x
    4x

    2954x
    2954x
    2118x
    836x
    832x

    2954x

    480x
     import chalk from 'chalk';
    import inquirer from 'inquirer';
    import { logWarning, logTask, rnvStatus, logEnd, logToSummary } from './logger';
    import Config from '../config';

    const highlight = chalk.grey.bold;

    export const inquirerPrompt = async (params) => {
        const c = Config.getConfig();
        const msg = params.logMessage || params.warningMessage;E
        if (c.program.ci) {
            throw msg || '--ci option does not allow prompts';
        }
        if (msEg && params.logMessage) logTask(msg, chalk.grey);
        if (msIg && params.warningMessage) logWarning(msg);
        const result = await inquirer.prompt(params);
        return result;
    };

    export const generateOptions = (inputData, isMultiChoice = false, mapping, renderMethod) => {
        let asString = '';
        const valuesAsObject = {};
        const valuesAsArray = [];
        const keysAsObject = {};
        const keysAsArray = [];
        const isArray = Array.isArray(inputData);

        const output = {};
        const renderer = renderMethod || _generateOptionString;
        if (isArray) {
            inputData.map((v, i) => {
                asString += renderer(i, v, mapping, v);
                valuesAsArray.push(v);
          E      if (!mapping) keysAsArray.push(v);
          E      if (!mapping) valuesAsObject[v] = v;
            });
        } else {
            let i = 0;
            for (const k in inputData) {
                const v = inputData[k];
                asString += renderer(i, v, mapping, k);
                keysAsArray.push(k);
                keysAsObject[k] = true;
                valuesAsObject[k] = v;
                valuesAsArray.push(v);
                i++;
            }
        }
        output.keysAsArray = keysAsArray.sort(_sort);
        output.valuesAsArray = valuesAsArray.sort(_sort);
        output.keysAsObject = keysAsObject;
        output.valuesAsObject = valuesAsObject;
        output.asString = asString;
        return output;
    };

    const _sort = (a, b) => {
        let aStr = '';
        let bStr = '';
        if (typeof a === 'string') {
            aStr = a.toLowerCase();
            bStr = b.toLowerCase();
        } else {
        I    if (a && a.name) aStr = a.name.toLowerCase();
        I    if (b && b.name) bStr = b.name.toLowerCase();
        }

        let com = 0;
        if (aStr > bStr) {
            com = 1;
        } else if (aStr < bStr) {
            com = -1;
        }
        return com;
    };

    const _generateOptionString = (i, obj, mapping, defaultVal) => ` [${highlight(i + 1)}]> ${highlight(mapping ? '' : defaultVal)} \n`;