createArgument
Creates a positional argument parser to use in command subjects.
Example
ts
import { SC } from "@duplojs/server-utils";
import { DP } from "@duplojs/utils";
const sourceArgument = SC.createArgument(
"source",
DP.string(),
{
description: "Source file path",
},
);
const targetArgument = SC.createArgument(
"target",
DP.string(),
{
description: "Target file path",
optional: true,
},
);
SC.create(
"copy",
{
subjects: [sourceArgument, targetArgument],
},
({ args }) => {
console.log("copy from", args.source, "to", args.target ?? "(stdout)");
},
);Syntax
typescript
function createArgument<
GenericName extends string,
GenericSpec extends EligibleSpec
>(
name: GenericName,
spec: GenericSpec,
params?: {
description?: string
optional?: false
}
): Argument<GenericName, EligibleSpecOutput<GenericSpec>>
function createArgument<
GenericName extends string,
GenericSpec extends EligibleSpec
>(
name: GenericName,
spec: GenericSpec,
params?: {
description?: string
optional: boolean
}
): Argument<GenericName, EligibleSpecOutput<GenericSpec> | undefined>Parameters
name(string) : argument key exposed inargs.spec(EligibleSpec) : parser/clean spec used to parse and validate the received positional value.params(optional) : argument metadata.params.description(string, optional) : help description.params.optional(boolean, defaultfalse) : allows the argument to be omitted.
Return value
Notes
- Positional arguments are consumed in declaration order.
- In execute handlers, parsed values are available as
args.<name>. - Use only
EligibleSpecvalues (primitive-like specs, literals, unions, pipes/transforms, file, clean specs).
