From 56be8c82683f4b657bdf05ade5db54390abb5d67 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Fri, 2 Feb 2018 20:59:48 -0800 Subject: [PATCH] feat: added env to flags --- src/flags.ts | 4 ++++ src/parse.ts | 17 +++++++++++------ test/parse.test.ts | 11 +++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/flags.ts b/src/flags.ts index c54ca01..c49169b 100644 --- a/src/flags.ts +++ b/src/flags.ts @@ -10,6 +10,10 @@ export type IFlagBase = { description?: string hidden?: boolean required?: boolean + /** + * also accept an environment variable as input + */ + env?: string parse(input: I): T } diff --git a/src/parse.ts b/src/parse.ts index 62bf074..ed1cdd3 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -172,12 +172,17 @@ export class Parser { + it('accepts as environment variable', () => { + process.env.TEST_FOO = '101' + const out = parse([], { + flags: {foo: flags.string({env: 'TEST_FOO'})}, + }) + expect(out.flags.foo).to.equal('101') + delete process.env.TEST_FOO + }) + }) })