parse the flags in the config file to an array for the exec command

This commit is contained in:
cupcakearmy 2019-12-04 20:38:48 +01:00
parent 45f7506478
commit a9696bbc0c

View File

@ -4,6 +4,7 @@ import { randomBytes } from 'crypto'
import { createWriteStream } from 'fs'
import { isAbsolute, resolve, dirname } from 'path'
import { CONFIG_FILE } from './config'
import { Location } from './types'
@ -86,3 +87,23 @@ export const pathRelativeToConfigFile = (path: string): string => isAbsolute(pat
: resolve(dirname(CONFIG_FILE), path)
export const ConfigError = new Error('Config file not found')
export const getFlagsFromLocation = (location: Location, command?: string): string[] => {
if (!location.options) return []
const all = {
...location.options.global,
...(location.options[command || ''] || {}),
}
let flags: string[] = []
// Map the flags to an array for the exec function.
for (let [flag, values] of Object.entries(all)) {
if (!Array.isArray(values))
values = [values]
for (const value of values)
flags = [...flags, `--${flag}`, value]
}
return flags
}