@optique/git 1.0.0-dev.786 → 1.0.0-dev.885
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/dist/index.cjs +37 -15
- package/dist/index.d.cts +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.js +37 -15
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -78,6 +78,14 @@ function listFailureMessage(error, dir, errors, fallback) {
|
|
|
78
78
|
const DEFAULT_SUGGESTION_DEPTH = 15;
|
|
79
79
|
function createAsyncValueParser(options, metavar, parseFn, suggestFn) {
|
|
80
80
|
(0, __optique_core_nonempty.ensureNonEmptyString)(metavar);
|
|
81
|
+
if (options?.suggestionDepth !== void 0) {
|
|
82
|
+
if (!Number.isInteger(options.suggestionDepth) || options.suggestionDepth < 1) {
|
|
83
|
+
const depth = options.suggestionDepth;
|
|
84
|
+
const repr = typeof depth === "number" ? String(depth) : typeof depth === "string" ? JSON.stringify(depth) : `${typeof depth} ${String(depth)}`;
|
|
85
|
+
throw new RangeError(`Invalid suggestionDepth (must be a positive integer): ${repr}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const validatedDepth = options?.suggestionDepth ?? DEFAULT_SUGGESTION_DEPTH;
|
|
81
89
|
return {
|
|
82
90
|
$mode: "async",
|
|
83
91
|
metavar,
|
|
@@ -90,10 +98,7 @@ function createAsyncValueParser(options, metavar, parseFn, suggestFn) {
|
|
|
90
98
|
},
|
|
91
99
|
async *suggest(prefix) {
|
|
92
100
|
const dir = getRepoDir(options?.dir);
|
|
93
|
-
if (suggestFn)
|
|
94
|
-
const depth = options?.suggestionDepth ?? DEFAULT_SUGGESTION_DEPTH;
|
|
95
|
-
yield* suggestFn(dir, prefix, depth);
|
|
96
|
-
}
|
|
101
|
+
if (suggestFn) yield* suggestFn(dir, prefix, validatedDepth);
|
|
97
102
|
}
|
|
98
103
|
};
|
|
99
104
|
}
|
|
@@ -105,6 +110,7 @@ function createAsyncValueParser(options, metavar, parseFn, suggestFn) {
|
|
|
105
110
|
*
|
|
106
111
|
* @param options Configuration options for the parser.
|
|
107
112
|
* @returns A value parser that accepts existing branch names.
|
|
113
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
108
114
|
* @since 0.9.0
|
|
109
115
|
*
|
|
110
116
|
* @example
|
|
@@ -170,6 +176,7 @@ function gitBranch(options) {
|
|
|
170
176
|
* @param remote The remote name to validate against.
|
|
171
177
|
* @param options Configuration options for the parser.
|
|
172
178
|
* @returns A value parser that accepts existing remote branch names.
|
|
179
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
173
180
|
* @since 0.9.0
|
|
174
181
|
*
|
|
175
182
|
* @example
|
|
@@ -234,6 +241,7 @@ function gitRemoteBranch(remote, options) {
|
|
|
234
241
|
*
|
|
235
242
|
* @param options Configuration options for the parser.
|
|
236
243
|
* @returns A value parser that accepts existing tag names.
|
|
244
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
237
245
|
* @since 0.9.0
|
|
238
246
|
*/
|
|
239
247
|
function gitTag(options) {
|
|
@@ -287,6 +295,7 @@ function gitTag(options) {
|
|
|
287
295
|
*
|
|
288
296
|
* @param options Configuration options for the parser.
|
|
289
297
|
* @returns A value parser that accepts existing remote names.
|
|
298
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
290
299
|
* @since 0.9.0
|
|
291
300
|
*/
|
|
292
301
|
function gitRemote(options) {
|
|
@@ -344,6 +353,7 @@ function gitRemote(options) {
|
|
|
344
353
|
*
|
|
345
354
|
* @param options Configuration options for the parser.
|
|
346
355
|
* @returns A value parser that accepts existing commit SHAs.
|
|
356
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
347
357
|
* @since 0.9.0
|
|
348
358
|
*/
|
|
349
359
|
function gitCommit(options) {
|
|
@@ -391,7 +401,7 @@ function gitCommit(options) {
|
|
|
391
401
|
depth
|
|
392
402
|
});
|
|
393
403
|
for (const commit of commits) if (commit.oid.startsWith(prefix)) {
|
|
394
|
-
const shortOid = commit.oid.slice(0, 7);
|
|
404
|
+
const shortOid = commit.oid.slice(0, Math.max(7, prefix.length));
|
|
395
405
|
const firstLine = commit.commit.message.split("\n")[0];
|
|
396
406
|
yield {
|
|
397
407
|
kind: "literal",
|
|
@@ -416,6 +426,7 @@ function gitCommit(options) {
|
|
|
416
426
|
*
|
|
417
427
|
* @param options Configuration options for the parser.
|
|
418
428
|
* @returns A value parser that accepts any git reference.
|
|
429
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
419
430
|
* @since 0.9.0
|
|
420
431
|
*/
|
|
421
432
|
function gitRef(options) {
|
|
@@ -474,16 +485,25 @@ function gitRef(options) {
|
|
|
474
485
|
depth
|
|
475
486
|
})
|
|
476
487
|
]);
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
}
|
|
488
|
+
const seen = /* @__PURE__ */ new Set();
|
|
489
|
+
for (const branch of branches) if (branch.startsWith(prefix) && !seen.has(branch)) {
|
|
490
|
+
seen.add(branch);
|
|
491
|
+
yield {
|
|
492
|
+
kind: "literal",
|
|
493
|
+
text: branch
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
for (const tag of tags) if (tag.startsWith(prefix) && !seen.has(tag)) {
|
|
497
|
+
seen.add(tag);
|
|
498
|
+
yield {
|
|
499
|
+
kind: "literal",
|
|
500
|
+
text: tag
|
|
501
|
+
};
|
|
502
|
+
}
|
|
485
503
|
for (const commit of commits) if (commit.oid.startsWith(prefix)) {
|
|
486
|
-
const shortOid = commit.oid.slice(0, 7);
|
|
504
|
+
const shortOid = commit.oid.slice(0, Math.max(7, prefix.length));
|
|
505
|
+
if (seen.has(shortOid)) continue;
|
|
506
|
+
seen.add(shortOid);
|
|
487
507
|
const firstLine = commit.commit.message.split("\n")[0];
|
|
488
508
|
yield {
|
|
489
509
|
kind: "literal",
|
|
@@ -504,7 +524,9 @@ function gitRef(options) {
|
|
|
504
524
|
* Creates a set of git parsers with shared configuration.
|
|
505
525
|
*
|
|
506
526
|
* @param options Shared configuration for the parsers.
|
|
507
|
-
* @returns An object containing git parsers.
|
|
527
|
+
* @returns An object containing git parsers. Each returned method may throw
|
|
528
|
+
* a {@link RangeError} if the merged `suggestionDepth` is not a positive
|
|
529
|
+
* integer.
|
|
508
530
|
* @since 0.9.0
|
|
509
531
|
*/
|
|
510
532
|
function createGitParsers(options) {
|
package/dist/index.d.cts
CHANGED
|
@@ -29,7 +29,9 @@ interface GitParserOptions {
|
|
|
29
29
|
errors?: GitParserErrors;
|
|
30
30
|
/**
|
|
31
31
|
* Maximum number of recent commits to include in shell completion suggestions.
|
|
32
|
-
* Only
|
|
32
|
+
* Only affects suggestions from `gitCommit()` and `gitRef()` parsers, but
|
|
33
|
+
* is validated by all git parser functions.
|
|
34
|
+
* Must be a positive integer.
|
|
33
35
|
* Defaults to 15.
|
|
34
36
|
*
|
|
35
37
|
* @since 0.9.0
|
|
@@ -77,6 +79,7 @@ interface GitParsers {
|
|
|
77
79
|
* Creates a value parser that validates local branch names.
|
|
78
80
|
* @param options Configuration options for the parser.
|
|
79
81
|
* @returns A value parser that accepts existing branch names.
|
|
82
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
80
83
|
*/
|
|
81
84
|
branch(options?: GitParserOptions): ValueParser<"async", string>;
|
|
82
85
|
/**
|
|
@@ -84,24 +87,28 @@ interface GitParsers {
|
|
|
84
87
|
* @param remote The remote name to validate against.
|
|
85
88
|
* @param options Configuration options for the parser.
|
|
86
89
|
* @returns A value parser that accepts existing remote branch names.
|
|
90
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
87
91
|
*/
|
|
88
92
|
remoteBranch(remote: string, options?: GitParserOptions): ValueParser<"async", string>;
|
|
89
93
|
/**
|
|
90
94
|
* Creates a value parser that validates tag names.
|
|
91
95
|
* @param options Configuration options for the parser.
|
|
92
96
|
* @returns A value parser that accepts existing tag names.
|
|
97
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
93
98
|
*/
|
|
94
99
|
tag(options?: GitParserOptions): ValueParser<"async", string>;
|
|
95
100
|
/**
|
|
96
101
|
* Creates a value parser that validates remote names.
|
|
97
102
|
* @param options Configuration options for the parser.
|
|
98
103
|
* @returns A value parser that accepts existing remote names.
|
|
104
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
99
105
|
*/
|
|
100
106
|
remote(options?: GitParserOptions): ValueParser<"async", string>;
|
|
101
107
|
/**
|
|
102
108
|
* Creates a value parser that validates commit SHAs.
|
|
103
109
|
* @param options Configuration options for the parser.
|
|
104
110
|
* @returns A value parser that accepts existing commit SHAs.
|
|
111
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
105
112
|
*/
|
|
106
113
|
commit(options?: GitParserOptions): ValueParser<"async", string>;
|
|
107
114
|
/**
|
|
@@ -109,6 +116,7 @@ interface GitParsers {
|
|
|
109
116
|
* Accepts branch names, tag names, or commit SHAs.
|
|
110
117
|
* @param options Configuration options for the parser.
|
|
111
118
|
* @returns A value parser that accepts any git reference.
|
|
119
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
112
120
|
*/
|
|
113
121
|
ref(options?: GitParserOptions): ValueParser<"async", string>;
|
|
114
122
|
}
|
|
@@ -120,6 +128,7 @@ interface GitParsers {
|
|
|
120
128
|
*
|
|
121
129
|
* @param options Configuration options for the parser.
|
|
122
130
|
* @returns A value parser that accepts existing branch names.
|
|
131
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
123
132
|
* @since 0.9.0
|
|
124
133
|
*
|
|
125
134
|
* @example
|
|
@@ -140,6 +149,7 @@ declare function gitBranch(options?: GitParserOptions): ValueParser<"async", str
|
|
|
140
149
|
* @param remote The remote name to validate against.
|
|
141
150
|
* @param options Configuration options for the parser.
|
|
142
151
|
* @returns A value parser that accepts existing remote branch names.
|
|
152
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
143
153
|
* @since 0.9.0
|
|
144
154
|
*
|
|
145
155
|
* @example
|
|
@@ -156,6 +166,7 @@ declare function gitRemoteBranch(remote: string, options?: GitParserOptions): Va
|
|
|
156
166
|
*
|
|
157
167
|
* @param options Configuration options for the parser.
|
|
158
168
|
* @returns A value parser that accepts existing tag names.
|
|
169
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
159
170
|
* @since 0.9.0
|
|
160
171
|
*/
|
|
161
172
|
declare function gitTag(options?: GitParserOptions): ValueParser<"async", string>;
|
|
@@ -164,6 +175,7 @@ declare function gitTag(options?: GitParserOptions): ValueParser<"async", string
|
|
|
164
175
|
*
|
|
165
176
|
* @param options Configuration options for the parser.
|
|
166
177
|
* @returns A value parser that accepts existing remote names.
|
|
178
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
167
179
|
* @since 0.9.0
|
|
168
180
|
*/
|
|
169
181
|
declare function gitRemote(options?: GitParserOptions): ValueParser<"async", string>;
|
|
@@ -175,6 +187,7 @@ declare function gitRemote(options?: GitParserOptions): ValueParser<"async", str
|
|
|
175
187
|
*
|
|
176
188
|
* @param options Configuration options for the parser.
|
|
177
189
|
* @returns A value parser that accepts existing commit SHAs.
|
|
190
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
178
191
|
* @since 0.9.0
|
|
179
192
|
*/
|
|
180
193
|
declare function gitCommit(options?: GitParserOptions): ValueParser<"async", string>;
|
|
@@ -186,6 +199,7 @@ declare function gitCommit(options?: GitParserOptions): ValueParser<"async", str
|
|
|
186
199
|
*
|
|
187
200
|
* @param options Configuration options for the parser.
|
|
188
201
|
* @returns A value parser that accepts any git reference.
|
|
202
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
189
203
|
* @since 0.9.0
|
|
190
204
|
*/
|
|
191
205
|
declare function gitRef(options?: GitParserOptions): ValueParser<"async", string>;
|
|
@@ -193,7 +207,9 @@ declare function gitRef(options?: GitParserOptions): ValueParser<"async", string
|
|
|
193
207
|
* Creates a set of git parsers with shared configuration.
|
|
194
208
|
*
|
|
195
209
|
* @param options Shared configuration for the parsers.
|
|
196
|
-
* @returns An object containing git parsers.
|
|
210
|
+
* @returns An object containing git parsers. Each returned method may throw
|
|
211
|
+
* a {@link RangeError} if the merged `suggestionDepth` is not a positive
|
|
212
|
+
* integer.
|
|
197
213
|
* @since 0.9.0
|
|
198
214
|
*/
|
|
199
215
|
declare function createGitParsers(options?: GitParserOptions): GitParsers;
|
package/dist/index.d.ts
CHANGED
|
@@ -29,7 +29,9 @@ interface GitParserOptions {
|
|
|
29
29
|
errors?: GitParserErrors;
|
|
30
30
|
/**
|
|
31
31
|
* Maximum number of recent commits to include in shell completion suggestions.
|
|
32
|
-
* Only
|
|
32
|
+
* Only affects suggestions from `gitCommit()` and `gitRef()` parsers, but
|
|
33
|
+
* is validated by all git parser functions.
|
|
34
|
+
* Must be a positive integer.
|
|
33
35
|
* Defaults to 15.
|
|
34
36
|
*
|
|
35
37
|
* @since 0.9.0
|
|
@@ -77,6 +79,7 @@ interface GitParsers {
|
|
|
77
79
|
* Creates a value parser that validates local branch names.
|
|
78
80
|
* @param options Configuration options for the parser.
|
|
79
81
|
* @returns A value parser that accepts existing branch names.
|
|
82
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
80
83
|
*/
|
|
81
84
|
branch(options?: GitParserOptions): ValueParser<"async", string>;
|
|
82
85
|
/**
|
|
@@ -84,24 +87,28 @@ interface GitParsers {
|
|
|
84
87
|
* @param remote The remote name to validate against.
|
|
85
88
|
* @param options Configuration options for the parser.
|
|
86
89
|
* @returns A value parser that accepts existing remote branch names.
|
|
90
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
87
91
|
*/
|
|
88
92
|
remoteBranch(remote: string, options?: GitParserOptions): ValueParser<"async", string>;
|
|
89
93
|
/**
|
|
90
94
|
* Creates a value parser that validates tag names.
|
|
91
95
|
* @param options Configuration options for the parser.
|
|
92
96
|
* @returns A value parser that accepts existing tag names.
|
|
97
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
93
98
|
*/
|
|
94
99
|
tag(options?: GitParserOptions): ValueParser<"async", string>;
|
|
95
100
|
/**
|
|
96
101
|
* Creates a value parser that validates remote names.
|
|
97
102
|
* @param options Configuration options for the parser.
|
|
98
103
|
* @returns A value parser that accepts existing remote names.
|
|
104
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
99
105
|
*/
|
|
100
106
|
remote(options?: GitParserOptions): ValueParser<"async", string>;
|
|
101
107
|
/**
|
|
102
108
|
* Creates a value parser that validates commit SHAs.
|
|
103
109
|
* @param options Configuration options for the parser.
|
|
104
110
|
* @returns A value parser that accepts existing commit SHAs.
|
|
111
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
105
112
|
*/
|
|
106
113
|
commit(options?: GitParserOptions): ValueParser<"async", string>;
|
|
107
114
|
/**
|
|
@@ -109,6 +116,7 @@ interface GitParsers {
|
|
|
109
116
|
* Accepts branch names, tag names, or commit SHAs.
|
|
110
117
|
* @param options Configuration options for the parser.
|
|
111
118
|
* @returns A value parser that accepts any git reference.
|
|
119
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
112
120
|
*/
|
|
113
121
|
ref(options?: GitParserOptions): ValueParser<"async", string>;
|
|
114
122
|
}
|
|
@@ -120,6 +128,7 @@ interface GitParsers {
|
|
|
120
128
|
*
|
|
121
129
|
* @param options Configuration options for the parser.
|
|
122
130
|
* @returns A value parser that accepts existing branch names.
|
|
131
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
123
132
|
* @since 0.9.0
|
|
124
133
|
*
|
|
125
134
|
* @example
|
|
@@ -140,6 +149,7 @@ declare function gitBranch(options?: GitParserOptions): ValueParser<"async", str
|
|
|
140
149
|
* @param remote The remote name to validate against.
|
|
141
150
|
* @param options Configuration options for the parser.
|
|
142
151
|
* @returns A value parser that accepts existing remote branch names.
|
|
152
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
143
153
|
* @since 0.9.0
|
|
144
154
|
*
|
|
145
155
|
* @example
|
|
@@ -156,6 +166,7 @@ declare function gitRemoteBranch(remote: string, options?: GitParserOptions): Va
|
|
|
156
166
|
*
|
|
157
167
|
* @param options Configuration options for the parser.
|
|
158
168
|
* @returns A value parser that accepts existing tag names.
|
|
169
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
159
170
|
* @since 0.9.0
|
|
160
171
|
*/
|
|
161
172
|
declare function gitTag(options?: GitParserOptions): ValueParser<"async", string>;
|
|
@@ -164,6 +175,7 @@ declare function gitTag(options?: GitParserOptions): ValueParser<"async", string
|
|
|
164
175
|
*
|
|
165
176
|
* @param options Configuration options for the parser.
|
|
166
177
|
* @returns A value parser that accepts existing remote names.
|
|
178
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
167
179
|
* @since 0.9.0
|
|
168
180
|
*/
|
|
169
181
|
declare function gitRemote(options?: GitParserOptions): ValueParser<"async", string>;
|
|
@@ -175,6 +187,7 @@ declare function gitRemote(options?: GitParserOptions): ValueParser<"async", str
|
|
|
175
187
|
*
|
|
176
188
|
* @param options Configuration options for the parser.
|
|
177
189
|
* @returns A value parser that accepts existing commit SHAs.
|
|
190
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
178
191
|
* @since 0.9.0
|
|
179
192
|
*/
|
|
180
193
|
declare function gitCommit(options?: GitParserOptions): ValueParser<"async", string>;
|
|
@@ -186,6 +199,7 @@ declare function gitCommit(options?: GitParserOptions): ValueParser<"async", str
|
|
|
186
199
|
*
|
|
187
200
|
* @param options Configuration options for the parser.
|
|
188
201
|
* @returns A value parser that accepts any git reference.
|
|
202
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
189
203
|
* @since 0.9.0
|
|
190
204
|
*/
|
|
191
205
|
declare function gitRef(options?: GitParserOptions): ValueParser<"async", string>;
|
|
@@ -193,7 +207,9 @@ declare function gitRef(options?: GitParserOptions): ValueParser<"async", string
|
|
|
193
207
|
* Creates a set of git parsers with shared configuration.
|
|
194
208
|
*
|
|
195
209
|
* @param options Shared configuration for the parsers.
|
|
196
|
-
* @returns An object containing git parsers.
|
|
210
|
+
* @returns An object containing git parsers. Each returned method may throw
|
|
211
|
+
* a {@link RangeError} if the merged `suggestionDepth` is not a positive
|
|
212
|
+
* integer.
|
|
197
213
|
* @since 0.9.0
|
|
198
214
|
*/
|
|
199
215
|
declare function createGitParsers(options?: GitParserOptions): GitParsers;
|
package/dist/index.js
CHANGED
|
@@ -56,6 +56,14 @@ function listFailureMessage(error, dir, errors, fallback) {
|
|
|
56
56
|
const DEFAULT_SUGGESTION_DEPTH = 15;
|
|
57
57
|
function createAsyncValueParser(options, metavar, parseFn, suggestFn) {
|
|
58
58
|
ensureNonEmptyString(metavar);
|
|
59
|
+
if (options?.suggestionDepth !== void 0) {
|
|
60
|
+
if (!Number.isInteger(options.suggestionDepth) || options.suggestionDepth < 1) {
|
|
61
|
+
const depth = options.suggestionDepth;
|
|
62
|
+
const repr = typeof depth === "number" ? String(depth) : typeof depth === "string" ? JSON.stringify(depth) : `${typeof depth} ${String(depth)}`;
|
|
63
|
+
throw new RangeError(`Invalid suggestionDepth (must be a positive integer): ${repr}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const validatedDepth = options?.suggestionDepth ?? DEFAULT_SUGGESTION_DEPTH;
|
|
59
67
|
return {
|
|
60
68
|
$mode: "async",
|
|
61
69
|
metavar,
|
|
@@ -68,10 +76,7 @@ function createAsyncValueParser(options, metavar, parseFn, suggestFn) {
|
|
|
68
76
|
},
|
|
69
77
|
async *suggest(prefix) {
|
|
70
78
|
const dir = getRepoDir(options?.dir);
|
|
71
|
-
if (suggestFn)
|
|
72
|
-
const depth = options?.suggestionDepth ?? DEFAULT_SUGGESTION_DEPTH;
|
|
73
|
-
yield* suggestFn(dir, prefix, depth);
|
|
74
|
-
}
|
|
79
|
+
if (suggestFn) yield* suggestFn(dir, prefix, validatedDepth);
|
|
75
80
|
}
|
|
76
81
|
};
|
|
77
82
|
}
|
|
@@ -83,6 +88,7 @@ function createAsyncValueParser(options, metavar, parseFn, suggestFn) {
|
|
|
83
88
|
*
|
|
84
89
|
* @param options Configuration options for the parser.
|
|
85
90
|
* @returns A value parser that accepts existing branch names.
|
|
91
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
86
92
|
* @since 0.9.0
|
|
87
93
|
*
|
|
88
94
|
* @example
|
|
@@ -148,6 +154,7 @@ function gitBranch(options) {
|
|
|
148
154
|
* @param remote The remote name to validate against.
|
|
149
155
|
* @param options Configuration options for the parser.
|
|
150
156
|
* @returns A value parser that accepts existing remote branch names.
|
|
157
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
151
158
|
* @since 0.9.0
|
|
152
159
|
*
|
|
153
160
|
* @example
|
|
@@ -212,6 +219,7 @@ function gitRemoteBranch(remote, options) {
|
|
|
212
219
|
*
|
|
213
220
|
* @param options Configuration options for the parser.
|
|
214
221
|
* @returns A value parser that accepts existing tag names.
|
|
222
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
215
223
|
* @since 0.9.0
|
|
216
224
|
*/
|
|
217
225
|
function gitTag(options) {
|
|
@@ -265,6 +273,7 @@ function gitTag(options) {
|
|
|
265
273
|
*
|
|
266
274
|
* @param options Configuration options for the parser.
|
|
267
275
|
* @returns A value parser that accepts existing remote names.
|
|
276
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
268
277
|
* @since 0.9.0
|
|
269
278
|
*/
|
|
270
279
|
function gitRemote(options) {
|
|
@@ -322,6 +331,7 @@ function gitRemote(options) {
|
|
|
322
331
|
*
|
|
323
332
|
* @param options Configuration options for the parser.
|
|
324
333
|
* @returns A value parser that accepts existing commit SHAs.
|
|
334
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
325
335
|
* @since 0.9.0
|
|
326
336
|
*/
|
|
327
337
|
function gitCommit(options) {
|
|
@@ -369,7 +379,7 @@ function gitCommit(options) {
|
|
|
369
379
|
depth
|
|
370
380
|
});
|
|
371
381
|
for (const commit of commits) if (commit.oid.startsWith(prefix)) {
|
|
372
|
-
const shortOid = commit.oid.slice(0, 7);
|
|
382
|
+
const shortOid = commit.oid.slice(0, Math.max(7, prefix.length));
|
|
373
383
|
const firstLine = commit.commit.message.split("\n")[0];
|
|
374
384
|
yield {
|
|
375
385
|
kind: "literal",
|
|
@@ -394,6 +404,7 @@ function gitCommit(options) {
|
|
|
394
404
|
*
|
|
395
405
|
* @param options Configuration options for the parser.
|
|
396
406
|
* @returns A value parser that accepts any git reference.
|
|
407
|
+
* @throws {RangeError} If `suggestionDepth` is not a positive integer.
|
|
397
408
|
* @since 0.9.0
|
|
398
409
|
*/
|
|
399
410
|
function gitRef(options) {
|
|
@@ -452,16 +463,25 @@ function gitRef(options) {
|
|
|
452
463
|
depth
|
|
453
464
|
})
|
|
454
465
|
]);
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
}
|
|
466
|
+
const seen = /* @__PURE__ */ new Set();
|
|
467
|
+
for (const branch of branches) if (branch.startsWith(prefix) && !seen.has(branch)) {
|
|
468
|
+
seen.add(branch);
|
|
469
|
+
yield {
|
|
470
|
+
kind: "literal",
|
|
471
|
+
text: branch
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
for (const tag of tags) if (tag.startsWith(prefix) && !seen.has(tag)) {
|
|
475
|
+
seen.add(tag);
|
|
476
|
+
yield {
|
|
477
|
+
kind: "literal",
|
|
478
|
+
text: tag
|
|
479
|
+
};
|
|
480
|
+
}
|
|
463
481
|
for (const commit of commits) if (commit.oid.startsWith(prefix)) {
|
|
464
|
-
const shortOid = commit.oid.slice(0, 7);
|
|
482
|
+
const shortOid = commit.oid.slice(0, Math.max(7, prefix.length));
|
|
483
|
+
if (seen.has(shortOid)) continue;
|
|
484
|
+
seen.add(shortOid);
|
|
465
485
|
const firstLine = commit.commit.message.split("\n")[0];
|
|
466
486
|
yield {
|
|
467
487
|
kind: "literal",
|
|
@@ -482,7 +502,9 @@ function gitRef(options) {
|
|
|
482
502
|
* Creates a set of git parsers with shared configuration.
|
|
483
503
|
*
|
|
484
504
|
* @param options Shared configuration for the parsers.
|
|
485
|
-
* @returns An object containing git parsers.
|
|
505
|
+
* @returns An object containing git parsers. Each returned method may throw
|
|
506
|
+
* a {@link RangeError} if the merged `suggestionDepth` is not a positive
|
|
507
|
+
* integer.
|
|
486
508
|
* @since 0.9.0
|
|
487
509
|
*/
|
|
488
510
|
function createGitParsers(options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/git",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.885+3300ebe1",
|
|
4
4
|
"description": "Git value parsers for Optique",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@logtape/logtape": "^1.2.2",
|
|
61
61
|
"isomorphic-git": "^1.36.1",
|
|
62
|
-
"@optique/core": "1.0.0-dev.
|
|
62
|
+
"@optique/core": "1.0.0-dev.885+3300ebe1"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@types/node": "^20.19.9",
|