1.0.5 • Published 16 days ago

config-from-argv v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
16 days ago

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

1.0.5

16 days ago

1.0.4

16 days ago

1.0.2

17 days ago

1.0.3

17 days ago

1.0.1

9 months ago

1.0.0

9 months ago