config-from-argv
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

workflow

config-from-argv

Command-line argument parser for CLI scripts written in Javascript or TypeScript.

Usage

Define a base config:

const baseConfig = {
  printExtraLines: false,
  inputFile: "input.txt",
  leftPaddingAmount: 10,
};

Tell config-from-argv how to map command-line arguments to your baseConfig:

import { ConfigToCLIOpt } from "config-from-argv";

const configToCLIOpt: ConfigToCLIOpt<typeof baseConfig> = {
  printExtraLines: "-x",
  inputFile: "-f_string",
  leftPaddingAmount: "-p_number",
};

In the example above:

  • -x will set printExtraLines to the boolean true
  • -f other.txt will set inputFile to the string "other.txt"
  • -p 30 will set leftPaddingAmount to the number 30

Last Step

Call newConfigFromArgv to get the final configuration:

import { newConfigFromArgv } from "config-from-argv";

const config = newConfigFromArgv(baseConfig, configToCLIOpt, process.argv.slice(2));

Behavior

The behavior of this library is described in src/lib/main.spec.ts

Examples

Note: install project's node modules before trying out the examples:

$ npm install # in project root

Dependency Graph

Graph showing how this library is structured:

Dependency Graph

Readme

Keywords

Package Sidebar

Install

npm i config-from-argv

Weekly Downloads

185

Version

1.0.5

License

MIT

Unpacked Size

25 kB

Total Files

37

Last publish

Collaborators

  • desm