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

Provide JSDoc comments for flag properties #230

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 64 additions & 0 deletions index.d.ts
Expand Up @@ -16,11 +16,75 @@ Callback function to determine if a flag is required during runtime.
export type IsRequiredPredicate = (flags: Readonly<AnyFlags>, input: readonly string[]) => boolean;

export type Flag<Type extends FlagType, Default, IsMultiple = false> = {
/**
Type of value. (Possible values: `string` `boolean` `number`)
*/
readonly type?: Type;

/**
A short flag alias.

@example
```
unicorn: {
shortFlag: 'u'
}
```
*/
readonly shortFlag?: string;

/**
Default value when the flag is not specified.

@example
```
unicorn: {
type: 'boolean',
default: true,
}
```
*/
readonly default?: Default;

/**
Determine if the flag is required.

If it's only known at runtime whether the flag is required or not you can pass a Function instead of a boolean, which based on the given flags and other non-flag arguments should decide if the flag is required.

@default false

@example
```
isRequired: (flags, input) => {
if (flags.otherFlag) {
return true;
}

return false;
}
```
*/
readonly isRequired?: boolean | IsRequiredPredicate;

/**
Indicates a flag can be set multiple times. Values are turned into an array.

Multiple values are provided by specifying the flag multiple times, for example, `$ foo -u rainbow -u cat`. Space- or comma-separated values are *not* supported.

@default false
*/
readonly isMultiple?: IsMultiple;

/**
Other names for the flag.

@example
```
unicorn: {
aliases: ['unicorns', 'u']
tommy-mitchell marked this conversation as resolved.
Show resolved Hide resolved
}
```
*/
readonly aliases?: string[];
};

Expand Down