<commit_before>_                = require 'lodash'
commander        = require 'commander'
colors           = require 'colors'
fs               = require 'fs'
path             = require 'path'
ShareFileService = require '../index.js'

class DownloadCommand
  run: =>
    @parseOptions()
    @downloadFile()

  downloadFile: =>
    # return
    @downloadFileByPath() if @path?
    @downloadFileById() if @itemId?

  downloadFileById: =>
    sharefileService = new ShareFileService {@token, @sharefileDomain}
    sharefileService.downloadFileById {@itemId}, (error, result) =>
      return console.log colors.red "Error: #{error.message}" if error?
      console.log JSON.stringify result.body, null, 2

  downloadFileByPath: =>
    sharefileService = new ShareFileService {@token, @sharefileDomain}
    sharefileService.downloadFileByPath {@path}, (error, result) =>
      return console.log colors.red "Error: #{error.message}" if error?

      console.log JSON.stringify result.body, null, 2

  parseOptions: =>
    commander
      .option '-D, --Domain <Domain>', 'The domain name for Sharefile'
      .option '-t, --token <token>', 'The token for Sharefile'
      .option '-i, --id <itemId>', 'The target folder itemId (must have either itemId or path)'
      .option '-p, --path <path>', 'The target folder path (must have either itemId or path)'
      .parse process.argv

    @sharefileDomain = commander.Domain
    @token = commander.token
    @path = commander.path
    @itemId = commander.id

    unless @sharefileDomain? and @token?
      commander.outputHelp()
      process.exit 0

    unless @path? or @itemId?
      commander.outputHelp()
      process.exit 0

(new DownloadCommand()).run()
<commit_msg>fixed formatting of download output in util<commit_after>_                = require 'lodash'
commander        = require 'commander'
colors           = require 'colors'
fs               = require 'fs'
path             = require 'path'
ShareFileService = require '../index.js'

class DownloadCommand
  run: =>
    @parseOptions()
    @downloadFile()

  downloadFile: =>
    # return
    @downloadFileByPath() if @path?
    @downloadFileById() if @itemId?

  downloadFileById: =>
    sharefileService = new ShareFileService {@token, @sharefileDomain}
    sharefileService.downloadFileById {@itemId}, (error, result) =>
      return console.error colors.red "Error: #{error.message}" if error?
      console.log result.body

  downloadFileByPath: =>
    sharefileService = new ShareFileService {@token, @sharefileDomain}
    sharefileService.downloadFileByPath {@path}, (error, result) =>
      return console.error colors.red "Error: #{error.message}" if error?
      console.log result.body

  parseOptions: =>
    commander
      .option '-D, --Domain <Domain>', 'The domain name for Sharefile'
      .option '-t, --token <token>', 'The token for Sharefile'
      .option '-i, --id <itemId>', 'The target folder itemId (must have either itemId or path)'
      .option '-p, --path <path>', 'The target folder path (must have either itemId or path)'
      .parse process.argv

    @sharefileDomain = commander.Domain
    @token = commander.token
    @path = commander.path
    @itemId = commander.id

    unless @sharefileDomain? and @token?
      commander.outputHelp()
      process.exit 1

    unless @path? or @itemId?
      commander.outputHelp()
      process.exit 1

(new DownloadCommand()).run()

{'fraction_non_alphanumeric': 0.11998829382499268, 'fraction_numerical': 0.001755926251097454, 'mean_word_length': 2.9560185185185186, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 21, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5028176', 'n_tokens_mistral': 977, 'n_tokens_neox': 964, 'n_words': 296}