import chalk from 'chalk';
import { CLI_LOGGER, createJHipsterLogger } from '../lib/utils/logger.js';
export const CLI_NAME = 'begcode';
export const GENERATOR_NAME = 'generator-begcode';
const SUCCESS_MESSAGE = `Congratulations, BegCode execution is complete!
If you find BegCode useful consider sponsoring the project ${chalk.yellow('https://www.begcode.com/sponsors.html')}`;
const SPONSOR_MESSAGE = 'Thanks for using BegCode!';
export const logger = createJHipsterLogger({ namespace: CLI_LOGGER });
export const getCommand = (cmd, args = []) => {
    let cmdArgs;
    if (args.length > 0) {
        logger.debug('Arguments found');
        args = args.flat();
        cmdArgs = args.join(' ').trim();
        logger.debug(`cmdArgs: ${cmdArgs}`);
    }
    return `${cmd}${cmdArgs ? ` ${cmdArgs}` : ''}`;
};
export const doneFactory = (options = {}) => {
    const { successMsg = SUCCESS_MESSAGE, sponsorMsg = SPONSOR_MESSAGE, logger: log = logger } = options;
    return errorOrMsg => {
        if (errorOrMsg instanceof Error) {
            log.error(`ERROR! ${errorOrMsg.message}`);
            log.log(errorOrMsg);
        }
        else if (errorOrMsg) {
            log.error(`ERROR! ${errorOrMsg}`);
        }
        else if (successMsg) {
            log.log('');
            log.log(chalk.green.bold(successMsg));
            log.log('');
            log.log(chalk.cyan.bold(sponsorMsg));
        }
    };
};
export const done = doneFactory();
