forked from withfig/autocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
119 lines (114 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const getTeamsGenerator: Fig.Generator = {
script: "npx -y fig-teams@latest teams ls --json",
postProcess: (output) => {
try {
const teams = JSON.parse(output) as Array<string>;
return teams.map((name) => ({
name,
}));
} catch (e) {
return [];
}
},
};
const getUsersGenerator: Fig.Generator = {
script: (context) => {
const teamOption = context.findIndex(
(ctx) => ctx === "-t" || ctx === "--team"
);
// try getting the value of the team option
if (teamOption !== -1 && context[teamOption + 1] !== undefined) {
const teamName = context[teamOption + 1];
return `npx -y fig-teams@latest users get -t ${teamName} --json`;
}
return "";
},
postProcess: (output) => {
try {
const teams = JSON.parse(output) as Array<{
email: string;
role: string;
}>;
return teams.map(({ email }) => ({
name: email,
icon: "fig://icon?type=invite",
}));
} catch (e) {
return [];
}
},
};
const teamOption: Fig.Option = {
name: ["-t", "--team"],
description: "Team to use",
args: {
name: "teamname",
generators: getTeamsGenerator,
},
};
const jsonOption: Fig.Option = {
name: "--json",
description: "Output as JSON",
};
const completionSpec: Fig.Spec = {
name: "fig-teams",
description: "Fig for teams",
subcommands: [
{
name: "teams",
subcommands: [
{
name: "ls",
description: "Get all available teams for the current user",
options: [jsonOption],
},
{
name: "create",
description: "Create a new team",
args: {
name: "team_name",
},
},
{
name: "ls:user",
description: "Get all users for a given team",
options: [teamOption, jsonOption],
},
{
name: "add:user",
description: "Add a new user to a team",
options: [teamOption],
args: {
name: "email",
generators: getUsersGenerator,
},
},
{
name: "remove:user",
description: "Remove a user from a team",
options: [teamOption],
args: {
name: "email",
generators: getUsersGenerator,
},
},
],
},
{
name: "deploy",
description:
"Push your locally compiled completion specs to Fig's server based on the mapping defined in the .fig/manifest file",
},
{
name: "manifest",
description:
"Create or update the .fig/manifest file. Use this command to link your locally created completion specs to your team",
},
{
name: "whoami",
description:
"Get information about the current user and their associated teams",
},
],
};
export default completionSpec;