meow inspired parseArgs() based CLI parser. Also contains help text helpers
const { flags } = peowly({
options: {
fix: {
description: 'Fixes stuff',
type: 'boolean',
},
},
});See example/basic.js
peowly(options): { flags, input, remainderArgs, showHelp }These options control how command-line arguments are parsed and define the CLI flags/options your tool accepts:
args- string[] - same as forparseArgs()(defaults toprocess.argvwithexecPathandfilenameremoved)options-Flags- superset of that ofparseArgs(). Every option / flag is expected to have adescriptionstring property in addition to whatparseArgs()require and they may have alistGroupstring property as wellreturnRemainderArgs- boolean - if set, then all parts ofargsthat doesn't match a flag inoptionswill be returned asremainderArgs, which can eg. be forwarded to another parser
These options configure help text, process metadata, and other CLI tool presentation:
description- string | false - a description that will be prefixed to the help text (defaults topkg.description, deactivated byfalse)examples- seeHelpMessageInfohelp- string - the help text to show on--help, preferably generated withformatHelpMessage()(defaults to being rendered withformatHelpMessage()using available data)indent- seeHelpMessageInfoname- string - the name of the CLI command. Used by a couple of other defaults. (defaults to the first key inpkg.binand else topkg.name)pkg-PackageJsonLike- apackage.jsonwhich some meta data can be derived fromprocessTitle- string | false - sets theprocess.titleto this (defaults toname, deactivated byfalse)usage- seeHelpMessageInfoversion- string - the version to show on--version(defaults topkg.version)
formatHelpMessage(name: string, info?: HelpMessageInfo): stringname- string - the name of the CLI command
aliases-HelpListBasic- list of help items to join withcommandsbut with group name defaulting to'Aliases'and other group names being prefixed with' Aliases'commands-HelpListBasic- list of help items to add prior to the flags list and with a default group name of'Commands'examples-(string | { prefix?: string, suffix?: string })[]- will be added as examples on individual lines prefixed with$ ${name}or, if provided as prefix and suffix, then the prefix will go inbetween$and thenameand the suffix after that, separated by spacesflags-HelpList- the flags to output in the help, compatible withFlagsindent- number - the number of spaces to indent the help text with (defaults to2)noDefaultFlags- boolean - excludes the default flags from the help textusage- string - what, if anything, that follows the$ ${name}in'Usage'headline in the initial help text
import type { AnyFlag } from 'peowly';
interface HelpListBasicItem {
listGroup?: string;
description: string;
}
type HelpListItem = AnyFlag | HelpListBasicItem;
type HelpListBasic = Record<string, HelpListBasicItem>;
type HelpList = Record<string, HelpListItem | string>;Contains the definition of the two default flags --help and --version.
Most of the time you should use formatHelpMessage() instead.
function formatHelpList(list: HelpList, indent: number, options?: HelpListOptions): stringlist- HelpList - the list that represents the flags, see types informatHelpMessage()indent- number - how far to indent the list
fixedPadName- boolean - when set,padNamewill be treated as a fixed rather than minimum paddingkeyPrefix- string - a prefix for the namepadName- number - the minimum padding between names and descriptionsshortFlagPrefix- string - a prefix for ashortFlag(defaults to'-')
function formatFlagList(list: HelpList, indent: number, options?: HelpListOptions): stringSame as formatHelpList() but with the keyPrefix option defaulting to '--'.
formatGroupedHelpList(list: HelpList, indent: number, options?: HelpListGroupOptions): stringSimilar to formatHelpList() but prints help items grouped and has some additional options to support it in that.
Same as HelpListOptions but with these additional options:
alignWithinGroups- boolean - when set (and unlessfixedPadNameis set) the padding between name and description will be calculated within each group instead of across all groupsdefaultGroupName- string - the default group name where all items that have no explicit group belonging will be placed (defaults to'Default')defaultGroupOrderFirst- boolean - if set the default group is added at the start rather than at the end
formatGroupedFlagList(list: HelpList, indent: number, options?: HelpListGroupOptions): stringSame as formatGroupedHelpList() but with the keyPrefix option defaulting to '--' and defaultGroup defaulting to 'Options'.
argsclopts- also concerned with generating help texts forparseArgs()meow- a more full fledged alternative and name inspiration (pas inparseArgs,eowas inmeow,lyto avoid being perceived as a typejacking)meow-with-subcommands- a companion module tomeowthat provides the same help functionality as this modulepeowly-commands- a companion module to this module that makes it on par withmeow-with-subcommands
parseArgs()- the node.js API this module is built around. Available sincev18.3.0andv16.17.0, non-experimental sincev20.0.0.