             .then ->
               # output result after order export post processing
               exporter.outputSummary()
-              @exitCode = 0
+              @_setExitCode 0
             .fail (error) ->
               exporter.outputSummary()
               logger.error error, 'Oops, something went wrong!'
               logger.error error.stack if error.stack
-              @exitCode = 1
-          .fail (error) ->
-            logger.error error, 'Oops, something went wrong!'
-            logger.error error.stack if error.stack
-            @exitCode = 1
+              @_setExitCode 1
+          .fail (error) ->
+            logger.error error, 'Oops, something went wrong!'
+            logger.error error.stack if error.stack
+            @_setExitCode 1
 
     program
       .command CONS.CMD_IMPORT_ORDERS_STATUS


module.exports = class

  # workaround to make sure that all logger streams are flushed properly before node terminates
  process.on 'exit', => process.exit(@exitCode)

  @run: (argv) ->
    program

            .then (result) ->
              importer = new Products resources.options
              processSftpImport(resources, importer, 'products')
          .then =>
            @_setExitCode 0
          .fail (error) =>
            logger.error error, 'Oops, something went wrong!'
            logger.error error.stack if error.stack
            @_setExitCode 1
        else # use command line arguments to load import/export files
          validateCredentialsOpts(opts, CONS.CMD_IMPORT_PRODUCTS)
          validateOpt(opts.products, 'products', CONS.CMD_IMPORT_PRODUCTS)
