@optique/git 0.9.0-dev.1
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/LICENSE +20 -0
- package/README.md +272 -0
- package/dist/index.cjs +553 -0
- package/dist/index.d.cts +215 -0
- package/dist/index.d.ts +215 -0
- package/dist/index.js +489 -0
- package/package.json +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2025–2026 Hong Minhee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
@optique/git
|
|
2
|
+
============
|
|
3
|
+
|
|
4
|
+
Git reference parsers for Optique CLI parser.
|
|
5
|
+
|
|
6
|
+
This package provides async value parsers for validating Git references
|
|
7
|
+
(branches, tags, commits, remotes) using [isomorphic-git]. It allows CLI
|
|
8
|
+
tools to accept only valid Git references from user input.
|
|
9
|
+
|
|
10
|
+
[isomorphic-git]: https://github.com/isomorphic-git/isomorphic-git
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
Installation
|
|
14
|
+
------------
|
|
15
|
+
|
|
16
|
+
~~~~ bash
|
|
17
|
+
# Deno
|
|
18
|
+
deno add jsr:@optique/git
|
|
19
|
+
|
|
20
|
+
# npm
|
|
21
|
+
npm install @optique/git
|
|
22
|
+
|
|
23
|
+
# pnpm
|
|
24
|
+
pnpm add @optique/git
|
|
25
|
+
~~~~
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
Quick start
|
|
29
|
+
-----------
|
|
30
|
+
|
|
31
|
+
~~~~ typescript
|
|
32
|
+
import { gitBranch, gitTag, gitCommit } from "@optique/git";
|
|
33
|
+
import { argument, option, object } from "@optique/core/primitives";
|
|
34
|
+
import { parse } from "@optique/core/parser";
|
|
35
|
+
|
|
36
|
+
const parser = object({
|
|
37
|
+
branch: argument(gitBranch()),
|
|
38
|
+
tag: option("-t", "--tag", gitTag()),
|
|
39
|
+
commit: option("-c", "--commit", gitCommit()),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const result = await parse(parser, ["feature/login"]);
|
|
43
|
+
// result.success === true
|
|
44
|
+
// result.value.branch === "feature/login"
|
|
45
|
+
~~~~
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
Custom repository location
|
|
49
|
+
--------------------------
|
|
50
|
+
|
|
51
|
+
By default, parsers use the current working directory as the Git repository.
|
|
52
|
+
Use `createGitParsers()` to create parsers for a different repository:
|
|
53
|
+
|
|
54
|
+
~~~~ typescript
|
|
55
|
+
import { createGitParsers } from "@optique/git";
|
|
56
|
+
import { argument, object } from "@optique/core/primitives";
|
|
57
|
+
import { parse } from "@optique/core/parser";
|
|
58
|
+
|
|
59
|
+
const git = createGitParsers({ dir: "/path/to/repo" });
|
|
60
|
+
|
|
61
|
+
const parser = object({
|
|
62
|
+
branch: argument(git.branch()),
|
|
63
|
+
tag: option("-t", "--tag", git.tag()),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const result = await parse(parser, ["v1.0.0"]);
|
|
67
|
+
// result.success === true
|
|
68
|
+
// result.value.tag === "v1.0.0"
|
|
69
|
+
~~~~
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
API
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
### `gitBranch(options?)`
|
|
76
|
+
|
|
77
|
+
A value parser for local branch names. Validates that the input matches an
|
|
78
|
+
existing branch in the repository.
|
|
79
|
+
|
|
80
|
+
~~~~ typescript
|
|
81
|
+
import { gitBranch } from "@optique/git";
|
|
82
|
+
import { argument, object } from "@optique/core/primitives";
|
|
83
|
+
import { parse } from "@optique/core/parser";
|
|
84
|
+
|
|
85
|
+
const parser = object({
|
|
86
|
+
branch: argument(gitBranch()),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const result = await parse(parser, ["main"]);
|
|
90
|
+
// Valid branch
|
|
91
|
+
~~~~
|
|
92
|
+
|
|
93
|
+
Options:
|
|
94
|
+
- `fs`: Custom filesystem implementation (defaults to Deno or Node.js fs)
|
|
95
|
+
- `dir`: Git repository directory (defaults to current working directory)
|
|
96
|
+
- `metavar`: Metavar name for help text (default: `"BRANCH"`)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
### `gitRemoteBranch(remote, options?)`
|
|
100
|
+
|
|
101
|
+
A value parser for remote branch names. Validates that the input matches an
|
|
102
|
+
existing branch on the specified remote.
|
|
103
|
+
|
|
104
|
+
~~~~ typescript
|
|
105
|
+
import { gitRemoteBranch } from "@optique/git";
|
|
106
|
+
import { option, object } from "@optique/core/primitives";
|
|
107
|
+
import { parse } from "@optique/core/parser";
|
|
108
|
+
|
|
109
|
+
const parser = object({
|
|
110
|
+
branch: option("-b", "--branch", gitRemoteBranch("origin")),
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const result = await parse(parser, ["--branch=main"]);
|
|
114
|
+
// Valid remote branch on origin
|
|
115
|
+
~~~~
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
### `gitTag(options?)`
|
|
119
|
+
|
|
120
|
+
A value parser for tag names. Validates that the input matches an existing tag
|
|
121
|
+
in the repository.
|
|
122
|
+
|
|
123
|
+
~~~~ typescript
|
|
124
|
+
import { gitTag } from "@optique/git";
|
|
125
|
+
import { option, object } from "@optique/core/primitives";
|
|
126
|
+
import { parse } from "@optique/core/parser";
|
|
127
|
+
|
|
128
|
+
const parser = object({
|
|
129
|
+
tag: option("-t", "--tag", gitTag()),
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const result = await parse(parser, ["--tag=v1.0.0"]);
|
|
133
|
+
// Valid tag
|
|
134
|
+
~~~~
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
### `gitRemote(options?)`
|
|
138
|
+
|
|
139
|
+
A value parser for remote names. Validates that the input matches an existing
|
|
140
|
+
remote in the repository.
|
|
141
|
+
|
|
142
|
+
~~~~ typescript
|
|
143
|
+
import { gitRemote } from "@optique/git";
|
|
144
|
+
import { option, object } from "@optique/core/primitives";
|
|
145
|
+
import { parse } from "@optique/core/parser";
|
|
146
|
+
|
|
147
|
+
const parser = object({
|
|
148
|
+
remote: option("-r", "--remote", gitRemote()),
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const result = await parse(parser, ["--remote=origin"]);
|
|
152
|
+
// Valid remote
|
|
153
|
+
~~~~
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
### `gitCommit(options?)`
|
|
157
|
+
|
|
158
|
+
A value parser for commit SHAs. Validates that the input is a valid commit SHA
|
|
159
|
+
(full or shortened) that exists in the repository.
|
|
160
|
+
|
|
161
|
+
~~~~ typescript
|
|
162
|
+
import { gitCommit } from "@optique/git";
|
|
163
|
+
import { option, object } from "@optique/core/primitives";
|
|
164
|
+
import { parse } from "@optique/core/parser";
|
|
165
|
+
|
|
166
|
+
const parser = object({
|
|
167
|
+
commit: option("-c", "--commit", gitCommit()),
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const result = await parse(parser, ["--commit=abc1234"]);
|
|
171
|
+
// Valid commit SHA
|
|
172
|
+
~~~~
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
### `gitRef(options?)`
|
|
176
|
+
|
|
177
|
+
A value parser for any Git reference (branches, tags, or commits). Validates
|
|
178
|
+
that the input resolves to a valid Git reference.
|
|
179
|
+
|
|
180
|
+
~~~~ typescript
|
|
181
|
+
import { gitRef } from "@optique/git";
|
|
182
|
+
import { option, object } from "@optique/core/primitives";
|
|
183
|
+
import { parse } from "@optique/core/parser";
|
|
184
|
+
|
|
185
|
+
const parser = object({
|
|
186
|
+
ref: option("--ref", gitRef()),
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
const result = await parse(parser, ["--ref=v1.0.0"]);
|
|
190
|
+
// Valid branch, tag, or commit
|
|
191
|
+
~~~~
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
### `createGitParsers(options?)`
|
|
195
|
+
|
|
196
|
+
Creates a factory for Git parsers with shared configuration. All parsers
|
|
197
|
+
created by the factory share the same filesystem and directory options.
|
|
198
|
+
|
|
199
|
+
~~~~ typescript
|
|
200
|
+
import { createGitParsers } from "@optique/git";
|
|
201
|
+
import { argument, option, object } from "@optique/core/primitives";
|
|
202
|
+
import { parse } from "@optique/core/parser";
|
|
203
|
+
|
|
204
|
+
const git = createGitParsers({ dir: "/path/to/repo" });
|
|
205
|
+
|
|
206
|
+
const parser = object({
|
|
207
|
+
branch: argument(git.branch()),
|
|
208
|
+
tag: option("-t", "--tag", git.tag()),
|
|
209
|
+
commit: option("-c", "--commit", git.commit()),
|
|
210
|
+
ref: option("--ref", git.ref()),
|
|
211
|
+
});
|
|
212
|
+
~~~~
|
|
213
|
+
|
|
214
|
+
The factory returns a `GitParsers` object with the following methods:
|
|
215
|
+
- `branch(options?)` - Same as `gitBranch()`
|
|
216
|
+
- `remoteBranch(remote, options?)` - Same as `gitRemoteBranch()`
|
|
217
|
+
- `tag(options?)` - Same as `gitTag()`
|
|
218
|
+
- `remote(options?)` - Same as `gitRemote()`
|
|
219
|
+
- `commit(options?)` - Same as `gitCommit()`
|
|
220
|
+
- `ref(options?)` - Same as `gitRef()`
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
### `FileSystem` interface
|
|
224
|
+
|
|
225
|
+
Custom filesystem implementations must implement this interface for use with
|
|
226
|
+
Git parsers:
|
|
227
|
+
|
|
228
|
+
~~~~ typescript
|
|
229
|
+
import type { FileSystem } from "@optique/git";
|
|
230
|
+
|
|
231
|
+
const customFs: FileSystem = {
|
|
232
|
+
async readFile(path) { /* ... */ },
|
|
233
|
+
async writeFile(path, data) { /* ... */ },
|
|
234
|
+
async mkdir(path, options) { /* ... */ },
|
|
235
|
+
async rmdir(path, options) { /* ... */ },
|
|
236
|
+
async unlink(path) { /* ... */ },
|
|
237
|
+
async readdir(path) { /* ... */ },
|
|
238
|
+
async lstat(path) { /* ... */ },
|
|
239
|
+
async stat(path) { /* ... */ },
|
|
240
|
+
async readlink(path) { /* ... */ },
|
|
241
|
+
async symlink(target, path) { /* ... */ },
|
|
242
|
+
async chmod(path, mode) { /* ... */ },
|
|
243
|
+
async chown(path, uid, gid) { /* ... */ },
|
|
244
|
+
async rename(oldPath, newPath) { /* ... */ },
|
|
245
|
+
async copyFile(srcPath, destPath) { /* ... */ },
|
|
246
|
+
async exists(path) { /* ... */ },
|
|
247
|
+
};
|
|
248
|
+
~~~~
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
Shell completion
|
|
252
|
+
----------------
|
|
253
|
+
|
|
254
|
+
All Git parsers support automatic shell completion. The parsers provide
|
|
255
|
+
suggestions for existing branches, tags, remotes, and commits that match
|
|
256
|
+
the user's input prefix.
|
|
257
|
+
|
|
258
|
+
~~~~ typescript
|
|
259
|
+
import { gitBranch } from "@optique/git";
|
|
260
|
+
import { argument, object } from "@optique/core/primitives";
|
|
261
|
+
|
|
262
|
+
const parser = object({
|
|
263
|
+
branch: argument(gitBranch()),
|
|
264
|
+
});
|
|
265
|
+
// Shell completion will suggest matching branch names
|
|
266
|
+
~~~~
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
License
|
|
270
|
+
-------
|
|
271
|
+
|
|
272
|
+
Distributed under the MIT License. See the *LICENSE* file for details.
|