-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathclojure.ts
219 lines (213 loc) · 4.96 KB
/
clojure.ts
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/**
* Adds brackets to some content.
*
* @param content The content to be bracketized
* @returns The content with brackets
*/
function bracketize<T>(content: T): string {
return `<${content}>`;
}
/**
* Gets a single value from one or more values.
*
* @param value The value to extract
* @returns The single value
*/
function singleName<T>(value: Fig.SingleOrArray<T>): T {
if (Array.isArray(value)) {
return value.at(-1);
} else {
return value;
}
}
/**
* Create an option with aliasing support.
*/
function alias(
{ name: oName, ...option }: Fig.Option,
{ args } = { args: "aliases" }
): Fig.Option {
const name = singleName(oName);
return {
name,
displayName: `${name}:${bracketize(args)}`,
...option,
};
}
const invokeArgs = [
{
name: "a/fn",
description: "An alias to refer to its function or a qualified function",
isOptional: true,
},
{
name: "kvs",
description: "A list of key-value arguments to merge with the exec-args",
isVariadic: true,
optionsCanBreakVariadicArg: false,
isOptional: true,
},
{
name: "kv-map",
description:
"Map to merge with the :exec-args map, taking precedence over kvs",
isOptional: true,
},
];
const completionSpec: Fig.Spec = {
name: "clojure",
description:
"Use the Clojure tools to run Clojure programs on the JVM, start a REPL, or invoke a specific function with data",
parserDirectives: {
flagsArePosixNoncompliant: true,
},
options: [
// exec-opts
alias({
name: "-A",
description: "Use concatenated aliases to modify classpath",
}),
alias({
name: "-X",
args: invokeArgs,
}),
alias(
{
name: "-T",
description: "Invoke tool by name or via aliases ala -X",
args: invokeArgs,
},
{ args: "name|aliases" }
),
alias({
name: "-M",
description:
"Use concatenated aliases to modify classpath or supply main opts",
args: {
name: "args",
isVariadic: true,
isOptional: true,
},
}),
{
name: "-P",
description:
"Prepare deps - download libs, cache classpath, but don't exec",
},
// clj-opts
{
name: "-J",
description: "Pass opt through in java_opts",
displayName: "-J<opt>",
insertValue: "-J{cursor}",
},
{
name: "-Sdeps",
description: "Pass the deps data on the command line",
args: {
name: "edn",
description: "The deps data in edn",
},
},
{
name: "-Spath",
description: "Compute classpath and echo to stdout only",
},
{
name: "-Scp",
description: "Use specified classpath instead of cached or computed one",
args: {
name: "cp",
description: "The classpath to use",
},
},
{
name: "-Sdescribe",
description: "Print environment and command parsing information as data",
},
{
name: "-Sforce",
description: "Ignore classpath cache and force recomputation",
},
{
name: "-Spom",
description: "Generate (or update) pom.xml with deps and paths",
},
{
name: "-Srepro",
description: "Ignore the ~/.clojure/deps.edn config file",
},
{
name: "-Sthreads",
description:
"Set the number of threads to use when downloading dependencies",
},
{
name: "-Strace",
description: "Write a trace.edn file that traces deps expansion",
},
{
name: "-Stree",
description: "Print dependency tree",
},
{
name: "-Sverbose",
description: "Print all path locations",
},
{
name: ["-version", "--version"],
description: "Print the Clojure CLI version",
},
// Init options
{
name: ["-i", "--init"],
description: "Load a file or resource",
args: {
name: "path",
},
},
{
name: ["-e", "--eval"],
description: "Evaluate expressions in string; print non-nil values",
args: {
name: "string",
},
},
{
name: "--report",
description: "Report uncaught exceptions",
args: {
name: "target",
description: "Where to report",
suggestions: ["file", "stderr", "none"],
},
},
// Main options
{
name: ["-m", "--main"],
description: "Call the -main function from a namespace with args",
args: [
{
name: "ns-name",
description: "The namespace of the -main function",
isScript: true,
},
{
name: "args",
description: "The arguments to pass to the -main function",
isVariadic: true,
},
],
},
{
name: ["-r", "--repl"],
description: "Run a REPL",
},
// May want to add `path` and `-` later if someone can figure out how to use those.
{
name: ["-h", "-?", "--help"],
description: "Show help for clojure",
},
],
};
export default completionSpec;