How to use the showHelp function from optimist

Find comprehensive JavaScript optimist.showHelp code examples handpicked from public code repositorys.

optimist.showHelp is a method that displays the usage information and options for an application that uses the optimist module for command-line argument parsing.

38
39
40
41
42
43
44
45
46
47

  .describe('help', 'Print usage instructions')
  .alias('h', 'help')
  .argv

if (argv.help || !argv.sites) return optimist.showHelp()

var server = review()

server.title(argv.title)
fork icon47
star icon911
watch icon25

+ 3 other calls in file

104
105
106
107
108
109
110
    break;
case 'test':
    testUrl();
    break;
default:
        userArgv.showHelp();
}
fork icon54
star icon151
watch icon16

+ 2 other calls in file

How does optimist.showHelp work?

optimist.showHelp works by displaying the usage information and options for an application that uses the optimist module for command-line argument parsing.

When called, optimist.showHelp prints out the usage information and options that have been defined using the optimist API, including:

  • The usage message, which is typically a brief description of how to use the application and its arguments.
  • The options that have been defined using optimist.option, including their aliases, descriptions, and default values.

The output of optimist.showHelp is typically displayed in the console, and is often triggered by the user passing the --help option to the application.

By using optimist.showHelp, you can provide users with a helpful message that explains how to use your application's command-line arguments and options, and helps them to troubleshoot any issues they may encounter.

38
39
40
41
42
43
44
45
46
47
    });

var argv = opt.argv;

if (argv.help) {
  return opt.showHelp();
}

if (argv.ls) {
  var versions = data.versions;
fork icon51
star icon349
watch icon20

19
20
21
22
23
24
25
26
27
28

if (argv._.length === 1) {
  runCode(argv)
}
if (argv.h) {
  options.showHelp()
  process.exit(1)
}

if (!argv.dere) {
fork icon16
star icon205
watch icon7

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 argv = require("optimist")
  .usage("Usage: $0 [options] ")
  .options({
    v: {
      alias: "verbose",
      describe: "Enable verbose logging",
      type: "boolean",
      default: false,
    },
    h: {
      alias: "help",
      describe: "Display usage information",
    },
  }).argv;

if (argv.help) {
  // Display usage information and options
  optimist.showHelp();
} else {
  // Do something with the command-line arguments
  console.log("Processing file:", argv._[0]);
}

In this example, we first use optimist to define the command-line arguments and options for our tool. We specify a usage message that describes how to use the tool and its options, and define two options: -v/--verbose, which enables verbose logging, and -h/--help, which displays usage information. We then check whether the --help option has been passed by the user. If it has, we call optimist.showHelp() to display the usage information and options. If it hasn't, we assume that the user has passed a file name as an argument, and we log a message indicating that we are processing that file. By using optimist.showHelp(), we make it easy for users to learn how to use our command-line tool and its options, and provide a helpful error message if they pass an invalid option or argument.

42
43
44
45
46
47
48
49
50
    describe: "Output file for compiled protos"
  });

var argv = optimist.argv;

if( argv.help ) { optimist.showHelp(); process.exit(0); }

if( argv._.length == 0 && fs.existsSync("./protos.json")) Protofile.protoPaths.push("./protos.json");
for(var i=0; i < argv._.length; i++) { Protofile.protoPaths.push(Path.resolve(argv._[i].trim())); }
fork icon12
star icon77
watch icon27

25
26
27
28
29
30
31
32
33
34
  .describe('m', 'the default file scale mode to display: should be either "count" or "size". Default: size')

  .argv

if (argv.help) {
  optimist.showHelp()
  return process.exit(1)
}

var files = argv._ || []
fork icon80
star icon0
watch icon19

29
30
31
32
33
34
35
36
37
38
/**
 * Main.
 */
function main () {
  var showHelp = function () {
    optimist.showHelp();
    console.log('Either a config file or a CSS file is required. '
                + 'If no HTML is given, uCSS will only look for duplicate CSS.'
                + '\nIf no arguments are specified, uCSS will assume there is a '
                + 'config_ucss.js file in the current directory.');
fork icon74
star icon0
watch icon78

19
20
21
22
23
24
25
26
27
28
      alias:"help", 
      descripe:"Show help info"   }
);
var argv = opt.argv;
if (argv.help || argv._.length === 0)  {
   return opt.showHelp(function(help)  {
         console.log(help);
         if (argv._.length === 0)  {
            console.error("Error: must pass in a file");
         }
fork icon0
star icon0
watch icon0