Skip to content

Commit

Permalink
support for tilde in optional arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
cupcakearmy committed Dec 21, 2019
1 parent 12d2e01 commit e51eacf
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import axios from 'axios'
import { spawnSync, SpawnSyncOptions } from 'child_process'
import { randomBytes } from 'crypto'
import { createWriteStream } from 'fs'
import { dirname, isAbsolute, resolve } from 'path'
import { dirname, isAbsolute, join, resolve } from 'path'
import { homedir } from 'os'

import axios from 'axios'
import { Duration, Humanizer } from 'uhrwerk'

import { CONFIG_FILE } from './config'
Expand Down Expand Up @@ -95,6 +97,11 @@ export const pathRelativeToConfigFile = (path: string): string => isAbsolute(pat
? path
: resolve(dirname(CONFIG_FILE), path)

export const resolveTildePath = (path: string): string | null =>
(path.length === 0 || path[0] !== '~')
? null
: join(homedir(), path.slice(1))

export const ConfigError = new Error('Config file not found')

export const getFlagsFromLocation = (location: Location, command?: string): string[] => {
Expand All @@ -108,8 +115,11 @@ export const getFlagsFromLocation = (location: Location, command?: string): stri
let flags: string[] = []
// Map the flags to an array for the exec function.
for (let [flag, values] of Object.entries(all))
for (const value of makeArrayIfIsNot(values))
flags = [...flags, `--${String(flag)}`, String(value)]
for (const value of makeArrayIfIsNot(values)) {
const stringValue = String(value)
const resolvedTilde = resolveTildePath(stringValue)
flags = [...flags, `--${String(flag)}`, resolvedTilde === null ? stringValue : resolvedTilde]
}

return flags
}
Expand Down

0 comments on commit e51eacf

Please sign in to comment.