 Q = require 'q'
 _ = require 'underscore'
 path = require 'path'
+{ProjectCredentialsConfig} = require 'sphere-node-utils'
 package_json = require '../package.json'
 Logger = require './logger'
 StockImport = require './stockimport'
 SftpHelper = require './sftp'
-{ProjectCredentialsConfig} = require 'sphere-node-utils'
 
 argv = require('optimist')
   .usage('Usage: $0 --projectKey [key] --clientId [id] --clientSecret [secret] --file [file] --logDir [dir] --logLevel [level]')

      logger: logger

  stockimport = new StockImport options

  importFn = (fileName) ->
    throw new Error 'You must provide a file to be processed' unless fileName
    d = Q.defer()
    logger.info "About to process file #{fileName}"
    mode = stockimport.getMode fileName
    fs.read fileName
    .then (content) ->
      logger.info 'File read, running import'
      stockimport.run(content, mode)
      .then (result) ->
        logger.info stockimport.sumResult(result)
        d.resolve(fileName)
      .fail (e) ->
        logger.error e, "Oops, something went wrong when processing file #{fileName}"
        d.reject 1
    .fail (e) ->
      logger.error e, "Cannot read file #{fileName}"
      d.reject 2
    d.promise

  file = argv.file


    .fail (error) ->
      logger.error error, 'Oops, something went wrong!'
      process.exit(1)
    .done()
.fail (err) ->
  logger.error e, "Problems on getting client credentials from config files."
  process.exit(1)
.done()