import arg from 'arg'
import { logInfo } from 'log'
import { PlatformClient } from 'platform-client'

export const deployHandler = cliArgs => {
  logInfo({ message: 'Running deploy command' })

  const parsedArgs = arg({
    '--username': String,
    '-u': '--username',

    '--authentication': String,
    '--a': '--authentication',

    '--target-env': String,
    '-t': '--target-env',

    '--ossyfile': String,
    '-o': '--ossyfile',

    '--platforms': String,
    '-p': '--platforms'
  }, { argv: cliArgs })

  PlatformClient.deploy({
    username: parsedArgs['--username'],
    authentication: parsedArgs['--authentication'],
    targetEnvironment: parsedArgs['--target-env'],
    pathToPlatformTemplates: parsedArgs['--platforms'],
    pathToOssyFile: parsedArgs['--ossyfile']
  })
}
