Class: Args
Defined in: projects/framework/src/lib/parsers/Args.ts:31
The argument parser to be used in Command.
Constructors
Constructor
new Args(
message:Message,command:MessageCommand,parser:ArgumentStream,context:MessageCommandContext):Args
Defined in: projects/framework/src/lib/parsers/Args.ts:59
Parameters
| Parameter | Type |
|---|---|
message | Message |
command | MessageCommand |
parser | ArgumentStream |
context | MessageCommandContext |
Returns
Args
Properties
command
readonlycommand:MessageCommand
Defined in: projects/framework/src/lib/parsers/Args.ts:40
The command that is being run.
commandContext
readonlycommandContext:MessageCommandContext
Defined in: projects/framework/src/lib/parsers/Args.ts:45
The context of the command being run.
message
readonlymessage:Message
Defined in: projects/framework/src/lib/parsers/Args.ts:35
The original message that triggered the command.
parser
protectedreadonlyparser:ArgumentStream
Defined in: projects/framework/src/lib/parsers/Args.ts:50
The internal Lexure parser.
Accessors
finished
Get Signature
get finished():
boolean
Defined in: projects/framework/src/lib/parsers/Args.ts:725
Whether all arguments have been consumed.
Returns
boolean
Methods
getFlags()
getFlags(...
keys: readonlystring[]):boolean
Defined in: projects/framework/src/lib/parsers/Args.ts:615
Checks if one or more flag were given.
Parameters
| Parameter | Type | Description |
|---|---|---|
...keys | readonly string[] | The name(s) of the flag. |
Returns
boolean
Example
// Suppose args are from '--f --g'.
console.log(args.getFlags('f'));
// >>> true
console.log(args.getFlags('g', 'h'));
// >>> true
console.log(args.getFlags('h'));
// >>> false
getOption()
getOption(...
keys: readonlystring[]):null|string
Defined in: projects/framework/src/lib/parsers/Args.ts:658
Gets the last value of one or more options.
Similar to Args.getOptionResult but returns the value on success, or null if not.
Parameters
| Parameter | Type | Description |
|---|---|---|
...keys | readonly string[] | The name(s) of the option. |
Returns
null | string
Example
// Suppose args are from '--a=1 --b=2 --c=3'.
console.log(args.getOption('a'));
// >>> '1'
console.log(args.getOption('b', 'c'));
// >>> '2'
console.log(args.getOption('d'));
// >>> null
getOptionResult()
getOptionResult(...
keys: readonlystring[]):Option<string>
Defined in: projects/framework/src/lib/parsers/Args.ts:637
Gets the last value of one or more options as an Option.
If you do not care about safely handling non-existing values
you can use Args.getOption to get string | null as return type
Parameters
| Parameter | Type | Description |
|---|---|---|
...keys | readonly string[] | The name(s) of the option. |
Returns
Option<string>
Example
// Suppose args are from '--a=1 --b=2 --c=3'.
console.log(args.getOptionResult('a'));
// >>> Some { value: '1' }
console.log(args.getOptionResult('b', 'c'));
// >>> Some { value: '2' }
console.log(args.getOptionResult('d'));
// >>> None {}
getOptions()
getOptions(...
keys: readonlystring[]):null| readonlystring[]
Defined in: projects/framework/src/lib/parsers/Args.ts:702
Gets all the values of one or more option.
Similar to Args.getOptionsResult but returns the value on success, or null if not.
Parameters
| Parameter | Type | Description |
|---|---|---|
...keys | readonly string[] | The name(s) of the option. |
Returns
null | readonly string[]
Example
// Suppose args are from '--a=1 --a=1 --b=2 --c=3'.
console.log(args.getOptions('a'));
// >>> ['1', '1']
console.log(args.getOptions('b', 'c'));
// >>> ['2', '3']
console.log(args.getOptions('d'));
// >>> null
getOptionsResult()
getOptionsResult(...
keys: readonlystring[]):Option<readonlystring[]>
Defined in: projects/framework/src/lib/parsers/Args.ts:681
Gets all the values of one or more option.
Parameters
| Parameter | Type | Description |
|---|---|---|
...keys | readonly string[] | The name(s) of the option. |
Returns
Option<readonly string[]>
Example
// Suppose args are from '--a=1 --a=1 --b=2 --c=3'.
console.log(args.getOptionsResult('a'));
// >>> Some { value: [ '1' ] }
console.log(args.getOptionsResult('a', 'd'));
// >>> Some { value: [ '1' ] }
console.log(args.getOptionsResult('b', 'c'));
// >>> Some { value: [ '2', '3' ] }
console.log(args.getOptionsResult('d'));
// >>> None {}
missingArguments()
protectedmissingArguments():Err<UserError>
Defined in: projects/framework/src/lib/parsers/Args.ts:747
Returns
Err<UserError>
next()
Call Signature
next():
string
Defined in: projects/framework/src/lib/parsers/Args.ts:576
Similar to Args.nextMaybe but returns the value on success, null otherwise.
Returns
string
Example
// !numbers 1 2 3
console.log(args.next());
// -> '1'
Call Signature
next<
T>(cb:ArgsNextCallback<T>):T
Defined in: projects/framework/src/lib/parsers/Args.ts:593
Similar to Args.nextMaybe but returns the value on success, null otherwise.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
cb | ArgsNextCallback<T> | Gives an option of either the resulting value, or nothing if failed. |
Returns
T
Typeparam
T Output type of the callback.
Example
// !numbers 1 2 3
const parse = (x: string) => {
const n = Number(x);
return Number.isNaN(n) ? none() : some(n);
};
console.log(args.nextMaybe(parse));
// -> 1
nextMaybe()
Call Signature
nextMaybe():
Option<string>
Defined in: projects/framework/src/lib/parsers/Args.ts:543
Retrieves the next raw argument from the parser.
Returns
Option<string>
Example
// !numbers 1 2 3
console.log(args.nextMaybe());
// -> { exists: true, value: '1' }
Call Signature
nextMaybe<
T>(cb:ArgsNextCallback<T>):Option<T>
Defined in: projects/framework/src/lib/parsers/Args.ts:561
Retrieves the value of the next unused ordered token, but only if it could be transformed. That token will now be used if the transformation succeeds.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
cb | ArgsNextCallback<T> | Gives an option of either the resulting value, or nothing if failed. |
Returns
Option<T>
Typeparam
T Output type of the callback.
Example
// !numbers 1 2 3
const parse = (x: string) => {
const n = Number(x);
return Number.isNaN(n) ? none() : some(n);
};
console.log(args.nextMaybe(parse));
// -> { exists: true, value: 1 }
peek()
Call Signature
Defined in: projects/framework/src/lib/parsers/Args.ts:481
Similar to Args.peekResult but returns the value on success, throwing otherwise.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | () => Result<T> | The function, custom argument, or argument name. |
Returns
Promise<T>
Example
// !bigintsumthensquarefirst 25 50 75
const resolver = Args.make((arg, { argument }) => {
try {
return Args.ok(BigInt(arg));
} catch {
return Args.error({ parameter: arg, argument, identifier: 'InvalidBigInt', message: 'You must specify a valid number for a bigint.' })
}
});
const peeked = await args.repeatResult(resolver);
await peeked.inspectAsync((value) => message.channel.send(`Sum: **${value.reduce((x, y) => x + y, 0n)}**`)); // Sum: 150n
const first = await args.pick(resolver);
await message.channel.send(`First bigint squared: ${first**2n}`); // First bigint squared: 625
Call Signature
peek<
T>(type:IArgument<T>,options?:ArgOptions):Promise<T>
Defined in: projects/framework/src/lib/parsers/Args.ts:510
Similar to Args.peekResult but returns the value on success, throwing otherwise.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | IArgument<T> | The function, custom argument, or argument name. |
options? | ArgOptions | The peek options. |
Returns
Promise<T>
Example
import { SnowflakeRegex } from '@sapphire/discord.js-utilities';
import { DiscordSnowflake } from '@sapphire/snowflake';
// !createdat 730159185517477900
const snowflakeResolver = Args.make<bigint>((arg, { argument }) => {
return SnowflakeRegex.test(arg)
? Args.ok(BigInt(arg))
: Args.error({ parameter: arg, argument, identifier: 'InvalidSnowflake', message: 'You must specify a valid snowflake.' });
});
const snowflake = await args.peek(snowflakeResolver);
const timestamp = Number((snowflake >> 22n) + DiscordSnowflake.epoch);
const createdAt = new Date(timestamp);
await message.channel.send(
`The snowflake ${snowflake} was registered on ${createdAt.toUTCString()}.`
); // The snowflake 730159185517477900 was registered on Tue, 07 Jul 2020 20:31:55 GMT.
const id = await args.pick('string');
await message.channel.send(`Your ID, reversed: ${id.split('').reverse().join('')}`); // Your ID, reversed: 009774715581951037
Call Signature
peek<
K>(type:K| () =>Result<ArgType[K]>,options?:ArgOptions):Promise<ArgType[K]>
Defined in: projects/framework/src/lib/parsers/Args.ts:527
Similar to Args.peekResult but returns the value on success, throwing otherwise.
Type Parameters
| Type Parameter |
|---|
K extends keyof ArgType |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | K | () => Result<ArgType[K]> | The function, custom argument, or argument name. |
options? | ArgOptions | The peek options. |
Returns
Example
// !messagelink https://discord.com/channels/737141877803057244/737142209639350343/791843123898089483
const remoteMessage = await args.peek('message');
await message.channel.send(
`${remoteMessage.author.tag}: ${remoteMessage.content}`
); // RealShadowNova#7462: Yeah, Sapphire has been a great experience so far, especially being able to help and contribute.
const url = await args.pick('hyperlink');
await message.channel.send(`Hostname: ${url.hostname}`); // Hostname: discord.com
peekResult()
Call Signature
peekResult<
T>(type: () =>Result<T>):Promise<ResultType<T>>
Defined in: projects/framework/src/lib/parsers/Args.ts:403
Peeks the following parameter(s) without advancing the parser's state. Passing a function as a parameter allows for returning Args.pickResult, Args.repeatResult, or Args.restResult; otherwise, passing the custom argument or the argument type with options will use Args.pickResult and only peek a single argument.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | () => Result<T> | The function, custom argument, or argument name. |
Returns
Promise<ResultType<T>>
Example
// !reversedandscreamfirst hello world
const resolver = Args.make((arg) => Args.ok(arg.split('').reverse().join('')));
const result = await args.repeatResult(resolver);
await result.inspectAsync((value) =>
message.channel.send(`Reversed ${value.length} word(s): ${value.join(' ')}`)
); // Reversed 2 word(s): olleh dlrow
const firstWord = await args.pickResult('string');
await firstWord.inspectAsync((value) =>
message.channel.send(firstWord.value.toUpperCase())
); // HELLO
Call Signature
peekResult<
T>(type:IArgument<T>,options?:ArgOptions):Promise<ResultType<T>>
Defined in: projects/framework/src/lib/parsers/Args.ts:423
Peeks the following parameter(s) without advancing the parser's state. Passing a function as a parameter allows for returning Args.pickResult, Args.repeatResult, or Args.restResult; otherwise, passing the custom argument or the argument type with options will use Args.pickResult and only peek a single argument.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | IArgument<T> | The function, custom argument, or argument name. |
options? | ArgOptions | The peekResult options. |
Returns
Promise<ResultType<T>>
Example
// !reverseandscreamfirst sapphire community
const resolver = Args.make((arg) => Args.ok(arg.split('').reverse().join('')));
const peekedWord = await args.peekResult(resolver);
await peekedWord.inspectAsync((value) => message.channel.send(value)); // erihppas
const firstWord = await args.pickResult('string');
await firstWord.inspectAsync((value) => message.channel.send(value.toUpperCase())); // SAPPHIRE
Call Signature
peekResult<
K>(type:K| () =>Awaitable<Result<ArgType[K]>>,options?:ArgOptions):Promise<ResultType<ArgType[K]>>
Defined in: projects/framework/src/lib/parsers/Args.ts:445
Peeks the following parameter(s) without advancing the parser's state. Passing a function as a parameter allows for returning Args.pickResult, Args.repeatResult, or Args.restResult; otherwise, passing the custom argument or the argument type with options will use Args.pickResult and only peek a single argument.
Type Parameters
| Type Parameter |
|---|
K extends keyof ArgType |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | K | () => Awaitable<Result<ArgType[K]>> | The function, custom argument, or argument name. |
options? | ArgOptions | The peekResult options. |
Returns
Promise<ResultType<ArgType[K]>>
Example
// !datethenaddtwo 1608867472611
const date = await args.peekResult('date');
await date.inspectAsync((value) =>
message.channel.send(`Your date (in UTC): ${value.toUTCString()}`)
); // Your date (in UTC): Fri, 25 Dec 2020 03:37:52 GMT
const result = await args.pickResult('number', { maximum: Number.MAX_SAFE_INTEGER - 2 });
await result.inspectAsync((value) =>
message.channel.send(`Your number plus two: ${value + 2}`)
); // Your number plus two: 1608867472613
pick()
Call Signature
pick<
T>(type:IArgument<T>,options?:ArgOptions):Promise<T>
Defined in: projects/framework/src/lib/parsers/Args.ts:165
Similar to Args.pickResult but returns the value on success, throwing otherwise.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | IArgument<T> | The type of the argument. |
options? | ArgOptions | The pick options. |
Returns
Promise<T>
Example
// !square 5
const resolver = Args.make((parameter, { argument }) => {
const parsed = Number(parameter);
if (Number.isNaN(parsed)) {
return Args.error({ argument, parameter, identifier: 'ArgumentNumberNaN', message: 'You must write a valid number.' });
}
return Args.ok(parsed);
});
const a = await args.pick(resolver);
await message.channel.send(`The result is: ${a ** 2}!`);
// Sends "The result is: 25"
Call Signature
pick<
K>(type:K,options?:ArgOptions):Promise<ArgType[K]>
Defined in: projects/framework/src/lib/parsers/Args.ts:179
Similar to Args.pickResult but returns the value on success, throwing otherwise.
Type Parameters
| Type Parameter |
|---|
K extends keyof ArgType |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | K | The type of the argument. |
options? | ArgOptions | The pick options. |
Returns
Example
// !add 1 2
const a = await args.pick('integer');
const b = await args.pick('integer');
await message.channel.send(`The result is: ${a + b}!`);
// Sends "The result is: 3"
pickResult()
Call Signature
pickResult<
T>(type:IArgument<T>,options?:ArgOptions):Promise<ResultType<T>>
Defined in: projects/framework/src/lib/parsers/Args.ts:99
Retrieves the next parameter and parses it. Advances index on success.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | IArgument<T> | The type of the argument. |
options? | ArgOptions | The pickResult options. |
Returns
Promise<ResultType<T>>
Example
// !square 5
const resolver = Args.make((parameter, { argument }) => {
const parsed = Number(parameter);
if (Number.isNaN(parsed)) {
return Args.error({ argument, parameter, identifier: 'ArgumentNumberNaN', message: 'You must write a valid number.' });
}
return Args.ok(parsed);
});
const a = await args.pickResult(resolver);
if (!a.success) {
throw new UserError({ identifier: 'ArgumentNumberNaN', message: 'You must write a valid number.' });
}
await message.channel.send(`The result is: ${a.value ** 2}!`);
// Sends "The result is: 25"
Call Signature
pickResult<
K>(type:K,options?:ArgOptions):Promise<ResultType<ArgType[K]>>
Defined in: projects/framework/src/lib/parsers/Args.ts:121
Retrieves the next parameter and parses it. Advances index on success.
Type Parameters
| Type Parameter |
|---|
K extends keyof ArgType |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | K | The type of the argument. |
options? | ArgOptions | The pickResult options. |
Returns
Promise<ResultType<ArgType[K]>>
Example
// !add 1 2
const a = await args.pickResult('integer');
if (!a.success) {
throw new UserError({ identifier: 'AddArgumentError', message: 'You must write two numbers, but the first one did not match.' });
}
const b = await args.pickResult('integer');
if (!b.success) {
throw new UserError({ identifier: 'AddArgumentError', message: 'You must write two numbers, but the second one did not match.' });
}
await message.channel.send(`The result is: ${a.value + b.value}!`);
// Sends "The result is: 3"
repeat()
Call Signature
repeat<
T>(type:IArgument<T>,options?:RepeatArgOptions):Promise<T[]>
Defined in: projects/framework/src/lib/parsers/Args.ts:362
Similar to Args.repeatResult but returns the value on success, throwing otherwise.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | IArgument<T> | The type of the argument. |
options? | RepeatArgOptions | The repeat options. |
Returns
Promise<T[]>
Example
// !reverse-each 2 Hello World!
const resolver = Args.make((arg) => Args.ok(arg.split('').reverse()));
const result = await args.repeat(resolver, { times: 5 });
await message.channel.send(`You have written ${result.length} word(s): ${result.join(' ')}`);
// Sends "You have written 2 word(s): Hello World!"
Call Signature
repeat<
K>(type:K,options?:RepeatArgOptions):Promise<ArgType[K][]>
Defined in: projects/framework/src/lib/parsers/Args.ts:375
Similar to Args.repeatResult but returns the value on success, throwing otherwise.
Type Parameters
| Type Parameter |
|---|
K extends keyof ArgType |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | K | The type of the argument. |
options? | RepeatArgOptions | The repeat options. |
Returns
Example
// !add 2 Hello World!
const words = await args.repeat('string', { times: 5 });
await message.channel.send(`You have written ${words.length} word(s): ${words.join(' ')}`);
// Sends "You have written 2 word(s): Hello World!"
repeatResult()
Call Signature
repeatResult<
T>(type:IArgument<T>,options?:RepeatArgOptions):Promise<ArrayResultType<T>>
Defined in: projects/framework/src/lib/parsers/Args.ts:295
Retrieves all the following arguments.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | IArgument<T> | The type of the argument. |
options? | RepeatArgOptions | The repeatResult options. |
Returns
Example
// !add 2 Hello World!
const resolver = Args.make((arg) => Args.ok(arg.split('').reverse()));
const result = await args.repeatResult(resolver, { times: 5 });
if (!result.success) {
throw new UserError({ identifier: 'CountArgumentError', message: 'You must write up to 5 words.' });
}
await message.channel.send(`You have written ${result.value.length} word(s): ${result.value.join(' ')}`);
// Sends "You have written 2 word(s): olleH !dlroW"
Call Signature
repeatResult<
K>(type:K,options?:RepeatArgOptions):Promise<ArrayResultType<ArgType[K]>>
Defined in: projects/framework/src/lib/parsers/Args.ts:312
Retrieves all the following arguments.
Type Parameters
| Type Parameter |
|---|
K extends keyof ArgType |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | K | The type of the argument. |
options? | RepeatArgOptions | The repeatResult options. |
Returns
Promise<ArrayResultType<ArgType[K]>>
Example
// !reverse-each 2 Hello World!
const result = await args.repeatResult('string', { times: 5 });
if (!result.success) {
throw new UserError({ identifier: 'CountArgumentError', message: 'You must write up to 5 words.' });
}
await message.channel.send(`You have written ${result.value.length} word(s): ${result.value.join(' ')}`);
// Sends "You have written 2 word(s): Hello World!"
rest()
Call Signature
rest<
T>(type:IArgument<T>,options?:ArgOptions):Promise<T>
Defined in: projects/framework/src/lib/parsers/Args.ts:258
Similar to Args.restResult but returns the value on success, throwing otherwise.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | IArgument<T> | The type of the argument. |
options? | ArgOptions | The rest options. |
Returns
Promise<T>
Example
// !reverse Hello world!
const resolver = Args.make((arg) => Args.ok(arg.split('').reverse()));
const a = await args.rest(resolver);
await message.channel.send(`The reversed value is... ${a}`);
// Sends "The reversed value is... !dlrow olleH"
Call Signature
rest<
K>(type:K,options?:ArgOptions):Promise<ArgType[K]>
Defined in: projects/framework/src/lib/parsers/Args.ts:272
Similar to Args.restResult but returns the value on success, throwing otherwise.
Type Parameters
| Type Parameter |
|---|
K extends keyof ArgType |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | K | The type of the argument. |
options? | ArgOptions | The rest options. |
Returns
Example
// !add 2 Hello World!
const a = await args.pick('integer');
const b = await args.rest('string', { minimum: 1 });
await message.channel.send(`The repeated value is... ${b.repeat(a)}!`);
// Sends "The repeated value is... Hello World!Hello World!"
restore()
restore():
void
Defined in: projects/framework/src/lib/parsers/Args.ts:718
Restores the previously saved state from the stack.
Returns
void
See
Args#save
restResult()
Call Signature
restResult<
T>(type:IArgument<T>,options?:ArgOptions):Promise<ResultType<T>>
Defined in: projects/framework/src/lib/parsers/Args.ts:203
Retrieves all the following arguments.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | IArgument<T> | The type of the argument. |
options? | ArgOptions | The restResult options. |
Returns
Promise<ResultType<T>>
Example
// !reverse Hello world!
const resolver = Args.make((parameter) => Args.ok(parameter.split('').reverse()));
const a = await args.restResult(resolver);
if (!a.success) {
throw new UserError({ identifier: 'AddArgumentError', message: 'You must write some text.' });
}
await message.channel.send(`The reversed value is... ${a.value}`);
// Sends "The reversed value is... !dlrow olleH"
Call Signature
restResult<
K>(type:K,options?:ArgOptions):Promise<ResultType<ArgType[K]>>
Defined in: projects/framework/src/lib/parsers/Args.ts:225
Retrieves all the following arguments.
Type Parameters
| Type Parameter |
|---|
K extends keyof ArgType |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | K | The type of the argument. |
options? | ArgOptions | The restResult options. |
Returns
Promise<ResultType<ArgType[K]>>
Example
// !add 2 Hello World!
const a = await args.pickResult('integer');
if (!a.success) {
throw new UserError({ identifier: 'AddArgumentError', message: 'You must write a number and a text, but the former did not match.' });
}
const b = await args.restResult('string', { minimum: 1 });
if (!b.success) {
throw new UserError({ identifier: 'AddArgumentError', message: 'You must write a number and a text, but the latter did not match.' });
}
await message.channel.send(`The repeated value is... ${b.value.repeat(a.value)}!`);
// Sends "The repeated value is... Hello World!Hello World!"
save()
save():
void
Defined in: projects/framework/src/lib/parsers/Args.ts:710
Saves the current state into the stack following a FILO strategy (first-in, last-out).
Returns
void
See
Args#restore
start()
start():
Args
Defined in: projects/framework/src/lib/parsers/Args.ts:69
Sets the parser to the first token.
Returns
Args
toJSON()
toJSON():
ArgsJson
Defined in: projects/framework/src/lib/parsers/Args.ts:732
Defines the JSON.stringify override.
Returns
unavailableArgument()
protectedunavailableArgument<T>(type:string|IArgument<T>):Err<UserError>
Defined in: projects/framework/src/lib/parsers/Args.ts:736
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
type | string | IArgument<T> |
Returns
Err<UserError>
error()
staticerror<T>(options:Options<T>):Err<ArgumentError<T>>
Defined in: projects/framework/src/lib/parsers/Args.ts:781
Constructs an Err result containing an ArgumentError.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
options | Options<T> | The options for the argument error. |
Returns
Err<ArgumentError<T>>
make()
staticmake<T>(cb: (parameter:string,context:Context<T>) =>AwaitableResult<T>,name:string):IArgument<T>
Defined in: projects/framework/src/lib/parsers/Args.ts:765
Converts a callback into a usable argument.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
cb | (parameter: string, context: Context<T>) => AwaitableResult<T> | undefined | The callback to convert into an IArgument. |
name | string | '' | The name of the argument. |
Returns
IArgument<T>
ok()
staticok<T>(value:T):Ok<T>
Defined in: projects/framework/src/lib/parsers/Args.ts:773
Constructs an Ok result.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
value | T | The value to pass. |
Returns
Ok<T>