import * as minimist from 'minimist' ; import { createError , ErrorCode } from './errors' ; import * as tempfile from 'tempfile' ; export type Platform = 'ios' | 'android' ; /**
 * The parameters passed in from the command line.
 */ export interface CliParameters { /** Will we be using ios or android? */ platform ? : Platform ; /** A file name to save the image. */ filename : string ; /** An optional device name for android if more than 1 device is plugged in. */ device ? : string ; /** Should we use the clipboard? */ useClipboard : boolean ; } param parsed function getPlatform ( parsed ) { const platform = parsed . _ [ 0 ] as string ; if ( ! platform ) throw createError ( ErrorCode . MissingPlatform ) ; if ( platform !== 'ios' && platform !== 'android' ) { throw createError ( ErrorCode . InvalidPlatform ) ; } return platform ; } param argv export function parse ( argv ? ) { argv = argv || process . argv . slice ( 2 ) ; const parsed = minimist ( argv ) ; const platform = getPlatform ( parsed ) ; const useClipboard = ! parsed [ 'f' ] ; const filename = ( parsed [ 'f' ] as string ) || tempfile ( '.png' ) ; const device = parsed [ 'd' ] as string ; return { platform , filename , device , useClipboard } ; }