UNPKG

@augment-vir/node

Version:

A collection of augments, helpers types, functions, and classes only for Node.js (backend) JavaScript environments.

56 lines (55 loc) 2.01 kB
/** * Input for extractRelevantArgs. * * @category Node : Terminal : Util * @category Package : @augment-vir/node * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node) */ export type RelevantArgsInput = { /** Raw arguments passed to the CLI. Typically this will simply be process.argv. */ rawArgs: ReadonlyArray<string>; /** * Executable bin name for your script. This should be the "bin" name in your package.json, or * simply your package name if you have no custom bin name defined. * * See https://docs.npmjs.com/cli/v10/configuring-npm/package-json#bin for details on the bin * field of package.json */ binName: string | undefined; /** * The name or path of your script file that will be executed via the CLI. This should almost * always simply be __filename in CJS or `import.meta.filename` in ESM. */ fileName: string; /** * If set to true, this function with throw an error if the given file or bin name was not found * in the given arguments list. */ errorIfNotFound?: boolean | undefined; }; /** * Trims arguments list to remove all arguments that take place before the script's file name or * executable bin name. * * @category Node : Terminal * @category Package : @augment-vir/node * @example * * ```ts * extractRelevantArgs({ * rawArgs: [ * 'npx', * 'ts-node', * './my-script.ts', * 'arg1', * '--arg2', * ], // typically will be process.argv * binName: 'my-script', // should be your package.json "bin" property name, can be undefined * fileName: 'my-script.ts', // should be __filename from the script that will be executed * }); * // will output ['arg1', '--arg2'] * ``` * * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node) */ export declare function extractRelevantArgs({ rawArgs, binName, fileName, errorIfNotFound, }: Readonly<RelevantArgsInput>): string[];