meow

repository·main·Indexed 25 days ago

https://github.com/sindresorhus/meow

A lightweight CLI app helper for parsing arguments, handling flags with camelCase conversion and negation, and managing help and version output.

Tokens
571
Snippets
1
Records
3
Agent score
37%

What's inside meow

  1. Configure meow options

    main

    When calling meow, you can pass an options object to control parsing behavior and help output:

    • flags: An object defining expected flags. Each flag can have type, aliases (array), and shortFlag (string).
    • commands: An array of valid command strings. If the first positional argument is not in this list, meow will report an error and show help.
    • allowUnknownFlags: Boolean. If false (default), meow will throw an error if unknown flags are detected.
    • autoHelp: Boolean. If true, automatically shows help when --help is passed.
    • autoVersion: Boolean. If true, automatically shows version when --version is passed.
    • description: A string describing the CLI. If provided, it is prepended to the help text.
    • helpIndent: A string used to indent the help text (e.g., \t).
    • pkg: The package metadata object.
    • getPackage: A function that returns the package metadata object.
    • version: The version string to display.
    • argv: The raw command-line arguments (defaults to process.argv).
  2. Use meow to parse CLI arguments

    main

    The meow function is the primary entrypoint for parsing command-line arguments, handling flags, and managing help/version displays. It returns an object containing the parsed input, the active command, and a flags object with camelCased keys.

    It can be called in two ways:

    1. meow(helpText, options): Where helpText is a string used for the help display.
    2. meow(options): Where the help text is provided within the options object.

    The returned object includes:

    • input: An array of positional arguments (excluding the command).
    • command: The detected command string (if options.commands is configured).
    • flags: An object containing the parsed flags with camelCased keys.
    • unnormalizedFlags: An object containing the parsed flags with original keys.
    • pkg: The package metadata (via a getPackage getter or the provided pkg object).
    • help: The formatted help text string.
    • showHelp(code?): A function to print the help text and exit the process. Defaults to exit code 2 if no code is provided.
    • showVersion(): A function to print the version and exit the process with code 0.