mirror of
https://github.com/toddbluhm/env-cmd.git
synced 2025-12-08 18:23:33 +00:00
This pull request adds support for expanding environment variable expansion support. Closes #91 Since the user controls the call site of cmd-env, it only supports basic UNIX style $var format. `%var%` (windows) or `${var}` is not supported. However, you can escape variable expansion by escaping the dollar sign like so `\$`. Signed-off-by: omeid matten <public@omeid.me>
20 lines
668 B
TypeScript
20 lines
668 B
TypeScript
/* eslint @typescript-eslint/no-non-null-assertion: 0 */
|
|
import { assert } from 'chai'
|
|
import { expandEnvs } from '../src/expand-envs'
|
|
|
|
describe('expandEnvs', (): void => {
|
|
const envs = {
|
|
notvar: 'this is not used',
|
|
dollar: 'money',
|
|
PING: 'PONG',
|
|
IP1: '127.0.0.1'
|
|
}
|
|
const args = ['notvar', '$dollar', '\\$notvar', '-4', '$PING', '$IP1', '\\$IP1', '$NONEXIST']
|
|
const argsExpanded = ['notvar', 'money', '\\$notvar', '-4', 'PONG', '127.0.0.1', '\\$IP1', '$NONEXIST']
|
|
|
|
it('should replace environment variables in args', (): void => {
|
|
const res = args.map(arg => expandEnvs(arg, envs))
|
|
assert.sameOrderedMembers(res, argsExpanded)
|
|
})
|
|
})
|