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 + }) + }) })