Argument Types Reference

A quick tour of the basic argument types CLI Forge supports out of the box: string, number, boolean, array, and positional. Each type is wrapped in a named region so it can be embedded into other guides.

For object-typed options see the object dot-notation example or the object arguments example. For multi-typed flags see the oneOf example.

All Example Files

FILE EXPLORER
argument-types.ts
1import cli from 'cli-forge';
2
3const app = cli('argument-types').command('deploy', {
4  builder: (args) =>
5    args
6      .positional('target', {
7        type: 'string',
8        required: true,
9        description: 'Where to deploy (e.g. production, staging)',
10      })
11      .option('name', {
12        type: 'string',
13        description: 'Release name',
14        default: 'latest',
15      })
16      .option('port', {
17        type: 'number',
18        description: 'Port to listen on',
19        default: 3000,
20      })
21      .option('tags', {
22        type: 'array',
23        items: 'string',
24        description: 'Tags to apply (space, comma, or repeated flag)',
25        default: [],
26      })
27      .option('verbose', {
28        type: 'boolean',
29        description: 'Enable verbose logging',
30        default: false,
31      })
32      ,
33  handler: (args) => {
34    console.log(
35      `name=${args.name} port=${args.port} verbose=${args.verbose} tags=${args.tags.join(',')} target=${args.target}`
36    );
37  },
38});
39
40export default app;
41
42if (require.main === module) {
43  (async () => {
44    await app.forge();
45  })();
46}
47