<commit_before>#!/usr/bin/env node

const app   = require('./index')
const yargs = require('yargs')
   .usage( 'Usage:\n'
         + '  node $0 [-d prefecture] <command>\n\n'
         + 'Commands:\n'
         + '  a, all    : show all greetings\n'
         + '  n, new    : new years greeting\n'
         + '  s, summer : summer greeting\n'
         + '  w, winter : winter greeting\n'
         + '  l, last   : end of years greeting\n'
         + '  t, thx    : thanks greeting\n'
         + '  so, sorry : sorry  greeting'
   )
   .options({
      'd': {
         alias: 'dialect',
         describe: 'Greeting from each prefecture dialect'
      },
      's': {
         alias: 'surround',
         describe: 'Decoration of the surround'
      },
      'v': {
         alias: 'version',
         describe: 'Show version'
      },
      'h': {
         alias: 'help',
         describe: 'Show help'
      }
   })
   .epilog( 'Dialects:\n'
          + '  kyoto osaka okinawa hiroshima\n\n'
          + 'Surrounds:\n'
          + '  no        Do not surround text\n'
          + '  w-star    ☆\n'
          + '  b-star    ★\n'
          + '  asterisk  ＊\n'
          + '  w-tri     top: ▽  , bottom: △\n'
          + '  b-tri     top: ▼  , bottom: ▲\n'
          + '  slash     top: /￣, bottom: ＿/\n'
   )
   .locale('en')

const     argv = yargs.argv
const is_exist = exist_check(argv)
let key = get_full_text(argv._[0])

// 'help' is top priority option
if (argv.h) {
   show_help()
}
else if (argv.v) {
   console.log('1.3.3')
}
else if (argv._.length >= 2) {
   show_help('Error: Please input only one command\n')
}
else if (is_exist < 1) {
      show_help()
}
else {
   switch (key) {
      case 'all':
         greet_all()
         break
      default:
         greet(key)
         break
   }
}

function greet(item) {
   const greet = app.greet(item, argv)
   if (greet) console.log(greet)
}

function greet_all() {
   let greet = ''
   app.get_greetings().forEach((item) => {
      if (item === 'all') return
      greet = app.greet(item, argv)
      if (greet) console.log(greet)
   })
}

function show_help(text) {
   if (text) console.log(text)
   yargs.showHelp()
}

function exist_check(argv) {
   const greetings = app.get_greetings()
   const dialects  = app.get_dialects()
   const surrounds = app.get_surrounds()
   let ret = true

   // If index is 0, it becomes false,
   // incrementing by 1
   ret = greetings.indexOf(get_full_text(argv._[0])) + 1
   if (argv.d && ret) ret = dialects.indexOf(argv.d) + 1
   if (argv.s && ret) ret = surrounds.indexOf(argv.s) + 1

   return ret
}

function get_full_text(key) {
   let ret = ''
   switch(key) {
      case 'a':
         ret = 'all'
         break
      case 'n':
         ret = 'new'
         break
      case 's':
         ret = 'summer'
         break
      case 'w':
         ret = 'winter'
         break
      case 'l':
         ret = 'last'
         break
      case 't':
         ret = 'thx'
         break
      case 'so':
         ret = 'sorry'
         break
      default:
         ret = key
         break
   }
   return ret
}
<commit_msg>minor refactoring<commit_after>#!/usr/bin/env node

const app   = require('./index')
const yargs = require('yargs')
   .usage( 'Usage:\n'
         + '  node $0 [-d prefecture] <command>\n\n'
         + 'Commands:\n'
         + '  a, all    : show all greetings\n'
         + '  n, new    : new years greeting\n'
         + '  s, summer : summer greeting\n'
         + '  w, winter : winter greeting\n'
         + '  l, last   : end of years greeting\n'
         + '  t, thx    : thanks greeting\n'
         + '  so, sorry : sorry  greeting'
   )
   .options({
      'd': {
         alias: 'dialect',
         describe: 'Greeting from each prefecture dialect'
      },
      's': {
         alias: 'surround',
         describe: 'Decoration of the surround'
      },
      'v': {
         alias: 'version',
         describe: 'Show version'
      },
      'h': {
         alias: 'help',
         describe: 'Show help'
      }
   })
   .epilog( 'Dialects:\n'
          + '  kyoto osaka okinawa hiroshima\n\n'
          + 'Surrounds:\n'
          + '  no        Do not surround text\n'
          + '  w-star    ☆\n'
          + '  b-star    ★\n'
          + '  asterisk  ＊\n'
          + '  w-tri     top: ▽  , bottom: △\n'
          + '  b-tri     top: ▼  , bottom: ▲\n'
          + '  slash     top: /￣, bottom: ＿/\n'
   )
   .locale('en')

const     argv = yargs.argv
const is_exist = exist_check(argv)
let key = convert(argv._[0])

// 'help' is top priority option
if (argv.h) {
   show_help()
}
else if (argv.v) {
   const package_json = require('./package.json')
   console.log(package_json.version)
}
else if (argv._.length >= 2) {
   show_help('Error: Please input only one command\n')
}
else if (is_exist < 1) {
      show_help()
}
else {
   switch (key) {
      case 'all':
         greet_all()
         break
      default:
         greet(key)
         break
   }
}

function greet(item) {
   const greet = app.greet(item, argv)
   if (greet) console.log(greet)
}

function greet_all() {
   let greet = ''
   app.get_greetings().forEach((item) => {
      if (item === 'all') return
      greet = app.greet(item, argv)
      if (greet) console.log(greet)
   })
}

function show_help(text) {
   if (text) console.log(text)
   yargs.showHelp()
}

function exist_check(argv) {
   const greetings = app.get_greetings()
   const dialects  = app.get_dialects()
   const surrounds = app.get_surrounds()
   let ret = true

   // If index is 0, it becomes false,
   // incrementing by 1
   ret = greetings.indexOf(convert(argv._[0])) + 1
   if (argv.d && ret) ret = dialects.indexOf(argv.d) + 1
   if (argv.s && ret) ret = surrounds.indexOf(argv.s) + 1

   return ret
}

function convert(key) {
   let ret = ''
   switch(key) {
      case 'a':
         ret = 'all'
         break
      case 'n':
         ret = 'new'
         break
      case 's':
         ret = 'summer'
         break
      case 'w':
         ret = 'winter'
         break
      case 'l':
         ret = 'last'
         break
      case 't':
         ret = 'thx'
         break
      case 'so':
         ret = 'sorry'
         break
      default:
         ret = key
         break
   }
   return ret
}

{'fraction_non_alphanumeric': 0.14544587505960896, 'fraction_numerical': 0.0036560165315530123, 'mean_word_length': 1.6271398747390398, 'pattern_counts': {'":': 0, '<': 7, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7157256', 'n_tokens_mistral': 2298, 'n_tokens_neox': 2222, 'n_words': 554}