From b00eb87b4860a890dd2dab0d6058241bbfd2b3ec Mon Sep 17 00:00:00 2001 From: Johan Holmerin Date: Sun, 27 Feb 2022 16:04:23 +0100 Subject: [PATCH] fix: return deno env object (#432) Fixes yargs/yargs#2136 --- .github/workflows/ci.yaml | 4 +++- deno.ts | 2 +- test/deno/yargs-test.ts | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5bcd95ae..51f1f43d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -61,7 +61,9 @@ jobs: deno-version: v1.x - run: | deno --version - deno test --allow-read test/deno/yargs-test.ts + deno test --allow-read --allow-env test/deno/yargs-test.ts + env: + MY_PREFIX_MY_KEY: "my value" browser: runs-on: ubuntu-latest steps: diff --git a/deno.ts b/deno.ts index 1074dc64..ea42bced 100644 --- a/deno.ts +++ b/deno.ts @@ -10,7 +10,7 @@ import type { Arguments, ArgsInput, Parser, Options, DetailedArguments } from '. const parser = new YargsParser({ cwd: Deno.cwd, env: () => { - Deno.env.toObject() + return Deno.env.toObject() }, format: (str: string, arg: string) => { return str.replace('%s', arg) }, normalize: path.posix.normalize, diff --git a/test/deno/yargs-test.ts b/test/deno/yargs-test.ts index f025ac62..8bb250ec 100644 --- a/test/deno/yargs-test.ts +++ b/test/deno/yargs-test.ts @@ -63,3 +63,8 @@ Deno.test('it detects strings that could be parsed as numbers', () => { assertEquals(parser.looksLikeNumber('0100'), false) assertEquals(parser.looksLikeNumber('apple'), false) }) + +Deno.test('should load values from environment variables', () => { + const argv = parser([], { envPrefix: 'MY_PREFIX_' }) + assertEquals(argv.myKey, 'my value') +})