Debian Codegraph @

cli/publish-spec/src/validation/validators/team.ts

raw symbols SCIP
1 import type prompts from "prompts";
2 import type { Validator } from "../types";
3 import type { RunOptions } from "../../types";
4 import { value, questions } from "./helpers.js";
5 import { exec } from "../../utils.js";
6
7 interface TeamValidation {
8 team?: string;
9 teamScopeInfo?: "p" | "t";
10 }
11
12 export const validateTeam: Validator<TeamValidation> = async (options: RunOptions) => {
13 const { team, interactive } = options;
14 if (team || !interactive) return value({ team });
15 try {
16 const availableTeams: prompts.Choice[] = (await exec("fig team --list"))
17 .trim()
18 .split("\n")
19 .map((name) => ({
20 title: name,
21 value: name,
22 }));
23
24 return questions([
25 {
26 type: "select",
27 message: "Would you like to publish the spec:",
28 choices: [
29 {
30 title: "For personal use",
31 value: "p",
32 },
33 {
34 title: "For a team",
35 value: "t",
36 },
37 ],
38 name: "teamScopeInfo",
39 },
40 {
41 type: (prev: string) => (prev === "t" ? "select" : false),
42 message: "Choose a team to publish the spec to:",
43 name: "team",
44 choices: availableTeams,
45 },
46 ]);
47 } catch {
48 return value({ team: "" });
49 }
50 };