{"size": 1501, "ext": "js", "max_stars_repo_path": "src/commands/select.js", "max_stars_repo_name": "FernandoA12/book_cli", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/commands/select.js", "max_issues_repo_name": "FernandoA12/book_cli", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/commands/select.js", "max_forks_repo_name": "FernandoA12/book_cli", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.7962962963, "max_line_length": 153, "alphanum_fraction": 0.5616255829}
 const logSymbol = require("log-symbols");
const command = {
  name: 'select',
  description: 'Seleciona um cadastro',
  run: async toolbox => {
    const {
      parameters: { options, first },
      table: { list },
      print: { warning, error, info },
      database: { data }
    } = toolbox;

    const optionsDefault = [
      'client',
      'host_db',
      'user_db',
      'pass_db',
      'host_ftp',
      'user_ftp',
      'pass_ftp',
      'host_vpn',
      'user_vpn',
      'pass_vpn',
      'host_ssh',
      'user_ssh',
      'pass_ssh'
    ]
    
    // VALIDAÇÃO DE OPTIONS
    if (Object.keys(options).length === 0) {
      warning(`${logSymbol.warning} OBRIGATÓRIO SELECINAR UMA CHAVE`)
      // LISTA DE OPTIONS VALIDAS
      optionsDefault.map(value => {
        info(`${logSymbol.info} ${value}`)
      })
      return
    } else {
      Object.keys(options).map(value => {
        if (!optionsDefault.includes(value)) {
          warning(`${logSymbol.warning} CHAVE INVÁLIDA`)
          // LISTA DE OPTIONS VALIDAS
          optionsDefault.map(value => {
            info(`${logSymbol.info} ${value}`)
          })
          process.exit(0);
        }
      })
    }    
    const filtered = data.filter(value => value[Object.keys(options)[0]].toLowerCase().match(new RegExp(options[Object.keys(options)[0]].toLowerCase())))
    if(filtered.length <= 0) return error(`${logSymbol.error} NENHUM CLIENTE ENCONTRADO!`)
    list(filtered, first);
  }
}
module.exports = command