<commit_before>require('babel-polyfill');
require('regenerator-runtime');

import chalk from 'chalk';
import ms from 'ms';

import { prompt as ask } from 'inquirer';
import { config } from '../extra/config';
import { clearSettings, errorHandler, highlightJSON, printBlock, pathFixer } from '../extra/utils';


export default async function settings([action, target]) {
	const questions = [];

	if (action) action = action.toString().toLowerCase();
	if (target) target = target.toString().toLowerCase();

	const _directory = generateQuestion('_directory', 'Default download path:', {
		default: config.get('directory'),
		filter: input => pathFixer(input)
	});

	const _askForLike = generateQuestion('_askForLike', 'Prompt to like the downloaded photo after download?', {
		type: 'confirm',
		default: config.get('askForLike')
	});

	const _askForCollection = generateQuestion('_askForCollection', 'Prompt to add the downloaded photo to a collection?', {
		type: 'confirm',
		default: config.get('askForCollection')
	});

	const _userFolder = generateQuestion(
		'_userFolder',
		'Do you want store photos by username?', {
			default: config.get('userFolder'),
			type: 'confirm'
		}
	);

	const _updateInterval = generateQuestion('_updateInterval', 'Set the "pic of the day" update interval', { default: ms(1000 * 60 * 30), });
	// config.has('pic-of-the-day') ? config.get('pic-of-the-day').date.delay : ms()

	switch (action) {
	case 'get':
		if (target && target.toLowerCase() == 'picoftheday') {
			target = 'pic-of-the-day';
		}

		const settings = config.get(); //target ? config.get(target) : config.get();

		if (settings['pic-of-the-day'].date.delay) {
			settings['pic-of-the-day'].date.delay = ms(settings['pic-of-the-day'].date.delay);
		}

		settings.picOfTheDay = settings['pic-of-the-day'];
		settings.settingsPath = config.path;

		delete settings['keys'];
		delete settings['user'];
		delete settings['pic-of-the-day'];

		if (!settings || (target && !settings[target])) {
			return printBlock(chalk `Settings key: "{cyan ${target}}" {red {bold NOT} available}.`);
		}

		if (settings[target]) {
			let o = {};

			o[target] = settings[target];

			return printBlock(chalk `{bold {bgYellow {black SETTINGS}}}\n`, highlightJSON(o));
		}

		printBlock(chalk `{bold {bgYellow {black SETTINGS}}}\n`, highlightJSON(settings));
		break;
	case 'clear':
	case 'reset':
	case 'restore':
		ask([generateQuestion('confirm', chalk `Are you sure? This action is {underline NOT reversable}!`, { type: 'confirm', default: false })])
			.then(async ({ confirm }) => {
				if (confirm) {
					await clearSettings();
					printBlock(chalk `{yellow Settings Restored!}`);
				} else {
					printBlock(chalk `{red {bold Operation aborted!}}`);
				}
			})
			.catch(error => {
				errorHandler(error);
			});
		break;

	case 'set':
	default:
		switch (target) {
		case 'directory':
		case 'dir':
			questions.push(_directory);
			break;
		case 'user':
		case 'user-folder':
		case 'userFolder':
		case 'groups':
			questions.push(_userFolder);
			break;
		case 'like':
		case 'askforlike':
			questions.push(_askForLike);
			break;
		case 'collection':
		case 'askforcollection':
			questions.push(_askForCollection);
			break;<commit_msg>fixed --day flag, again<commit_after>require('babel-polyfill');
require('regenerator-runtime');

import frun from 'first-run';

import chalk from 'chalk';
import ms from 'ms';

import { prompt as ask } from 'inquirer';
import { config } from '../extra/config';
import { clearSettings, errorHandler, highlightJSON, printBlock, pathFixer } from '../extra/utils';


export default async function settings([action, target]) {
	const questions = [];

	if (action) action = action.toString().toLowerCase();
	if (target) target = target.toString().toLowerCase();

	const _directory = generateQuestion('_directory', 'Default download path:', {
		default: config.get('directory'),
		filter: input => pathFixer(input)
	});

	const _askForLike = generateQuestion('_askForLike', 'Prompt to like the downloaded photo after download?', {
		type: 'confirm',
		default: config.get('askForLike')
	});

	const _askForCollection = generateQuestion('_askForCollection', 'Prompt to add the downloaded photo to a collection?', {
		type: 'confirm',
		default: config.get('askForCollection')
	});

	const _userFolder = generateQuestion(
		'_userFolder',
		'Do you want store photos by username?', {
			default: config.get('userFolder'),
			type: 'confirm'
		}
	);

	const _updateInterval = generateQuestion('_updateInterval', 'Set the "pic of the day" update interval', { default: ms(1000 * 60 * 30), });


	switch (action) {
	case 'get':
		if (target && target.toLowerCase() == 'picoftheday') {
			target = 'pic-of-the-day';
		}

		const settings = config.get(); //target ? config.get(target) : config.get();

		if (settings['pic-of-the-day'].date.delay) {
			settings['pic-of-the-day'].date.delay = ms(settings['pic-of-the-day'].date.delay);
		}

		settings.picOfTheDay = settings['pic-of-the-day'];
		settings.settingsPath = config.path;

		delete settings['keys'];
		delete settings['user'];
		delete settings['pic-of-the-day'];

		if (!settings || (target && !settings[target])) {
			return printBlock(chalk `Settings key: "{cyan ${target}}" {red {bold NOT} available}.`);
		}

		if (settings[target]) {
			let o = {};

			o[target] = settings[target];

			return printBlock(chalk `{bold {bgYellow {black SETTINGS}}}\n`, highlightJSON(o));
		}

		printBlock(chalk `{bold {bgYellow {black SETTINGS}}}\n`, highlightJSON(settings));
		break;
	case 'clear':
	case 'reset':
	case 'restore':
		ask([generateQuestion('confirm', chalk `Are you sure? This action is {underline NOT reversable}!`, { type: 'confirm', default: false })])
			.then(async ({ confirm }) => {
				if (confirm) {
					frun.clear();

					await clearSettings();

					printBlock(chalk `{yellow Settings Restored!}`);
				} else {
					printBlock(chalk `{red {bold Operation aborted!}}`);
				}
			})
			.catch(error => {
				errorHandler(error);
			});
		break;

	case 'set':
	default:
		switch (target) {
		case 'directory':
		case 'dir':
			questions.push(_directory);
			break;
		case 'user':
		case 'user-folder':
		case 'userFolder':
		case 'groups':
			questions.push(_userFolder);
			break;
		case 'like':
		case 'askforlike':
			questions.push(_askForLike);
			break;
		case 'collection':
		case 'askforcollection':
			questions.push(_askForCollection);
			break;
{'fraction_non_alphanumeric': 0.166589183325585, 'fraction_numerical': 0.002479466914613358, 'mean_word_length': 4.303204601479047, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '780147', 'n_tokens_mistral': 2287, 'n_tokens_neox': 2020, 'n_words': 516}