Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | 1x 1x 1x 69x 69x 110x 69x 1x 3x 3x 2x 3x 1x 1x 3x 1x 1x 1x 1x 1x 5x 1x | import yargs from 'yargs'
import { USAGE, CLI_PARAMS, EPILOG, PROTOCOL_MAP, DEFAULT_OPTIONS } from './constants'
import { getParameters } from './utils'
import SauceLabs from './'
export const run = () => {
let argv = yargs.usage(USAGE)
.epilog(EPILOG)
.demandCommand()
.help()
for (const [commandName, options] of PROTOCOL_MAP) {
const params = getParameters(options.description.parameters)
const command = `${commandName} ${params.map((p) => (
p.required ? `<${p.name}>` : `[${p.name}]`
)).join(' ')}`
yargs.command(command.trim(), options.description.summary, (yargs) => {
for (const param of params) {
const paramDescription = {
describe: param.description,
type: param.type
}
if (typeof param.default !== 'undefined') {
paramDescription.default = param.default
}
yargs.positional(param.name, paramDescription)
}
}, (argv) => {
const { user, key, headless, region } = Object.assign({}, DEFAULT_OPTIONS, argv)
const api = new SauceLabs({ user, key, headless, region })
const requiredParams = params.filter((p) => p.required).map((p) => argv[p.name])
api[commandName](...requiredParams, argv).then(
(result) => {
/* istanbul ignore if */
if (typeof result === 'object') {
// eslint-disable-next-line no-console
return console.log(JSON.stringify(result, null, 4))
}
// eslint-disable-next-line no-console
console.log(result)
},
/* istanbul ignore next */
(error) => {
// eslint-disable-next-line no-console
console.error(error)
process.exit(1)
}
)
return api
})
}
/**
* populate cli arguments
*/
for (const param of CLI_PARAMS) {
argv = argv.option(param.name, param)
}
return argv.argv
}
|