{"name":"@percy/cli-command","version":"1.31.4-beta.2","license":"MIT","_id":"@percy/cli-command@1.31.4-beta.2","maintainers":[{"name":"percy-admin","email":"apps+npm@percy.io"}],"homepage":"https://github.com/percy/cli#readme","bugs":{"url":"https://github.com/percy/cli/issues"},"bin":{"percy-cli-readme":"bin/readme.js"},"dist":{"shasum":"45cc8b2fcae2053cb31ecb63ccb5637c89fcf454","tarball":"http://registry-npm.ywwl.com/@percy/cli-command/download/@percy/cli-command-1.31.4-beta.2.tgz","fileCount":12,"integrity":"sha512-o4rzpNjLw1oO+ERwfon1vq2STcANmMNlSOwIVjKZvWoSmWJMArNfLfwiFHNsqpMo2EfgIR6AOq4k2dGXmmqX2Q==","signatures":[{"sig":"MEUCIDZCDx7s+50fHnAcroIGQ6v2YiBMtRaVXrdMeKXcDHlrAiEAoqObmwXtaWWG3EZk4HTqt6a0pbUcgrwJt3QLoeiNPRM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":52375,"size":15977,"noattachment":false,"key":"/@percy/cli-command/-/@percy/cli-command-1.31.4-beta.2.tgz"},"main":"./dist/index.js","type":"module","engines":{"node":">=14"},"exports":{".":"./dist/index.js","./flags":"./dist/flags.js","./utils":"./dist/utils.js","./test/helpers":"./test/helpers.js"},"gitHead":"a0bd772d1d41454683a15b5c5223f7fc571f3b29","scripts":{"lint":"eslint --ignore-path ../../.gitignore .","test":"node ../../scripts/test","build":"node ../../scripts/build","test:coverage":"yarn test --coverage"},"_npmUser":{"name":"percy-admin","email":"apps+npm@percy.io"},"repository":{"url":"git+https://github.com/percy/cli.git","type":"git","directory":"packages/cli-command"},"_npmVersion":"lerna/6.0.1/node@v14.21.3+x64 (linux)","description":"Percy CLI command parser and runner.","directories":{},"_nodeVersion":"14.21.3","dependencies":{"@percy/core":"1.31.4-beta.2","@percy/config":"1.31.4-beta.2","@percy/logger":"1.31.4-beta.2"},"publishConfig":{"tag":"beta","access":"public"},"_hasShrinkwrap":false,"readmeFilename":"README.md","_npmOperationalInternal":{"tmp":"tmp/cli-command_1.31.4-beta.2_1760600395541_0.09352265221404421","host":"s3://npm-registry-packages-npm-production"},"readme":"# @percy/cli-command\n\nPercy CLI command parser and runner.\n\n- [Usage](#usage)\n- [Options](#options)\n  - [Args](#args)\n  - [Flags](#flags)\n  - [Percy](#percy)\n\n## Usage\n\nThe `command` function accepts a name, definition, and callback and returns a runner function that\naccepts an array of command-line arguments.\n\n``` js\nimport command from '@percy/cli-command';\n\n// example command runner\nconst example = command('example', {\n  description: 'Example command description',\n  // positional arguments\n  args: [\n    { name: 'one' }\n  ],\n  // flags and options\n  flags: [\n    { name: 'foo' }, // boolean by default\n    { name: 'bar', type: 'string' }\n  ],\n  // shows in help output\n  examples: [\n    // $0 will be replaced by the command name\n    '$0 --foo --bar baz qux'\n  ]\n}, ({ flags, args }) => {\n  // see below for other available properties\n  console.log({ flags, args });\n});\n\n// remove the script name from argv\nexample(process.argv.slice(2));\n```\n\n``` shell\n$ node ./example --foo --bar baz qux\n{ flags: { foo: true, bar: 'baz' }, args: { one: 'qux' } }\n```\n\n## Options\n\nOnly a command `name` is required. However, without any other options, a command will only show the\ndefault help output with global flags. A command's `callback` will be called when the resulting\ncommand runner is invoked with an array of command-line arguments. How those arguments are\ninterpreted and parsed is defined by the command's `definition`.\n\n- `name` — The command name shown in help output, also used to match nested commands.\n- `definition` — A command definition object defines various options to control help output, the\n  arguments parser, and other percy options.\n  - `description` — The command description shown in help output.\n  - `usage` — Custom command usage shown in help output.\n  - `examples` — An array of example strings to show in help output.\n  - `version` — A version string to display via a `-V, --version` flag.\n  - `commands` — An array or function returning an array of nested subcommands.\n  - `flags` — Optional flag arguments accepted by the command ([see below](#flags)).\n  - `args` — Positional arguments accepted by the command ([see below](#args)).\n  - `percy` — Enable creation of a core percy instance ([see below](#percy)).\n  - `config` — Automatic percy config registration ([see below](#percy)).\n  - `loose` — Push unknown arguments to `argv`. A string value will log as a warning when unknown\n    arguments are first encountered by the parser.\n  - `exitOnError` — Call `process.exit()` if the command encounters an error while running.\n- `callback` — The command callback invoked after the runner is called with command-line arguments\n  and after those arguments are interpreted by the internal parser.\n\nThe `callback` argument can be a function, an async function, or an async generator function. Given\nan async generator function, the command becomes cancelable via process interruption and is able to\nclean up after itself using traditional try-catch error handling.\n\nThe `callback` function is invoked with a single argument containing various contextual properties\naccording to the command definition:\n\n- `flags` — An object containing key-value pairs of flag arguments interpreted by the parser as\n  determined by the flag's respective definition ([see below](#flags)).\n- `args` — An object containing key-value pairs of positional arguments interpreted by the parser as\n  determined by the arg's respective definition ([see below](#args)).\n- `argv` — An array of unknown arguments that were not parsed due to either the `loose` option or\n  the presence of an end-of-arguments delimiter (`--`).\n- `percy` — An instance of `@percy/core` only present when a corresponding `percy` definition option\n  is provided ([see below](#percy)).\n- `log` — A `@percy/logger` group namespaced under the command's `name`. The initial loglevel is\n  optionally determined by various global logging flags (`--verbose`, `--silent`, `--quiet`).\n- `exit` — Utility function to stop the execution of a command from within the runner. Accepts\n  an exit code (default `1`) and an exit reason (default `'EEXIT: ${exitCode}'`). The function will\n  throw an error which can be handled, or let bubble where the presence of `exitOnError` will cause\n  the process to exit with the provided exit code.\n\n### Flags\n\nEach flag definition must contain either a `name` or a `short` option. By default, all flags will be\ninterpreted as boolean flags and will produce an error if a value is provided. Setting the `type`\noption to anything other than `'boolean'` will allow providing command-line values and error if one\n_is not_ provided.\n\n- `name` — The flag name (i.e. `--flag-name`).\n- `short` — The flag short character (i.e. `-s`).\n- `type` — The flag type as displayed in help output.\n- `default` — The flag's default value when not provided.\n- `parse` — A function used to parse any provided flag value.\n- `validate` — A function that should throw an error when the provided flag value is invalid.\n- `attribute` — A string or function returning a string to set the value at on the `callback`\n  argument's `flags` property. Defaults to the camelcase `name` or `short` character.\n- `percyrc` — A string to map this flag to percy config options ([see below](#percy)).\n- `deprecated` — A boolean, string, or tuple used to warn about a deprecated flag and optionally map\n  it to an alternate flag ([see below](#deprecations)).\n\n### Args\n\nPositional args correspond to their definition index, so the arg definition at index `0` will match\nthe first provided command-line argument that is not a flag or subcommand. By default, positional\nargs are optional, but can be configured to be required or have default values.\n\n- `name` — The arg name shown in help output.\n- `required` — Indicate that this flag is required, which causes an error when not provided.\n- `default` — The arg's default value when not provided.\n- `parse` — A function used to parse the provided argument.\n- `validate` — A function that should throw an error when the provided argument is invalid.\n- `attribute` — A string or function returning a string to set the value at on the `callback`\n  argument's `args` property. Defaults to camelcase `name`.\n- `percyrc` — A string to map this arg to percy config options ([see below](#percy)).\n- `deprecated` — A boolean, string, or tuple used to warn about a deprecated arg and optionally map\n  it to a flag ([see below](#deprecations)).\n\n#### Deprecations\n\nWhen the `deprecated` option is `true` and the flag or positional arg has been provided by\ncommand-line arguments, a deprecation warning will be logged. A string value indicates the version\nin which this argument will be removed and is reflected in the deprecation message.\n\n<details>\n  <summary>Remapping deprecated arguments</summary><br>\n\nWhen providing a tuple, the version is the first option of the tuple, while the second option can be\nan alternate flag to use, or a recommendation message to display when the deprecation warning is\nlogged. Given an alternate flag, the value will be automatically mapped to the corresponding flag's\nattribute name on the `callback` argument's `flags` property.\n\n``` js\n{ name: 'foo', deprecated: true }\n// [percy] Warning: The '--foo' option will be removed in a future release.\n\n{ name: 'foo', deprecated: 'v2.0.0' }\n// [percy] Warning: The '--foo' option will be removed in v2.0.0.\n\n{ name: 'foo', deprecated: ['v2.0.0', '--bar'] }\n// [percy] Warning: The '--foo' option will be removed in v2.0.0. Use '--bar' instead.\n\n{ name: 'foo', deprecated: ['v2.0.0', 'Use the config file option instead.'] }\n// [percy] Warning: The '--foo' option will be removed in v2.0.0. Use the config file option instead.\n```\n</details>\n\n### Percy\n\nThe `percy` definition option accepts an object consisting of `@percy/core` options. The presence of\nthis option will add shared percy flags to accepted command-line arguments and provide the command\ncallback with a percy instance initialized with the provided options.\n\nWhen the `percy` definition option is `true`, shared percy flags will not be accepted, but a default\npercy instance will still be provided to the command callback when run. Regardless of the `percy`\noption, if the environment variable `PERCY_ENABLE` is `0`, the callback _will not_ receive a percy\ninstance (and can act accordingly).\n\n- `percy` — Enables creation of a `@percy/core` instance initialized with provided options.\n\n#### Config\n\nAcceptable percy config file options can be extended before the file is loaded via\n`PercyConfig.addSchema()` and `PercyConfig.addMigration()`. These functions can be called before the\ncommand is run to achieve the same effect as including them in the command definition. However, the\npresence of a `percy` definition option will also signal `@percy/core` config schemas and migrations\nto be automatically registered before the following options are registered.\n\n- `config` — Percy config schemas and migrations to register while creating the command runner.\n  - `schemas` — An array of percy config schemas to automatically register.\n  - `migrations` — An array of percy config migrations to automatically register.\n\nAdditionally, flags and positional arguments that define a `percyrc` option will have their\nassociated values mapped to a corresponding `percy` property that is used when initializing a\n`@percy/core` instance. Provided options are validated against config schemas and are made available\non the command callback argument's `percy.config` property.\n","publish_time":1760600395772,"_cnpm_publish_time":1760600395772,"dist-tags":{"alpha":"1.31.15-alpha.0","beta":"1.33.0-beta.0","latest":"1.33.1"}}