How to use the options function from nomnom

Find comprehensive JavaScript nomnom.options code examples handpicked from public code repositorys.

nomnom.options is a method in the nomnom library that allows you to define and configure command line options for a command line tool or application.

58
59
60
61
62
63
64
65
66
67

/**
 * If running this module directly start the server.
 */
if (require.main === module) {
  var options = nomnom.options({
    port: {
      abbr: 'p',
      default: 3000,
      help: 'Port for incoming connections',
fork icon16
star icon60
watch icon11

+ 13 other calls in file

How does nomnom.options work?

The nomnom.options method is used to define the options that can be passed into the command line interface, and takes a configuration object specifying each option, such as its name, abbreviation, type, and help text.

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const nomnom = require("nomnom");

const options = nomnom
  .options({
    input: {
      abbr: "i",
      help: "Input file path",
      required: true,
    },
    output: {
      abbr: "o",
      help: "Output file path",
      required: true,
    },
    verbose: {
      abbr: "v",
      help: "Enable verbose output",
    },
  })
  .parse();

console.log(options);

In this example, we define three options for the CLI application: input, output, and verbose. The abbr property provides a short name for the option that can be used with a single dash on the command line (e.g., -i for input). The help property provides a description of the option that is displayed when the user runs the command with the --help flag. The required property indicates whether the option is mandatory or optional. The nomnom.options method returns a Parser object that can be used to parse the command-line arguments and extract the option values. The parse method is called on the Parser object to actually parse the arguments and return an object with the option values. In this example, the option values are logged to the console for demonstration purposes.