help-me command line help utility

5.0.0 · active · verified Sun Apr 19

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

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `help-me` in an ESM module, dynamically create a documentation directory and a sample help file, and then display help messages for both existing and non-existent commands using top-level await.

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'])

view raw JSON →