npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mri-help

v0.2.0

Published

Help text generator for mri

Downloads

10

Readme

mri-help

Help text generator for mri.

GitHub license Build Status npm Project Status

Usage

const mri = require('mri');
const help = require('mri-help');

// use mri like normal, but wrap options in mri-help and (optionally) add an help parameter
const mriOptions = help({
  // ... define your mri options here, but see caveats below
  help: {
    '@command': 'your-awesome-command', // optional, sets the command shown in the usage output
    '@signature': '[options] <file>', // optional, customize the command's signature ("[options]" by default)
    '@description': 'file:  file to use', // optional
    '<flag>': 'Description', // optional, but recommended, description to use for a given flag (long form version)
  }
});

const args = mri(process.argv.slice(2), mriOptions); // get mri output

Now when the user provides the --help flag, help output is shown:

$ your-awesome-command --help

Usage: your-awesome-command [options] <file>

  --<arg>  Description
  --help   Display this help message

API

mriHelper(mriOptions)

mriOption is the options object normally passed to mri. Additional help configuration can be added to enhance the help output.

Returns the mriOptions, with a couple of additional properties:

  • unknown appended to handle capturing of the --help flag.
  • showHelp appended to display help text and exit. Useful for when args parse correctly but don't meet your requirements.

mriOptions.help.@command

Used to override the command shown on the Usage: line. Defaults to process.argv[1] with the current path removed.

mriOptions.help.@signature

Used to override the function signature on the Usage: line. By default, if only shows [options]. It is useful to add other parameters based on your use, such as <file>.

mriOptions.help.@signature

Used to show custom description text under the usage line. This is especially useful if you are using _ args, and would like to describe how they are used.

mriOptions.help.arg

Used to provide a description for any of your arguments. The key is the long-form version of the argument (anything used in boolean, string, of default), and the value is the description used in the output. By default, no description text is shown.

mriOptions.help.!arg

Used to prefix flags in help with no-. For example, if you have a check option, and use { help: { '!check': 'Disable the check' }, the help output will be --no-check Disable the check. This is most useful when the default value is true.

Caveats

mri-help uses the unknown mri option to listen for the --help flag and output the help body when it's seen. It will preserve your own unknown handler, with the exception of --help

As a result of using the unknown argument, there are some gotchas:

  1. You must define all of the arguments you handle in the mri configuration object, otherwise the parser will stop. If you do not provide your own unknown handler, it will tell the user to use the --help flag and exit with status code 1.
  2. Code execution will stop When the --help flag or any unknown flag is found. You can provide your own unknown handler to stop it from exiting on unknown flags, but the mri parser will return undefined.

License

MIT © w33ble