From 93b490c8e478b35fbcc14cff49122b1b60e6f01c Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Sat, 4 Feb 2023 14:25:36 -0600 Subject: [PATCH] chore: update readme --- .changeset/bright-nails-march.md | 5 +++++ README.md | 30 ++++++++++++++++++++++++++++-- src/index.ts | 4 +--- src/types.ts | 11 +---------- 4 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 .changeset/bright-nails-march.md diff --git a/.changeset/bright-nails-march.md b/.changeset/bright-nails-march.md new file mode 100644 index 0000000..26d1469 --- /dev/null +++ b/.changeset/bright-nails-march.md @@ -0,0 +1,5 @@ +--- +"ultraflag": patch +--- + +Update README diff --git a/README.md b/README.md index 4915a93..aba85f1 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,35 @@ # `ultraflag` -A <1kB library for parsing CLI flags. +A <1kB library for parsing CLI flags. Inspired by Deno's `std` [`flags`](https://github.com/denoland/deno_std/blob/main/flags/mod.ts) module. ### Features - It's very small. - It's very fast. -- I need to write docs. + +### Usage + +Basic usage does not require any configuration. + +```js +import { parse } from "ultraflag"; + +// my-cli build --bundle -rf --a value --b=value --c 1 +const argv = process.argv.slice(2); +const args = parse(argv); + +console.log(args); +// { _: ['build'], bundle: true, r: true, f: true, a: "value", b: "value", c: 1 } +``` + +Parsing can be configured to ensure values are handled in a certain format. + +```js +const args = parse(argv, { + default: { a: 1, b: 2, c: "value" }, + alias: { h: "help" }, + boolean: ["foo", "bar"], + string: ["baz", "qux"], + array: ["input"], +}); +``` diff --git a/src/index.ts b/src/index.ts index 0605e2c..58f958e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,6 @@ import type { BooleanType, StringType, Collectable, - Negatable, Aliases, } from "./types.js"; export { ParseOptions, Args } from "./types.js"; @@ -69,14 +68,13 @@ export function parse< TBooleans, TStrings, TCollectable, - TNegatable, + undefined, TDefaults, TAliases >, TBooleans extends BooleanType = undefined, TStrings extends StringType = undefined, TCollectable extends Collectable = undefined, - TNegatable extends Negatable = undefined, TDefaults extends Record | undefined = undefined, TAliases extends Aliases | undefined = undefined, TAliasArgNames extends string = string, diff --git a/src/types.ts b/src/types.ts index 4ac886b..168a987 100644 --- a/src/types.ts +++ b/src/types.ts @@ -211,8 +211,7 @@ type ValueOf = TValue[keyof TValue]; /** The value returned from `parse`. */ export type Args< // deno-lint-ignore no-explicit-any - TArgs extends Record = Record, - TDoubleDash extends boolean | undefined = undefined, + TArgs extends Record = Record > = Id< & TArgs & { @@ -220,16 +219,8 @@ export type Args< * them. */ _: Array; } - & (boolean extends TDoubleDash ? DoubleDash - : true extends TDoubleDash ? Required - : Record) >; -type DoubleDash = { - /** Contains all the arguments that appear after the double dash: "--". */ - "--"?: Array; -}; - /** The options for the `parse` call. */ export interface ParseOptions< TBooleans extends BooleanType = BooleanType, -- 2.51.2