(client: ArtifactClient, args: string[])
| 488 | } |
| 489 | |
| 490 | async function runTokenCreate(client: ArtifactClient, args: string[]): Promise<ArtifactsCLIResult> { |
| 491 | const parsed = parseFlags(args, { |
| 492 | scope: { kind: "value" }, |
| 493 | ttl: { kind: "value" }, |
| 494 | }); |
| 495 | if ("error" in parsed) return argvError("token create", parsed.error); |
| 496 | const repo = parsed.positional[0]; |
| 497 | if (repo === undefined) return argvError("token create", "missing <repo>"); |
| 498 | if (parsed.positional.length > 1) { |
| 499 | return argvError("token create", `unexpected argument '${parsed.positional[1]}'`); |
| 500 | } |
| 501 | |
| 502 | let scope: ArtifactScope | undefined; |
| 503 | if (parsed.flags.scope !== undefined) { |
| 504 | const s = parsed.flags.scope as string; |
| 505 | if (s !== "read" && s !== "write") { |
| 506 | return argvError("token create", `--scope must be 'read' or 'write' (got '${s}')`); |
| 507 | } |
| 508 | scope = s; |
| 509 | } |
| 510 | |
| 511 | let ttl: number | undefined; |
| 512 | if (parsed.flags.ttl !== undefined) { |
| 513 | try { |
| 514 | ttl = parseDuration(parsed.flags.ttl as string); |
| 515 | } catch (cause) { |
| 516 | return argvError("token create", cause instanceof Error ? cause.message : String(cause)); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | try { |
| 521 | return ok(json(await client.createToken(repo, scope, ttl))); |
| 522 | } catch (cause) { |
| 523 | return mapError("token create", cause); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | async function runTokenList(client: ArtifactClient, args: string[]): Promise<ArtifactsCLIResult> { |
| 528 | const parsed = parseFlags(args, {}); |
no test coverage detected