@zinn-dev/cli 0.40.0 → 0.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -561
- package/index.js +24 -13
- package/package.json +8 -2
- package/skills/zinn/SKILL.md +63 -0
- package/src/actor.d.ts +2 -1
- package/src/actor.js +78 -11
- package/src/capabilities-schema.d.ts +162 -0
- package/src/capabilities-schema.js +59 -0
- package/src/capabilities.d.ts +29 -0
- package/src/capabilities.js +30 -0
- package/src/column-hint.d.ts +3 -0
- package/src/column-hint.js +225 -0
- package/src/database.d.ts +1 -1
- package/src/database.js +5 -8
- package/src/errors.d.ts +158 -0
- package/src/errors.js +226 -0
- package/src/input.d.ts +227 -0
- package/src/input.js +192 -0
- package/src/lib.d.ts +71 -8
- package/src/lib.js +275 -18
- package/src/presentation/activity-presentation.d.ts +9 -1
- package/src/presentation/activity-presentation.js +120 -23
- package/src/presentation/capabilities-presentation.d.ts +2 -0
- package/src/presentation/capabilities-presentation.js +3 -0
- package/src/presentation/column-presentation.d.ts +9 -5
- package/src/presentation/column-presentation.js +10 -0
- package/src/presentation/comment-presentation.d.ts +15 -0
- package/src/presentation/comment-presentation.js +29 -0
- package/src/presentation/description-presentation.d.ts +17 -0
- package/src/presentation/description-presentation.js +26 -4
- package/src/presentation/info-presentation.d.ts +4 -0
- package/src/presentation/info-presentation.js +96 -0
- package/src/presentation/label-presentation.d.ts +8 -0
- package/src/presentation/label-presentation.js +28 -0
- package/src/presentation/project-presentation.d.ts +7 -0
- package/src/presentation/project-presentation.js +19 -0
- package/src/presentation/relation-presentation.d.ts +7 -0
- package/src/presentation/relation-presentation.js +73 -0
- package/src/presentation/task-presentation.d.ts +4 -12
- package/src/presentation/task-presentation.js +22 -18
- package/src/project.d.ts +18 -3
- package/src/project.js +37 -12
- package/src/result-schemas.d.ts +1194 -0
- package/src/result-schemas.js +279 -0
- package/src/results.d.ts +40 -0
- package/src/results.js +36 -0
- package/src/routes/activity-router.d.ts +104 -0
- package/src/routes/activity-router.js +155 -34
- package/src/routes/aliases.d.ts +2 -0
- package/src/routes/aliases.js +11 -0
- package/src/routes/backup-router.d.ts +17 -0
- package/src/routes/backup-router.js +15 -3
- package/src/routes/capabilities-router.d.ts +21 -0
- package/src/routes/capabilities-router.js +34 -0
- package/src/routes/comment-router.d.ts +210 -8
- package/src/routes/comment-router.js +189 -65
- package/src/routes/info-router.d.ts +21 -0
- package/src/routes/info-router.js +29 -0
- package/src/routes/label-router.d.ts +217 -2
- package/src/routes/label-router.js +189 -62
- package/src/routes/migrate-router.d.ts +17 -0
- package/src/routes/migrate-router.js +17 -5
- package/src/routes/project-router.d.ts +373 -2
- package/src/routes/project-router.js +322 -132
- package/src/routes/reindex-router.d.ts +17 -0
- package/src/routes/reindex-router.js +15 -3
- package/src/routes/relation-router.d.ts +110 -14
- package/src/routes/relation-router.js +122 -79
- package/src/routes/restore-router.d.ts +29 -0
- package/src/routes/restore-router.js +31 -14
- package/src/routes/router.d.ts +1 -1
- package/src/routes/router.js +80 -32
- package/src/routes/routes.d.ts +1781 -8
- package/src/routes/routes.js +9 -1
- package/src/routes/task-router.d.ts +946 -4
- package/src/routes/task-router.js +524 -260
- package/src/routes/whoami-router.d.ts +21 -0
- package/src/routes/whoami-router.js +31 -0
- package/src/text-edit.d.ts +28 -6
- package/src/text-edit.js +40 -23
- package/src/text-input.d.ts +47 -0
- package/src/text-input.js +187 -0
- package/src/types.d.ts +37 -0
- package/src/types.js +9 -1
package/src/input.d.ts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const inputValueSchema: z.ZodObject<{
|
|
3
|
+
kind: z.ZodString;
|
|
4
|
+
name: z.ZodOptional<z.ZodString>;
|
|
5
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
6
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
7
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
8
|
+
description: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, z.core.$strict>;
|
|
10
|
+
export declare const inputOptionSchema: z.ZodObject<{
|
|
11
|
+
type: z.ZodEnum<{
|
|
12
|
+
string: "string";
|
|
13
|
+
boolean: "boolean";
|
|
14
|
+
}>;
|
|
15
|
+
short: z.ZodOptional<z.ZodString>;
|
|
16
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
17
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodArray<z.ZodBoolean>]>>;
|
|
18
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
19
|
+
value: z.ZodOptional<z.ZodObject<{
|
|
20
|
+
kind: z.ZodString;
|
|
21
|
+
name: z.ZodOptional<z.ZodString>;
|
|
22
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
23
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
24
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
25
|
+
description: z.ZodOptional<z.ZodString>;
|
|
26
|
+
}, z.core.$strict>>;
|
|
27
|
+
description: z.ZodOptional<z.ZodString>;
|
|
28
|
+
}, z.core.$strict>;
|
|
29
|
+
export declare const inputOptionsSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
30
|
+
type: z.ZodEnum<{
|
|
31
|
+
string: "string";
|
|
32
|
+
boolean: "boolean";
|
|
33
|
+
}>;
|
|
34
|
+
short: z.ZodOptional<z.ZodString>;
|
|
35
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
36
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodArray<z.ZodBoolean>]>>;
|
|
37
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
38
|
+
value: z.ZodOptional<z.ZodObject<{
|
|
39
|
+
kind: z.ZodString;
|
|
40
|
+
name: z.ZodOptional<z.ZodString>;
|
|
41
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
42
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
43
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
44
|
+
description: z.ZodOptional<z.ZodString>;
|
|
45
|
+
}, z.core.$strict>>;
|
|
46
|
+
description: z.ZodOptional<z.ZodString>;
|
|
47
|
+
}, z.core.$strict>>;
|
|
48
|
+
declare const inputReferenceSchema: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
49
|
+
declare const inputConstraintSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
50
|
+
kind: z.ZodLiteral<"exclusive">;
|
|
51
|
+
members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
|
|
52
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
53
|
+
kind: z.ZodLiteral<"requires">;
|
|
54
|
+
input: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
55
|
+
requires: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
56
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
57
|
+
kind: z.ZodLiteral<"requiresAny">;
|
|
58
|
+
input: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
59
|
+
members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
|
|
60
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
61
|
+
kind: z.ZodLiteral<"atLeastOne">;
|
|
62
|
+
members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
|
|
63
|
+
}, z.core.$strict>], "kind">;
|
|
64
|
+
declare const positionalInputSchema: z.ZodObject<{
|
|
65
|
+
name: z.ZodString;
|
|
66
|
+
min: z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>]>;
|
|
67
|
+
max: z.ZodNullable<z.ZodLiteral<1>>;
|
|
68
|
+
value: z.ZodObject<{
|
|
69
|
+
kind: z.ZodString;
|
|
70
|
+
name: z.ZodOptional<z.ZodString>;
|
|
71
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
72
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
73
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
74
|
+
description: z.ZodOptional<z.ZodString>;
|
|
75
|
+
}, z.core.$strict>;
|
|
76
|
+
}, z.core.$strict>;
|
|
77
|
+
declare const inputFormSchema: z.ZodObject<{
|
|
78
|
+
id: z.ZodString;
|
|
79
|
+
positionals: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
80
|
+
name: z.ZodString;
|
|
81
|
+
min: z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>]>;
|
|
82
|
+
max: z.ZodNullable<z.ZodLiteral<1>>;
|
|
83
|
+
value: z.ZodObject<{
|
|
84
|
+
kind: z.ZodString;
|
|
85
|
+
name: z.ZodOptional<z.ZodString>;
|
|
86
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
87
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
88
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
89
|
+
description: z.ZodOptional<z.ZodString>;
|
|
90
|
+
}, z.core.$strict>;
|
|
91
|
+
}, z.core.$strict>>>;
|
|
92
|
+
}, z.core.$strict>;
|
|
93
|
+
export declare const commandInputSchema: z.ZodObject<{
|
|
94
|
+
options: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
95
|
+
type: z.ZodEnum<{
|
|
96
|
+
string: "string";
|
|
97
|
+
boolean: "boolean";
|
|
98
|
+
}>;
|
|
99
|
+
short: z.ZodOptional<z.ZodString>;
|
|
100
|
+
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
101
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodArray<z.ZodString>, z.ZodArray<z.ZodBoolean>]>>;
|
|
102
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
103
|
+
value: z.ZodOptional<z.ZodObject<{
|
|
104
|
+
kind: z.ZodString;
|
|
105
|
+
name: z.ZodOptional<z.ZodString>;
|
|
106
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
107
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
108
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
109
|
+
description: z.ZodOptional<z.ZodString>;
|
|
110
|
+
}, z.core.$strict>>;
|
|
111
|
+
description: z.ZodOptional<z.ZodString>;
|
|
112
|
+
}, z.core.$strict>>;
|
|
113
|
+
forms: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
114
|
+
id: z.ZodString;
|
|
115
|
+
positionals: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
116
|
+
name: z.ZodString;
|
|
117
|
+
min: z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>]>;
|
|
118
|
+
max: z.ZodNullable<z.ZodLiteral<1>>;
|
|
119
|
+
value: z.ZodObject<{
|
|
120
|
+
kind: z.ZodString;
|
|
121
|
+
name: z.ZodOptional<z.ZodString>;
|
|
122
|
+
choices: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
123
|
+
caseInsensitive: z.ZodOptional<z.ZodBoolean>;
|
|
124
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
125
|
+
description: z.ZodOptional<z.ZodString>;
|
|
126
|
+
}, z.core.$strict>;
|
|
127
|
+
}, z.core.$strict>>>;
|
|
128
|
+
}, z.core.$strict>>>;
|
|
129
|
+
constraints: z.ZodReadonly<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
130
|
+
kind: z.ZodLiteral<"exclusive">;
|
|
131
|
+
members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
|
|
132
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
133
|
+
kind: z.ZodLiteral<"requires">;
|
|
134
|
+
input: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
135
|
+
requires: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
136
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
137
|
+
kind: z.ZodLiteral<"requiresAny">;
|
|
138
|
+
input: z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>;
|
|
139
|
+
members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
|
|
140
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
141
|
+
kind: z.ZodLiteral<"atLeastOne">;
|
|
142
|
+
members: z.ZodReadonly<z.ZodArray<z.ZodTemplateLiteral<`option:${string}` | `positional:${string}`>>>;
|
|
143
|
+
}, z.core.$strict>], "kind">>>;
|
|
144
|
+
notes: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
145
|
+
}, z.core.$strict>;
|
|
146
|
+
export type InputValue = z.infer<typeof inputValueSchema>;
|
|
147
|
+
export type InputOption = z.infer<typeof inputOptionSchema>;
|
|
148
|
+
export type InputOptions = z.infer<typeof inputOptionsSchema>;
|
|
149
|
+
export type PositionalInput = z.infer<typeof positionalInputSchema>;
|
|
150
|
+
export type InputForm = z.infer<typeof inputFormSchema>;
|
|
151
|
+
export type InputReference = z.infer<typeof inputReferenceSchema>;
|
|
152
|
+
export type InputConstraint = z.infer<typeof inputConstraintSchema>;
|
|
153
|
+
export type CommandInput = z.infer<typeof commandInputSchema>;
|
|
154
|
+
export declare const taskKeyPositional: {
|
|
155
|
+
readonly name: "task-key";
|
|
156
|
+
readonly min: 1;
|
|
157
|
+
readonly max: 1;
|
|
158
|
+
readonly value: {
|
|
159
|
+
readonly kind: "task-key";
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
export declare const noInput: {
|
|
163
|
+
readonly options: {};
|
|
164
|
+
readonly forms: readonly [{
|
|
165
|
+
readonly id: "default";
|
|
166
|
+
readonly positionals: readonly [];
|
|
167
|
+
}];
|
|
168
|
+
readonly constraints: readonly [];
|
|
169
|
+
};
|
|
170
|
+
export declare const archiveConstraint: {
|
|
171
|
+
readonly kind: "exclusive";
|
|
172
|
+
readonly members: readonly ["option:archived", "option:all"];
|
|
173
|
+
};
|
|
174
|
+
export declare const routerOptionNames: {
|
|
175
|
+
readonly json: "json";
|
|
176
|
+
readonly legacyRead: "allow-legacy-read";
|
|
177
|
+
};
|
|
178
|
+
export declare const routerOptions: {
|
|
179
|
+
readonly json: {
|
|
180
|
+
readonly type: "boolean";
|
|
181
|
+
};
|
|
182
|
+
readonly "allow-legacy-read": {
|
|
183
|
+
readonly type: "boolean";
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
export declare const helpSpellings: readonly string[];
|
|
187
|
+
export declare const versionSpellings: readonly string[];
|
|
188
|
+
export declare const invocation: {
|
|
189
|
+
readonly routerOptions: {
|
|
190
|
+
readonly json: {
|
|
191
|
+
readonly type: "boolean";
|
|
192
|
+
};
|
|
193
|
+
readonly "allow-legacy-read": {
|
|
194
|
+
readonly type: "boolean";
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
readonly routerOptionPlacement: "exact-tokens-anywhere-before-separator";
|
|
198
|
+
readonly optionSeparator: "--";
|
|
199
|
+
readonly literalOptionValue: "equals";
|
|
200
|
+
readonly singularOptions: "reject-repetition";
|
|
201
|
+
readonly jsonFailure: "one-stderr-document-with-buffered-diagnostics";
|
|
202
|
+
readonly jsonSuccessDiagnostics: "text-on-stderr-at-completion";
|
|
203
|
+
readonly canonicalArgv: readonly ["command-path", "options-with-equals-values", "--json", "separator-if-positionals", "positionals"];
|
|
204
|
+
readonly version: {
|
|
205
|
+
readonly spellings: readonly string[];
|
|
206
|
+
readonly placement: "sole-argument";
|
|
207
|
+
readonly stdout: "text";
|
|
208
|
+
readonly exitCode: 0;
|
|
209
|
+
};
|
|
210
|
+
readonly help: {
|
|
211
|
+
readonly spellings: readonly string[];
|
|
212
|
+
readonly stdout: "text";
|
|
213
|
+
readonly exitCode: 0;
|
|
214
|
+
readonly precedence: "root-first-token-otherwise-router-prefix-before-help";
|
|
215
|
+
readonly scansRouterOptionsFirst: true;
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
/** Formats the same positional facts used by validation */
|
|
219
|
+
export declare function positionalWords(form: InputForm): string[];
|
|
220
|
+
/** Validates structure without tripping on empty strings */
|
|
221
|
+
export declare function violatesConstraint(constraint: InputConstraint, inputs: Partial<Record<InputReference, unknown>>): boolean;
|
|
222
|
+
export declare function getOptionInputs(values: Record<string, unknown>): Partial<Record<InputReference, unknown>>;
|
|
223
|
+
/** Generates syntax without the explanatory help stuff */
|
|
224
|
+
export declare function generateInputUsage(input: CommandInput): string[];
|
|
225
|
+
export declare const usageLabel = "Usage: ";
|
|
226
|
+
export declare function generateCommandUsage(path: string, input: CommandInput): string;
|
|
227
|
+
export {};
|
package/src/input.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const inputValueSchema = z.strictObject({
|
|
3
|
+
kind: z.string(),
|
|
4
|
+
name: z.string().optional(),
|
|
5
|
+
choices: z.array(z.string()).readonly().optional(),
|
|
6
|
+
caseInsensitive: z.boolean().optional(),
|
|
7
|
+
pattern: z.string().optional(),
|
|
8
|
+
description: z.string().optional(),
|
|
9
|
+
});
|
|
10
|
+
export const inputOptionSchema = z.strictObject({
|
|
11
|
+
type: z.enum(["string", "boolean"]),
|
|
12
|
+
short: z.string().optional(),
|
|
13
|
+
multiple: z.boolean().optional(),
|
|
14
|
+
default: z.union([z.string(), z.boolean(), z.array(z.string()), z.array(z.boolean())]).optional(),
|
|
15
|
+
required: z.boolean().optional(),
|
|
16
|
+
value: inputValueSchema.optional(),
|
|
17
|
+
description: z.string().optional(),
|
|
18
|
+
});
|
|
19
|
+
export const inputOptionsSchema = z.record(z.string(), inputOptionSchema);
|
|
20
|
+
const inputReferenceSchema = z.templateLiteral([
|
|
21
|
+
z.enum(["option:", "positional:"]),
|
|
22
|
+
z.string().min(1),
|
|
23
|
+
]);
|
|
24
|
+
const members = z.array(inputReferenceSchema).readonly();
|
|
25
|
+
const inputConstraintSchema = z.discriminatedUnion("kind", [
|
|
26
|
+
z.strictObject({ kind: z.literal("exclusive"), members }),
|
|
27
|
+
z.strictObject({
|
|
28
|
+
kind: z.literal("requires"),
|
|
29
|
+
input: inputReferenceSchema,
|
|
30
|
+
requires: inputReferenceSchema,
|
|
31
|
+
}),
|
|
32
|
+
z.strictObject({ kind: z.literal("requiresAny"), input: inputReferenceSchema, members }),
|
|
33
|
+
z.strictObject({ kind: z.literal("atLeastOne"), members }),
|
|
34
|
+
]);
|
|
35
|
+
const positionalInputSchema = z.strictObject({
|
|
36
|
+
name: z.string(),
|
|
37
|
+
min: z.union([z.literal(0), z.literal(1)]),
|
|
38
|
+
max: z.literal(1).nullable(),
|
|
39
|
+
value: inputValueSchema,
|
|
40
|
+
});
|
|
41
|
+
const inputFormSchema = z.strictObject({
|
|
42
|
+
id: z.string(),
|
|
43
|
+
positionals: z.array(positionalInputSchema).readonly(),
|
|
44
|
+
});
|
|
45
|
+
export const commandInputSchema = z.strictObject({
|
|
46
|
+
options: inputOptionsSchema,
|
|
47
|
+
forms: z.array(inputFormSchema).min(1).readonly(),
|
|
48
|
+
constraints: z.array(inputConstraintSchema).readonly(),
|
|
49
|
+
notes: z.array(z.string()).readonly().optional(),
|
|
50
|
+
});
|
|
51
|
+
export const taskKeyPositional = {
|
|
52
|
+
name: "task-key",
|
|
53
|
+
min: 1,
|
|
54
|
+
max: 1,
|
|
55
|
+
value: { kind: "task-key" },
|
|
56
|
+
};
|
|
57
|
+
export const noInput = {
|
|
58
|
+
options: {},
|
|
59
|
+
forms: [{ id: "default", positionals: [] }],
|
|
60
|
+
constraints: [],
|
|
61
|
+
};
|
|
62
|
+
export const archiveConstraint = {
|
|
63
|
+
kind: "exclusive",
|
|
64
|
+
members: ["option:archived", "option:all"],
|
|
65
|
+
};
|
|
66
|
+
export const routerOptionNames = { json: "json", legacyRead: "allow-legacy-read" };
|
|
67
|
+
export const routerOptions = {
|
|
68
|
+
[routerOptionNames.json]: { type: "boolean" },
|
|
69
|
+
[routerOptionNames.legacyRead]: { type: "boolean" },
|
|
70
|
+
};
|
|
71
|
+
export const helpSpellings = ["-h", "--help"];
|
|
72
|
+
export const versionSpellings = ["-v", "--version"];
|
|
73
|
+
export const invocation = {
|
|
74
|
+
routerOptions,
|
|
75
|
+
routerOptionPlacement: "exact-tokens-anywhere-before-separator",
|
|
76
|
+
optionSeparator: "--",
|
|
77
|
+
literalOptionValue: "equals",
|
|
78
|
+
singularOptions: "reject-repetition",
|
|
79
|
+
jsonFailure: "one-stderr-document-with-buffered-diagnostics",
|
|
80
|
+
jsonSuccessDiagnostics: "text-on-stderr-at-completion",
|
|
81
|
+
canonicalArgv: [
|
|
82
|
+
"command-path",
|
|
83
|
+
"options-with-equals-values",
|
|
84
|
+
"--json",
|
|
85
|
+
"separator-if-positionals",
|
|
86
|
+
"positionals",
|
|
87
|
+
],
|
|
88
|
+
version: { spellings: versionSpellings, placement: "sole-argument", stdout: "text", exitCode: 0 },
|
|
89
|
+
help: {
|
|
90
|
+
spellings: helpSpellings,
|
|
91
|
+
stdout: "text",
|
|
92
|
+
exitCode: 0,
|
|
93
|
+
precedence: "root-first-token-otherwise-router-prefix-before-help",
|
|
94
|
+
scansRouterOptionsFirst: true,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
/** Formats the same positional facts used by validation */
|
|
98
|
+
export function positionalWords(form) {
|
|
99
|
+
return form.positionals.map(({ name, min, max, value }) => {
|
|
100
|
+
const word = value.choices === undefined ? `<${name}>` : `{${value.choices.join("|")}}`;
|
|
101
|
+
const repeatedWord = max === null ? `${word}...` : word;
|
|
102
|
+
return min === 0 ? `[${repeatedWord}]` : repeatedWord;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/** Validates structure without tripping on empty strings */
|
|
106
|
+
export function violatesConstraint(constraint, inputs) {
|
|
107
|
+
const supplied = (reference) => inputs[reference] !== undefined && inputs[reference] !== false;
|
|
108
|
+
switch (constraint.kind) {
|
|
109
|
+
case "exclusive":
|
|
110
|
+
return constraint.members.filter(supplied).length > 1;
|
|
111
|
+
case "requires":
|
|
112
|
+
return supplied(constraint.input) && !supplied(constraint.requires);
|
|
113
|
+
case "requiresAny":
|
|
114
|
+
return supplied(constraint.input) && !constraint.members.some(supplied);
|
|
115
|
+
case "atLeastOne":
|
|
116
|
+
return !constraint.members.some(supplied);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export function getOptionInputs(values) {
|
|
120
|
+
return Object.fromEntries(Object.entries(values).map(([name, value]) => [`option:${name}`, value]));
|
|
121
|
+
}
|
|
122
|
+
/** Generates syntax without the explanatory help stuff */
|
|
123
|
+
export function generateInputUsage(input) {
|
|
124
|
+
const options = Object.entries(input.options).map(([name, option]) => {
|
|
125
|
+
const value = option.value;
|
|
126
|
+
const valueWord = value?.name === undefined && value?.choices !== undefined
|
|
127
|
+
? `{${value.choices.join("|")}}`
|
|
128
|
+
: `<${value?.name ?? "text"}>`;
|
|
129
|
+
const flag = `--${name}${option.type === "string" ? ` ${valueWord}` : ""}`;
|
|
130
|
+
return {
|
|
131
|
+
reference: `option:${name}`,
|
|
132
|
+
word: `${option.required ? flag : `[${flag}]`}${option.multiple ? "..." : ""}`,
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
/**
|
|
136
|
+
* Exclusive inputs that also need one of them are a required choice: (a|b) instead of [a|b],
|
|
137
|
+
* like how it is in git's synopsis notation.
|
|
138
|
+
* {a|b} stays reserved for a choice of literal words.
|
|
139
|
+
*/
|
|
140
|
+
const isRequiredChoice = (members) => input.constraints.some((constraint) => constraint.kind === "atLeastOne" &&
|
|
141
|
+
constraint.members.length === members.length &&
|
|
142
|
+
constraint.members.every((member) => members.includes(member)));
|
|
143
|
+
const choice = (alternatives, isRequired) => isRequired ? `(${alternatives.join("|")})` : `[${alternatives.join("|")}]`;
|
|
144
|
+
return input.forms.map((form) => {
|
|
145
|
+
const words = new Map([
|
|
146
|
+
...form.positionals.map((positional, index) => [`positional:${positional.name}`, positionalWords(form)[index]]),
|
|
147
|
+
...options.map(({ reference, word }) => [reference, word]),
|
|
148
|
+
]);
|
|
149
|
+
// Text modifiers share one syntax group with the text sources they change
|
|
150
|
+
const textRequirement = input.constraints.find((constraint) => constraint.kind === "requiresAny" && constraint.input === "option:append");
|
|
151
|
+
if (textRequirement?.kind === "requiresAny") {
|
|
152
|
+
const sources = textRequirement.members;
|
|
153
|
+
const sourceSyntax = sources.map((reference) => {
|
|
154
|
+
const name = reference.slice("option:".length);
|
|
155
|
+
return `--${name} <${input.options[name].value?.name ?? "text"}>`;
|
|
156
|
+
});
|
|
157
|
+
const isRequired = isRequiredChoice(sources);
|
|
158
|
+
const source = sourceSyntax.length === 1 ? sourceSyntax[0] : choice(sourceSyntax, true);
|
|
159
|
+
const replacing = words.get("option:replacing").slice(1, -1);
|
|
160
|
+
const group = `${source} [--append|${replacing} ${words.get("option:all")}]`;
|
|
161
|
+
words.set(sources[0], isRequired ? group : `[${group}]`);
|
|
162
|
+
// The words written inside the first source's group
|
|
163
|
+
const foldedReferences = [
|
|
164
|
+
...sources.slice(1),
|
|
165
|
+
"option:append",
|
|
166
|
+
"option:replacing",
|
|
167
|
+
"option:all",
|
|
168
|
+
];
|
|
169
|
+
for (const reference of foldedReferences) {
|
|
170
|
+
words.delete(reference);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
for (const constraint of input.constraints) {
|
|
174
|
+
const hasEveryMemberWord = constraint.kind === "exclusive" && constraint.members.every((member) => words.has(member));
|
|
175
|
+
if (!hasEveryMemberWord) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const alternatives = constraint.members.map((member) => words.get(member).slice(1, -1));
|
|
179
|
+
words.set(constraint.members[0], choice(alternatives, isRequiredChoice(constraint.members)));
|
|
180
|
+
for (const member of constraint.members.slice(1)) {
|
|
181
|
+
words.delete(member);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return [...words.values()].join(" ");
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
export const usageLabel = "Usage: ";
|
|
188
|
+
export function generateCommandUsage(path, input) {
|
|
189
|
+
return generateInputUsage(input)
|
|
190
|
+
.map((syntax, index) => `${index === 0 ? usageLabel : " ".repeat(usageLabel.length)}zinn ${path}${syntax === "" ? "" : ` ${syntax}`}`)
|
|
191
|
+
.join("\n");
|
|
192
|
+
}
|
package/src/lib.d.ts
CHANGED
|
@@ -1,31 +1,94 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ParseArgsOptionsConfig } from "node:util";
|
|
2
|
+
import type { InputForm, InputOptions, InputOption } from "./input.js";
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
4
|
+
import { CliError, type ErrorDetails } from "./errors.js";
|
|
2
5
|
type ParsedTokens = NonNullable<ReturnType<typeof parseArgs>["tokens"]>;
|
|
3
6
|
type OutputMode = "text" | "json";
|
|
4
7
|
export declare function setOutputMode(mode: OutputMode): void;
|
|
5
|
-
export declare function
|
|
6
|
-
|
|
8
|
+
export declare function getOutputMode(): OutputMode;
|
|
9
|
+
/** Selects output before routing, without treating words after `--` as flags. */
|
|
10
|
+
export declare function prepareOutput(args: Array<string>): void;
|
|
11
|
+
/** Keeps JSON failures parseable while text-mode notices remain immediate. */
|
|
12
|
+
export declare function diagnostic(message: string): void;
|
|
13
|
+
export declare function flushDiagnostics(): void;
|
|
14
|
+
export declare function isJsonFlag(flag: string): boolean;
|
|
15
|
+
export declare function isAllowLegacyReadFlag(flag: string): boolean;
|
|
16
|
+
/** A flag the router reads wherever it appears before --, for every command. */
|
|
17
|
+
export declare function isRouterFlag(flag: string): boolean;
|
|
7
18
|
export declare function setLegacyReadAllowed(allowed: boolean): void;
|
|
8
19
|
export declare function isLegacyReadAllowed(): boolean;
|
|
9
20
|
export declare function output<T>(data: T, transformToString: (data: T) => string): void;
|
|
21
|
+
/** Includes change data in JSON and adds a stderr note for each unchanged object */
|
|
22
|
+
export declare function outputChanges<Change extends {
|
|
23
|
+
changed: boolean;
|
|
24
|
+
}, Presented extends object>(changes: Array<Change>, present: (change: Change) => Presented, formatEntries: (entries: Array<Presented>) => string, describeUnchanged: (entry: Presented) => string): void;
|
|
10
25
|
/** Asks before a change that cannot be undone, unless --yes already confirmed it. */
|
|
11
26
|
export declare function confirmAction(message: string, isPreconfirmed: boolean, jsonRefusal?: string): Promise<boolean>;
|
|
27
|
+
export declare const confirmationDescription = "Requires --yes with --json or without a terminal. Otherwise prompts on stderr and only y or Y confirms. Declining exits successfully without the requested mutation; interruption exits 130.";
|
|
12
28
|
/** Like confirmAction, without opening the database, for commands that bypass the open policy. */
|
|
13
29
|
export declare function askConfirmation(message: string, isPreconfirmed: boolean, jsonRefusal?: string): Promise<boolean>;
|
|
14
30
|
/** Whether someone can answer a prompt: stdin and stdout are both terminals, like how gh decides it. */
|
|
15
31
|
export declare function canPrompt(): boolean;
|
|
16
32
|
/** The message to report for a failed command, or fallback when the error has none. */
|
|
17
33
|
export declare function failureMessage(error: any, fallback: string): any;
|
|
18
|
-
/**
|
|
19
|
-
export declare function quit(reason: string, help?: string): never;
|
|
34
|
+
/** Stops a command while retaining its classified error for the outer renderer. */
|
|
35
|
+
export declare function quit(reason: string | Error, help?: string, details?: ErrorDetails): never;
|
|
36
|
+
/** Emits one handled failure, including any notices collected before it. */
|
|
37
|
+
export declare function renderFailure(reason: unknown): void;
|
|
20
38
|
/** A command was given the wrong words. The router prints the message with the command's usage lines. */
|
|
21
|
-
export declare class UsageError extends
|
|
39
|
+
export declare class UsageError extends CliError {
|
|
40
|
+
constructor(message: string, details?: ErrorDetails);
|
|
22
41
|
}
|
|
23
42
|
/**
|
|
24
43
|
* Checks a command's words against its usage line, with the words written the same way:
|
|
25
44
|
* `<task-key>` is required, `[<project-key>]` is optional and `<task-key>...` repeats.
|
|
26
45
|
* Optional words go last.
|
|
27
46
|
*/
|
|
28
|
-
export declare function validatePositionals(positionals: Array<string>,
|
|
29
|
-
export declare function validateUniqueOptions(tokens: ParsedTokens,
|
|
47
|
+
export declare function validatePositionals(positionals: Array<string>, form: InputForm): void;
|
|
48
|
+
export declare function validateUniqueOptions(tokens: ParsedTokens, options: InputOptions): void;
|
|
49
|
+
/** The choices a positional accepts; positionals without choices contribute never. */
|
|
50
|
+
type PositionalChoices<Positional> = Positional extends {
|
|
51
|
+
value: {
|
|
52
|
+
choices: readonly (infer Choice)[];
|
|
53
|
+
};
|
|
54
|
+
} ? Choice : never;
|
|
55
|
+
/** The direction words a form's direction positional accepts. */
|
|
56
|
+
type OrderDirection<Form extends InputForm> = PositionalChoices<Extract<Form["positionals"][number], {
|
|
57
|
+
name: "direction";
|
|
58
|
+
}>>;
|
|
59
|
+
/**
|
|
60
|
+
* A selected form with the direction word and the positional index it was read from.
|
|
61
|
+
* Distributes over the form union, so each form keeps its own direction choices.
|
|
62
|
+
*/
|
|
63
|
+
type SelectedOrderForm<Form extends InputForm> = Form extends unknown ? Form & {
|
|
64
|
+
direction: OrderDirection<Form>;
|
|
65
|
+
directionIndex: number;
|
|
66
|
+
} : never;
|
|
67
|
+
/** Selects an order form after checking its required leading words. */
|
|
68
|
+
export declare function validateOrderForms<Form extends InputForm>(positionals: string[], forms: readonly Form[]): SelectedOrderForm<Form>;
|
|
69
|
+
export declare function requireStringOption(option: InputOption & {
|
|
70
|
+
required: true;
|
|
71
|
+
}, value: string | undefined, name: string, message: string): string;
|
|
30
72
|
export declare function isHelpFlag(flag: string): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Help sentence for a flag whose value may begin with a dash, such as a Markdown bullet.
|
|
75
|
+
* `parseArgs` refuses `--flag -value`, since a value that looks like an option may mean the value
|
|
76
|
+
* was forgotten, so we respect that refusal and not take the next word as the value
|
|
77
|
+
* @see {@link https://github.com/pkgjs/parseargs/issues/77}
|
|
78
|
+
*/
|
|
79
|
+
export declare function dashValueHelp(flag: string): string;
|
|
80
|
+
/** Quotes a word for a POSIX shell when it needs it, like Python's `shlex.quote` */
|
|
81
|
+
export declare function shellQuote(word: string): string;
|
|
82
|
+
/** A command line to show, with each word quoted for the shell as needed. */
|
|
83
|
+
export declare function formatCommand(args: Array<string>): string;
|
|
84
|
+
/** The words of the command a user likely meant by a flag the command does not take, if known. */
|
|
85
|
+
type SuggestFor = (flag: string) => Array<string> | undefined;
|
|
86
|
+
/** Renames an option without changing values or words after `--` */
|
|
87
|
+
export declare function renameFlag(args: Array<string>, options: ParseArgsOptionsConfig, source: string, target: string): string[];
|
|
88
|
+
/**
|
|
89
|
+
* The message for an argument error from parseArgs, rewritten where parseArgs' own advice misleads.
|
|
90
|
+
* parseArgs names the flag only in its message text, which Node and Bun word the same.
|
|
91
|
+
* `null` for any other error.
|
|
92
|
+
*/
|
|
93
|
+
export declare function parseArgsMessage(error: any, args: Array<string>, suggestFor: SuggestFor): any;
|
|
31
94
|
export {};
|