mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2024-12-22 08:16:25 +00:00
parse the flags in the config file to an array for the exec command
This commit is contained in:
parent
45f7506478
commit
a9696bbc0c
21
src/utils.ts
21
src/utils.ts
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user