How to use the getUsage function from cli

Find comprehensive JavaScript cli.getUsage code examples handpicked from public code repositorys.

cli.getUsage is a function that generates usage information for a command-line interface based on a configuration object.

20
21
22
23
24
25
26
27
28
options = cli.parse({
  now:   ['n', 'Run sync on start']
});

if(cli.args.length !== 1) {
  return cli.getUsage();
}

/* Configuration */
fork icon48
star icon112
watch icon10

+ 11 other calls in file

52
53
54
55
56
57
58
59
60
61
            false
        ],
    });

if (!cli.args.length) {
    cli.getUsage(1);
} else {
    cli.options.pattern = cli.args.pop();
    var files = process.stdin;
    if (cli.options.name) {
fork icon21
star icon195
watch icon6

How does cli.getUsage work?

cli.getUsage is a function that generates usage information for a command-line interface based on a configuration object. When you call cli.getUsage, you pass in a configuration object that describes the different options and arguments that your command-line interface supports. This configuration object typically includes the following information: A description of the command and its purpose A list of supported options, including their names, descriptions, and default values A list of positional arguments that the command accepts, along with their descriptions Based on this configuration object, cli.getUsage generates a usage string that summarizes the command and its usage. This usage string typically includes the following information: A brief summary of the command and its purpose A list of supported options, including their names, descriptions, and default values A list of positional arguments that the command accepts, along with their descriptions Any other relevant information, such as examples or usage notes By generating this usage string automatically based on a configuration object, cli.getUsage makes it easy to keep your usage information up-to-date and consistent across your command-line interface. Overall, cli.getUsage is a useful tool for generating usage information that can help users understand how to use your command-line interface.

18
19
20
21
22
23
24
25
26
27
      cwd: ['c', 'Resolve path names from this directory', 'string', '.'],
      rename: ['r', 'Rename input files rather than creating converted copies', 'boolean', false]
    })

if (!cli.args.length) {
    cli.getUsage(1)
} else {
    cli.options.pattern = cli.args.length > 1 ? cli.args.pop() : null

    if (cli.args.length) {
fork icon11
star icon52
watch icon4

+ 3 other calls in file

25
26
27
28
29
30
31
32
33
34
35
if (!cliArgs.mediumPublicationUrl &&
    !cliArgs.mediumPublicationHtmlFile &&
    !cliArgs.mediumPublicationUrlsFile &&
    !cliArgs.mediumPublicationUrls
) {
    cli.getUsage();
}


async function wait(timeInMills) {
    return new Promise((resolve) => {
fork icon3
star icon15
watch icon0

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const cli = require("command-line-args");

const optionDefinitions = [
  {
    name: "help",
    alias: "h",
    type: Boolean,
    description: "Print this usage guide.",
  },
  {
    name: "name",
    type: String,
    description: "The name of the person to greet.",
  },
  {
    name: "count",
    alias: "c",
    type: Number,
    description: "The number of times to repeat the greeting.",
  },
];

const usage = cli.getUsage({
  header: "A simple CLI app for greeting people.",
  optionList: optionDefinitions,
  footer:
    "Examples:\n" + "  greet --name Alice --count 3\n" + "  greet -n Bob\n",
});

console.log(usage);

In this example, we start by defining an array of option definitions using the command-line-args library. This array includes options for specifying the name of the person to greet and the number of times to repeat the greeting. We then call cli.getUsage to generate a usage string based on this array. We pass in an object that includes a header describing the command, the option definitions, and a footer with usage examples. Finally, we log the resulting usage string to the console. The resulting usage string might look something like this: lua Copy code