<commit_before>#!/usr/bin/env node
'use strict';
const _ = require('lodash');
const inquirer = require('inquirer');
const program = require('commander');
const clipboardy = require('clipboardy');
const expandTilde = require('expand-tilde');
const pathLibrary = require('path');
const fs = require('fs');


const {createVariableBlock,readSnippetConfiguration} = require('./src/create_variable_block');
const {createSnippet, renderTemplateString} = require('./src/create_snippet');
const {getSnippetPath,getSnippetNamesFromAllSnippetFolders} = require('./src/get_snippet_path');
const {readConfig,writeConfig} = require('./src/read_config');


const configNotPopulatedMessage =
`
In order to use turingsnip you'll need to register some tasty snippet folders
Edit the configuration file in ~/.turingsnip and add the paths
For Example :
{
  "snippetFolders": ["~/snippetFolder", "~/anotherSnippetFolder"]
}
`;
const couldNotFindSnippetMessage = 'Could not find the snippet in your snippet folders.';
const snipAvailableMessage = 'Clipboard contains complete snippet.'
const pathAlreadyExistsInConfig = 'Path already exists in config file.'

const config = readConfig();

program
  .version('1.0.0')

program.command('clip [snippetName]')
  .description('Put the requested snippet on the clipboard')
  .action((name = undefined) => {
    if (!name) {
      interactive_choose_snippet( (snippetName) => {
        const result = pushSnippetToFunction(config, snippetName, clipboardy.writeSync);
      });
    } else {
      const result = pushSnippetToFunction(config, name, clipboardy.writeSync);
    }
  });

program.command('debug <snippetName>')
  .description('Put the requested snippet on the console')
  .action((name) => {
    pushSnippetToFunction(config, name, console.log);
  });

function createFilesForSnippet(snippetName) {
  pushSnippetToFunction(config, snippetName,
    (snippet,filename = undefined) => {
      if (filename) {
        fs.writeFileSync(filename, snippet+"\n");
        console.log("Created snippet file");
      }
  });
}

program.command('create [snippetName]')
  .description('Create files for snippet.')
  .action((snippetName = undefined) => {
    if (!snippetName) {
      interactive_choose_snippet( (snippetName) => {
        createFilesForSnippet(snippetName);
      });
    } else {
      createFilesForSnippet(snippetName);
    }
  });

program.command('list')
  .description('Creates a list of available snippets')
  .action(listSnippets);

program.command('addfolder <folderPath>')
  .description('Adds the path to the list of available snippet folders')
  .action(addFolderToConfig);


program.parse(process.argv);

if (!process.argv.slice(2).length) {
  program.outputHelp();
  return;
}

function addFolderToConfig(rawPath) {
  const path = pathLibrary.resolve(rawPath);
  const config = readConfig();
  const repoMatch = _.find(config.snippetFolders,
    repo => repo === path);
  if (!repoMatch)
  {
    config.snippetFolders.push(path);
    const jsonConfig = writeConfig(config);
    console.log("Config Updated\n" + jsonConfig);
  } else {<commit_msg>Added config filename to addfolder command<commit_after>#!/usr/bin/env node
'use strict';
const _ = require('lodash');
const inquirer = require('inquirer');
const program = require('commander');
const clipboardy = require('clipboardy');
const expandTilde = require('expand-tilde');
const pathLibrary = require('path');
const fs = require('fs');


const {createVariableBlock,readSnippetConfiguration} = require('./src/create_variable_block');
const {createSnippet, renderTemplateString} = require('./src/create_snippet');
const {getSnippetPath,getSnippetNamesFromAllSnippetFolders} = require('./src/get_snippet_path');
const {readConfig,writeConfig} = require('./src/read_config');


const configNotPopulatedMessage =
`
In order to use turingsnip you'll need to register some tasty snippet folders
Edit the configuration file in ~/.turingsnip and add the paths
For Example :
{
  "snippetFolders": ["~/snippetFolder", "~/anotherSnippetFolder"]
}
`;
const couldNotFindSnippetMessage = 'Could not find the snippet in your snippet folders.';
const snipAvailableMessage = 'Clipboard contains complete snippet.'
const pathAlreadyExistsInConfig = 'Path already exists in config file.'

const config = readConfig();

program
  .version('1.0.0')

program.command('clip [snippetName]')
  .description('Put the requested snippet on the clipboard')
  .action((name = undefined) => {
    if (!name) {
      interactive_choose_snippet( (snippetName) => {
        const result = pushSnippetToFunction(config, snippetName, clipboardy.writeSync);
      });
    } else {
      const result = pushSnippetToFunction(config, name, clipboardy.writeSync);
    }
  });

program.command('debug <snippetName>')
  .description('Put the requested snippet on the console')
  .action((name) => {
    pushSnippetToFunction(config, name, console.log);
  });

function createFilesForSnippet(snippetName) {
  pushSnippetToFunction(config, snippetName,
    (snippet,filename = undefined) => {
      if (filename) {
        fs.writeFileSync(filename, snippet+"\n");
        console.log("Created snippet file");
      }
  });
}

program.command('create [snippetName]')
  .description('Create files for snippet.')
  .action((snippetName = undefined) => {
    if (!snippetName) {
      interactive_choose_snippet( (snippetName) => {
        createFilesForSnippet(snippetName);
      });
    } else {
      createFilesForSnippet(snippetName);
    }
  });

program.command('list')
  .description('Creates a list of available snippets')
  .action(listSnippets);

program.command('addfolder <folderPath>')
  .description('Adds the path to the list of available snippet folders')
  .action(addFolderToConfig);


program.parse(process.argv);

if (!process.argv.slice(2).length) {
  program.outputHelp();
  return;
}

function addFolderToConfig(rawPath) {
  const path = pathLibrary.resolve(rawPath);
  const config = readConfig();
  const repoMatch = _.find(config.snippetFolders,
    repo => repo === path);
  if (!repoMatch)
  {
    config.snippetFolders.push(path);
    const jsonConfig = writeConfig(config);
    console.log("Config Updated in ~/.turingsnip\n" + jsonConfig);
  } else {
{'fraction_non_alphanumeric': 0.13216917654597884, 'fraction_numerical': 0.001281640499839795, 'mean_word_length': 4.748618784530387, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '53730', 'n_tokens_mistral': 1903, 'n_tokens_neox': 1834, 'n_words': 435}