How to use the excludeEventType function from yargs
Find comprehensive JavaScript yargs.excludeEventType code examples handpicked from public code repositorys.
yargs.excludeEventType is a function in the yargs library that excludes certain event types from being emitted by a yargs instance.
191 192 193 194 195 196 197 198 199 200
//const filterType = = SearchFilter.FILTER_TYPE_TASK_SID; //const filterType = SearchFilter.FILTER_TYPE_CHAT_CHANNEL_SID; const filterValue = args.filterValue; //const filterValue = "CHc03ffaacf8f14027a25f2fc5e0482066"; //const excludedEventTypes = undefined; const excludedEventTypes = args.excludeEventType; const extraIncludedColumns = args.includeColumn; let includedColumns = defaults.includedColumns; if (!!extraIncludedColumns) includedColumns = includedColumns.concat(extraIncludedColumns);
+ 20 other calls in file
How does yargs.excludeEventType work?
When you use yargs.excludeEventType in your code, you are using a function that excludes certain event types from being emitted by a yargs instance. The excludeEventType function takes a single argument, which is the name of the event type to be excluded. When an event of the excluded type is emitted, it will not be propagated by the yargs instance, and any listeners attached to that event will not be called. This can be useful in cases where you want to filter or restrict the types of events that can be emitted by a yargs instance. For example, you may want to exclude certain events to prevent accidental modification of critical state or to enforce strict event handling policies. Here is an example of using yargs.excludeEventType to exclude the fail event type: javascript Copy code {{{{{{{ const yargs = require('yargs'); yargs.excludeEventType('fail'); yargs.command('hello', 'Say hello', (yargs) => { yargs.demandOption('name'); }, (argv) => { console.log(`Hello, ${argv.name}!`); }); yargs.fail((msg, err) => { console.error(`Error: ${msg}`); }); yargs.parse(['hello', '--name', 'Alice']); In this example, we are using yargs.excludeEventType to exclude the fail event type. We then define a command using yargs.command, which requires the name option to be passed in. We also define a fail handler using yargs.fail, which will be called if the command fails to execute. When we call yargs.parse(['hello', '--name', 'Alice']), the command will execute successfully, and the output will be: Copy code {{{{{{{ class="!whitespace-pre hljs">Hello, Alice! If we had omitted the --name option, the fail event would have been emitted, but because we have excluded it using yargs.excludeEventType, the fail handler will not be called. Overall, yargs.excludeEventType provides a simple and powerful way to filter and restrict the types of events that can be emitted by a yargs instance, allowing you to write more robust and reliable command-line interfaces in Node.js.
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
const yargs = require("yargs"); yargs.excludeEventType("fail"); yargs.command( "hello", "Say hello", (yargs) => { yargs.demandOption("name"); }, (argv) => { console.log(`Hello, ${argv.name}!`); } ); yargs.fail((msg, err) => { console.error(`Error: ${msg}`); }); yargs.parse(["hello", "--name", "Alice"]);
In this example, we are using yargs.excludeEventType to exclude the fail event type. We then define a command using yargs.command, which requires the name option to be passed in. We also define a fail handler using yargs.fail, which will be called if the command fails to execute. When we call yargs.parse(['hello', '--name', 'Alice']), the command will execute successfully, and the output will be: Copy code
yargs.argv is the most popular function in yargs (1012 examples)