Strict Mode

This example demonstrates how to use strict mode to ensure that all arguments are recognized. Strict mode throws a validation error when unmatched arguments are encountered.

All Example Files

FILE EXPLORER
strict-mode.ts
1import cliForge from 'cli-forge';
2
3const cli = cliForge('strict-mode-example')
4  // Enable strict mode - unmatched arguments will throw validation errors
5  .strict()
6  .option('name', {
7    type: 'string',
8    description: 'The name to greet',
9    default: 'World',
10  })
11  .command('$0', {
12    builder: (args) => args,
13    handler: (args) => {
14      console.log(`Hello, ${args.name}!`);
15    },
16  });
17
18export default cli;
19
20if (require.main === module) {
21  (async () => {
22    await cli.forge();
23  })();
24}
25