Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support array-type #1

Merged
merged 4 commits into from
Dec 6, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: updated readme
  • Loading branch information
privatenumber committed Dec 6, 2021
commit 1b464494091b37f100c565b7cf8c0fc5a1a0633a
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ const parsed = typeFlag(process.argv.slice(2), {
someBoolean: {
type: Boolean,
alias: 'b'
},

// Wrap with an array to indicate an array type
stringArray: [String],

numberArray: {
type: [Number]
}
})

Expand All @@ -46,9 +53,11 @@ console.log(parsed.flags.someString[0])
```ts
{
flags: {
someString: string[];
someNumber: boolean[];
someBoolean: number[];
someString: string | undefined;
someNumber: boolean | undefined;
someBoolean: number | undefined;
stringArray: string[];
numberArray: number[];
};
unknownFlags: {
[flagName: string]: (string | boolean)[];
Expand Down Expand Up @@ -142,7 +151,7 @@ const parsed = typeFlag(process.argv.slice(2), {
```ts
const parsed: {
flags: {
size: Sizes[];
size: Sizes | undefined;
};
...
}
Expand Down Expand Up @@ -206,7 +215,7 @@ $ node ./cli --boolean-flag false
```ts
{
flags: {
booleanFlag: [true]
booleanFlag: true
},
_: ['false']
}
Expand All @@ -220,7 +229,7 @@ Returns an object with the shape:
```ts
{
flags: {
[flagName: string]: InferredType[];
[flagName: string]: InferredType;
};
unknownFlags: {
[flagName: string]: (string | boolean)[];
Expand All @@ -241,8 +250,8 @@ Type:
type TypeFunction = (argvValue: any) => any;

type FlagSchema = {
[flagName: string]: TypeFunction | {
type?: TypeFunction; // defaults to String
[flagName: string]: TypeFunction | [TypeFunction] | {
type: TypeFunction | [TypeFunction];
alias?: string;
};
};
Expand Down