1.6.2 • Published 3 years ago

meow-helper v1.6.2

Weekly downloads
18
License
MIT
Repository
github
Last release
3 years ago

Features

  • Generates help text without effort. See images below.
  • Provides common flags. (--help and --version)
  • meow throws unknown flags with the allowUnknownFlags option. meow-helper shows help text instead of throwing. You can change this behavior with the notThrow option.
  • Formats, colorizes, and aligns arguments, options, default values, and their descriptions.
  • Marks required fields with an *.
  • Supports maximum line length and automatic word wrap.
  • Splits options into two lines if space for description is too small. You can change this behavior with the multilineThreshold option.
  • Generates description, usage, arguments, flags/options, examples sections.
  • Colorizes command in usage and examples and adds $ before command.
  • Exports chalk and cliui.
  • Supports both { autoHelp: true } and { autoHelp: false }. Adds a description to help if required.
  • Moves three dots in arguments outside of brackets. For example: args: { “path...” } becomes command <path>...
  • Adds three dots ... to flags with multiple value.

Synopsis

TypeScript

import getHelp, { commonFlags, chalk, cliui } from "meow-helper";
import type { ExtendedAnyFlags } from "meow-helper";
import { readFileSync } from "fs";
import { join } from "path";

CommonJS

const { default: getHelp, commonFlags, chalk, cliui } = require("meow-helper");
const { readFileSync } = require("fs");

Usage

const flags: ExtendedAnyFlags = {
  name: { alias: "n", type: "string", desc: "Name" },
  cwd: { alias: "c", type: "string", desc: "Working path." },
  context: { type: "string", desc: "Context." },
  ...commonFlags,
};

// Groups options. Keys are the first option of the group.
const groups = {
  name: { title: "General Options", description: "Some description" },
  context: { title: "Other Options", description: "Other description" },
};

const args = { "path...": "Paths of files." };
const pkg = JSON.parse(readFileSync(join(__dirname, "../package.json"), { encoding: "utf8" }));

meow(getHelp({ flags, args, groups, pkg }), { flags, pkg, allowUnknownFlags: false });
const help = getHelp({
  lineLength: 80,
  titleLength: 15,
  pkg: {}, // package.json data
  command: "not-sync",
  description: "Description of the command",
  args: { path: "Path of file." },
  flags, // meow flags with `desc` key.
  examples: ["not-sync node_modules,dist,coverage", "not-sync node_modules,dist,coverage --ignoreConfigs .gitignore"],
  multilineThreshold: 50,
  autoHelp: true,
  notThrow: true,
});

Details

meow-helper generates single-line or multi-line help text based on the multilineThreshold option automatically.

Single-Line

meow-helper help text in single line mode

Multi-Line

meow-helper help text in multi line mode

API

Table of contents

Interfaces

Type aliases

ExtendedAnyFlag

Ƭ ExtendedAnyFlag: AnyFlag & { desc?: string }

Meow flag extended with desc key.

Defined in: get-help.ts:8


ExtendedAnyFlags

Ƭ ExtendedAnyFlags: Record<string, ExtendedAnyFlag>

Record of extended any flag.

Defined in: get-help.ts:11

Variables

cliui

Const cliui: any

Defined in: index.ts:5


commonFlags

Const commonFlags: ExtendedAnyFlags

Very common flags

Defined in: index.ts:12

Functions

default

default(helpOptions: HelpOptions): string

Generate help text for meow.

Example

const flags: ExtendedFlags = { cwd: { alias: "c", type: "string", desc: "Current CWD." }, ...commonFlags };
const args = { path: "Path of file." };

meow(getHelp({ flags, args, pkg }), { flags, pkg, allowUnknownFlags: false });

Parameters:

NameTypeDescription
helpOptionsHelpOptionsare options

Returns: string

Defined in: get-help.ts:193

Interfaces

meow-helper / HelpOptions

Interface: HelpOptions

Options below modify behaviour of [getHelp] function.

Properties

args

Optional args: Record<string, string>

Name and description of positional arguments.

Defined in: get-help.ts:28


autoHelp

Optional autoHelp: boolean

This option sets whether the autoHelp option of meow is used. If this is true, the description text is not added, because meow adds it automatically.

Defined in: get-help.ts:36


command

Optional command: string

Name of the command.

Defined in: get-help.ts:22


description

Optional description: string | string[]

Command description.

Defined in: get-help.ts:24


examples

Optional examples: string | string[]

A single example or list of examples can be provided to show in the help text. Lines are prefixed with $ and the command is colored automatically.

Defined in: get-help.ts:32


flags

Optional flags: ExtendedAnyFlags

Flags provided to meow. Uses desc key for the description.

Defined in: get-help.ts:30


groups

Optional groups: Record<string, { description?: string ; title?: string }>

Option groups shown in help text. Key is the first option in group.

Defined in: get-help.ts:40


lineLength

Optional lineLength: number

Text longer than line length will be word-wrapped.

Defined in: get-help.ts:16


multilineThreshold

Optional multilineThreshold: number

If space available for option descriptions is less than this threshold, descriptions are given their own rows. So they have more space. See images above.

Defined in: get-help.ts:34


notThrow

Optional notThrow: boolean

Whether to throw an error when meow exits with exit code 2. If true, it adds process.on("exit") to show help and exits with code 0.

Defined in: get-help.ts:38


pkg

Optional pkg: Record<string, any>

package.json data.

Defined in: get-help.ts:20


titleLength

Optional titleLength: number

The total length of the colored background area of titles.

Defined in: get-help.ts:18


usage

Optional usage: string | string[]

Uasge text is shown at the beginning of help text. Lines are prefixed with $ and command is colored automatically.

Defined in: get-help.ts:26

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.3

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.0.2

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago