2.1.1 • Published 1 year ago

mclip v2.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

mclip

Build Status

Minimal cli args parser.

Installation

npm install mclip

Usage

import { mclip } from "mclip";

const options = mclip(process.argv);

Why named export?

Module is a namespace, and interop with commonjs is broken in many cases or hard to maintain. It's not really worth it.

Defining default values

It's possible to define a default value for an option in case it's not specified in the argv

import { mclip } from "mclip";

const options = mclip(process.argv, {
  boo: { description: "This option does something" },
  foo: { default: "banana", description: "Sets the foo", short: "f" },
  tem: { short: "t", default: true },
});

If you use Typescript the type of options returned will be:

{
  boo: string | boolean | undefined;
  foo: string;
  help?: boolean;
  list: string[];
  tem: boolean;
}

Positional arguments

Positional arguments will be found in a list property in the returned options.

./my-script mama -f=3 lama
const { mclip } = require("mclip");

const options = mclip(process.argv);

console.log(options); // { foo: '3', list: [ 'mama', 'lama' ] }

Printing usage information

It's possible to define descriptions about the expected parameters; if the script is called with --help it will print the usage informations and exit.

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.0

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago