diff --git a/commander/commander-tests.ts b/commander/commander-tests.ts index f2457901da..135ad8bf02 100644 --- a/commander/commander-tests.ts +++ b/commander/commander-tests.ts @@ -95,6 +95,13 @@ program.on('--help', () => { console.log(''); }); +program + .command('allow-unknown-option') + .allowUnknownOption() + .action(() => { + console.log('unknown option is allowed'); + }); + program.parse(process.argv); console.log('stuff'); diff --git a/commander/commander.d.ts b/commander/commander.d.ts index 09d7966596..278a491a62 100644 --- a/commander/commander.d.ts +++ b/commander/commander.d.ts @@ -158,6 +158,15 @@ declare module commander { option(flags:string, description?:string, fn?:(arg1:any, arg2:any)=>void, defaultValue?:any):ICommand; option(flags:string, description?:string, defaultValue?:any):ICommand; + /** + * Allow unknown options on the command line. + * + * @param {Boolean} arg if `true` or omitted, no error will be thrown + * for unknown options. + * @api public + */ + allowUnknownOption(arg?: boolean):ICommand; + /** * Parse `argv`, settings options and invoking commands when defined. *