help-me command line help utility
help-me is a lightweight Node.js utility designed to simplify the creation and display of help messages for command-line interfaces. It serves as a direct partner for argument parsers like `minimist` and command dispatchers such as `commist`, allowing developers to define structured help documentation in simple text files. Currently at version 5.0.0, the package sees an active development and maintenance cadence, with recent updates focusing on modernizing its codebase and reducing dependencies, notably dropping `glob` in v5.0.0. Its primary differentiator lies in its straightforward, file-based approach to help documentation and its minimal API surface, making it an ideal choice for projects already leveraging `minimist` or `commist` that require a simple, declarative help system without the overhead of larger CLI frameworks.
Common errors
-
ENOENT: no such file or directory, stat '/path/to/doc/command.txt'
cause The help command was invoked for a command (e.g., 'command') for which a corresponding help file ('command.txt') does not exist in the configured documentation directory.fixVerify that the `dir` option points to the correct directory containing your help files and that the requested command's help file exists (e.g., `command.txt` for `['command']`). Ensure file names match command arguments. -
TypeError: help is not a function
cause This error typically occurs when attempting to use `help-me` with incorrect import syntax, such as using CommonJS `require()` with named destructuring (`const { help } = require('help-me')`) or importing the ESM `help` function as a default import (`import help from 'help-me'`).fixFor CommonJS, use `const helpMe = require('help-me')` to get the default export function. For ESM, use `import { help } from 'help-me'` for the named export.
Warnings
- breaking Version 5.0.0 removed the 'glob' dependency. This change may affect how help files are resolved or impact functionality relying on wildcard path matching for help documentation that was previously available.
- breaking Version 4.0.0 introduced significant internal modernization, dependency reductions, and a move towards 'exact match' for help file lookup. This may alter previous fuzzy matching behavior for command help files.
- gotcha When using `help-me` in an ESM module, resolving the `dir` option (where help files are located) requires using `import.meta.url` in conjunction with a utility like `desm` or Node.js's `fileURLToPath` and `path.dirname` to correctly derive file system paths. Directly using `__dirname` is not available in ESM.
Install
-
npm install help-me -
yarn add help-me -
pnpm add help-me
Imports
- helpMe
const { helpMe } = require('help-me')const helpMe = require('help-me') - help
import help from 'help-me'
import { help } from 'help-me'
Quickstart
import { help } from 'help-me'
import { join } from 'desm'
import { fileURLToPath } from 'url'
import { dirname } from 'path'
import { mkdirSync, existsSync, writeFileSync } from 'fs'
// Setup for __dirname equivalent in ESM
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const docDir = join(__dirname, 'doc')
// Ensure the 'doc' directory exists
if (!existsSync(docDir)) {
mkdirSync(docDir, { recursive: true })
}
// Create a dummy help file for the example
const helpFilePath = join(docDir, 'hello.txt')
if (!existsSync(helpFilePath)) {
writeFileSync(helpFilePath, 'This is a detailed help message for the "hello" command.\n\nUsage: mycli hello <name>')
}
// Instantiate and use the help function
// help-me expects a path to a directory containing help files.
// The help function is then called with options and the command arguments.
console.log('--- Displaying help for "hello" command ---\n')
await help({
dir: docDir,
ext: '.txt',
// Optional: customize "no such help" message
noHelp: (command) => `No help available for command: ${command.join(' ')}`
}, ['hello'])
// Example of requesting help for a non-existent command
console.log('\n--- Displaying help for "unknown" command ---\n')
await help({
dir: docDir,
ext: '.txt',
noHelp: (command) => `No help available for command: ${command.join(' ')}`
}, ['unknown'])