@taskset/cli 0.1.2
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/CHANGELOG.md +20 -0
- package/LICENSE +21 -0
- package/README.md +20 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +3 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +203 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/package.json +48 -0
- package/src/bin.ts +5 -0
- package/src/cli.ts +282 -0
- package/src/index.ts +2 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# @taskset/cli
|
|
2
|
+
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Publish the Taskset CLI and its runtime package chain under the `@taskset`
|
|
8
|
+
scope with public npm access and intentional package contents.
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
- @taskset/contracts@0.1.2
|
|
11
|
+
- @taskset/core@0.1.2
|
|
12
|
+
|
|
13
|
+
## 0.1.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Changeset initiated
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
- @taskset/contracts@0.1.1
|
|
20
|
+
- @taskset/core@0.1.1
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Taskset contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, 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,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# @taskset/cli
|
|
2
|
+
|
|
3
|
+
The public, scriptable command-line interface for Taskset. Install it with:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pnpm add --save-dev @taskset/cli
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
It contains argument parsing, stdout and stderr rendering, exit-code mapping,
|
|
10
|
+
the `taskset` executable, and the `defineConfig` helper used by
|
|
11
|
+
`taskset.config.ts`. Repository discovery, validation, storage, and task
|
|
12
|
+
behavior are delegated to `@taskset/core`.
|
|
13
|
+
|
|
14
|
+
Current commands:
|
|
15
|
+
|
|
16
|
+
- `taskset init`
|
|
17
|
+
- `taskset config`
|
|
18
|
+
- `taskset task create`
|
|
19
|
+
- `taskset task list`
|
|
20
|
+
- `taskset task show`
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
|
package/dist/bin.js
ADDED
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface CliContext {
|
|
2
|
+
readonly cwd?: string;
|
|
3
|
+
readonly stderr?: (value: string) => void;
|
|
4
|
+
readonly stdout?: (value: string) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare function runCli(args: readonly string[], context?: CliContext): Promise<number>;
|
|
7
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAiCA,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACzC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACzC;AA2ED,wBAAsB,MAAM,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAyK/F"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { parseArgs } from 'node:util';
|
|
3
|
+
import { TASK_PRIORITIES, TASK_STATUSES, } from '@taskset/contracts';
|
|
4
|
+
import { createTask, discoverRepository, initializeRepository, listTasks, readTask, serializeTaskFile, } from '@taskset/core';
|
|
5
|
+
const USAGE = `Usage:
|
|
6
|
+
taskset init [--cwd <path>]
|
|
7
|
+
taskset config [--json] [--cwd <path>]
|
|
8
|
+
taskset task create --title <title> [options]
|
|
9
|
+
taskset task list [--json] [--cwd <path>]
|
|
10
|
+
taskset task show <task-id> [--json] [--cwd <path>]
|
|
11
|
+
|
|
12
|
+
Create options:
|
|
13
|
+
--status <status>
|
|
14
|
+
--priority <priority>
|
|
15
|
+
--label <label> Repeatable
|
|
16
|
+
--depends-on <task-id> Repeatable
|
|
17
|
+
--file <path> Repeatable
|
|
18
|
+
--body <markdown>
|
|
19
|
+
`;
|
|
20
|
+
class CliUsageError extends Error {
|
|
21
|
+
constructor(message) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = 'CliUsageError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function parseTaskStatus(value) {
|
|
27
|
+
if (value === undefined) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
if (!TASK_STATUSES.includes(value)) {
|
|
31
|
+
throw new CliUsageError(`Invalid task status "${value}"`);
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
function parseTaskPriority(value) {
|
|
36
|
+
if (value === undefined) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
if (!TASK_PRIORITIES.includes(value)) {
|
|
40
|
+
throw new CliUsageError(`Invalid task priority "${value}"`);
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
function resolveCommandCwd(baseDirectory, cwdOption) {
|
|
45
|
+
return cwdOption ? path.resolve(baseDirectory, cwdOption) : baseDirectory;
|
|
46
|
+
}
|
|
47
|
+
function parseCommonOptions(args) {
|
|
48
|
+
return parseArgs({
|
|
49
|
+
args,
|
|
50
|
+
allowPositionals: false,
|
|
51
|
+
options: {
|
|
52
|
+
cwd: { type: 'string' },
|
|
53
|
+
json: { type: 'boolean' },
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function requireSinglePositional(positionals, name) {
|
|
58
|
+
if (positionals.length !== 1 || !positionals[0]) {
|
|
59
|
+
throw new CliUsageError(`Expected exactly one ${name}`);
|
|
60
|
+
}
|
|
61
|
+
return positionals[0];
|
|
62
|
+
}
|
|
63
|
+
function formatError(error) {
|
|
64
|
+
if (!(error instanceof Error)) {
|
|
65
|
+
return 'Unknown Taskset error';
|
|
66
|
+
}
|
|
67
|
+
const issues = 'issues' in error && Array.isArray(error.issues)
|
|
68
|
+
? error.issues
|
|
69
|
+
.map((issue) => typeof issue === 'object' && issue !== null && 'field' in issue && 'message' in issue
|
|
70
|
+
? `\n ${String(issue.field)}: ${String(issue.message)}`
|
|
71
|
+
: '')
|
|
72
|
+
.join('')
|
|
73
|
+
: '';
|
|
74
|
+
return `${error.message}${issues}`;
|
|
75
|
+
}
|
|
76
|
+
export async function runCli(args, context = {}) {
|
|
77
|
+
const cwd = path.resolve(context.cwd ?? process.cwd());
|
|
78
|
+
const stdout = context.stdout ?? ((value) => process.stdout.write(value));
|
|
79
|
+
const stderr = context.stderr ?? ((value) => process.stderr.write(value));
|
|
80
|
+
try {
|
|
81
|
+
const [command, subcommand] = args;
|
|
82
|
+
const commandArgs = args.slice(1);
|
|
83
|
+
const taskArgs = args.slice(2);
|
|
84
|
+
if (!command || command === 'help' || command === '--help' || command === '-h') {
|
|
85
|
+
stdout(USAGE);
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
if (command === 'init') {
|
|
89
|
+
const parsed = parseCommonOptions(commandArgs);
|
|
90
|
+
const repository = await initializeRepository(resolveCommandCwd(cwd, parsed.values.cwd));
|
|
91
|
+
stdout(`Initialized Taskset in ${repository.rootDirectory}\n`);
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
94
|
+
if (command === 'config') {
|
|
95
|
+
const parsed = parseCommonOptions(commandArgs);
|
|
96
|
+
const repository = await discoverRepository(resolveCommandCwd(cwd, parsed.values.cwd));
|
|
97
|
+
if (parsed.values.json) {
|
|
98
|
+
stdout(`${JSON.stringify({
|
|
99
|
+
rootDirectory: repository.rootDirectory,
|
|
100
|
+
configPath: repository.configPath,
|
|
101
|
+
dataDirectory: repository.dataDirectory,
|
|
102
|
+
config: repository.config,
|
|
103
|
+
}, null, 2)}\n`);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
stdout(`${repository.configPath}\n`);
|
|
107
|
+
}
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
if (command !== 'task') {
|
|
111
|
+
throw new CliUsageError(`Unknown command "${command}"`);
|
|
112
|
+
}
|
|
113
|
+
if (subcommand === 'create') {
|
|
114
|
+
const parsed = parseArgs({
|
|
115
|
+
args: taskArgs,
|
|
116
|
+
allowPositionals: false,
|
|
117
|
+
options: {
|
|
118
|
+
body: { type: 'string' },
|
|
119
|
+
cwd: { type: 'string' },
|
|
120
|
+
'depends-on': { type: 'string', multiple: true },
|
|
121
|
+
file: { type: 'string', multiple: true },
|
|
122
|
+
json: { type: 'boolean' },
|
|
123
|
+
label: { type: 'string', multiple: true },
|
|
124
|
+
priority: { type: 'string' },
|
|
125
|
+
status: { type: 'string' },
|
|
126
|
+
title: { type: 'string' },
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
if (!parsed.values.title) {
|
|
130
|
+
throw new CliUsageError('The --title option is required');
|
|
131
|
+
}
|
|
132
|
+
const status = parseTaskStatus(parsed.values.status);
|
|
133
|
+
const priority = parseTaskPriority(parsed.values.priority);
|
|
134
|
+
const repository = await discoverRepository(resolveCommandCwd(cwd, parsed.values.cwd));
|
|
135
|
+
const record = await createTask(repository, {
|
|
136
|
+
title: parsed.values.title,
|
|
137
|
+
...(status ? { status } : {}),
|
|
138
|
+
...(priority ? { priority } : {}),
|
|
139
|
+
...(parsed.values.label ? { labels: parsed.values.label } : {}),
|
|
140
|
+
...(parsed.values['depends-on'] ? { dependsOn: parsed.values['depends-on'] } : {}),
|
|
141
|
+
...(parsed.values.file ? { files: parsed.values.file } : {}),
|
|
142
|
+
...(parsed.values.body !== undefined ? { body: parsed.values.body } : {}),
|
|
143
|
+
});
|
|
144
|
+
if (parsed.values.json) {
|
|
145
|
+
stdout(`${JSON.stringify({ relativePath: record.relativePath, ...record.task.metadata }, null, 2)}\n`);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
stdout(`${record.task.metadata.id}\n`);
|
|
149
|
+
}
|
|
150
|
+
return 0;
|
|
151
|
+
}
|
|
152
|
+
if (subcommand === 'list') {
|
|
153
|
+
const parsed = parseCommonOptions(taskArgs);
|
|
154
|
+
const repository = await discoverRepository(resolveCommandCwd(cwd, parsed.values.cwd));
|
|
155
|
+
const records = await listTasks(repository);
|
|
156
|
+
if (parsed.values.json) {
|
|
157
|
+
stdout(`${JSON.stringify(records.map((record) => ({
|
|
158
|
+
relativePath: record.relativePath,
|
|
159
|
+
...record.task.metadata,
|
|
160
|
+
})), null, 2)}\n`);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
for (const record of records) {
|
|
164
|
+
stdout(`${record.task.metadata.id}\t${record.task.metadata.status}\t${record.task.metadata.title}\n`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return 0;
|
|
168
|
+
}
|
|
169
|
+
if (subcommand === 'show') {
|
|
170
|
+
const parsed = parseArgs({
|
|
171
|
+
args: taskArgs,
|
|
172
|
+
allowPositionals: true,
|
|
173
|
+
options: {
|
|
174
|
+
cwd: { type: 'string' },
|
|
175
|
+
json: { type: 'boolean' },
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
const taskId = requireSinglePositional(parsed.positionals, 'task ID');
|
|
179
|
+
const repository = await discoverRepository(resolveCommandCwd(cwd, parsed.values.cwd));
|
|
180
|
+
const record = await readTask(repository, taskId);
|
|
181
|
+
if (parsed.values.json) {
|
|
182
|
+
stdout(`${JSON.stringify({
|
|
183
|
+
relativePath: record.relativePath,
|
|
184
|
+
metadata: record.task.metadata,
|
|
185
|
+
body: record.task.body,
|
|
186
|
+
}, null, 2)}\n`);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
stdout(serializeTaskFile(record.task, { filePath: record.relativePath }));
|
|
190
|
+
}
|
|
191
|
+
return 0;
|
|
192
|
+
}
|
|
193
|
+
throw new CliUsageError(`Unknown task command "${subcommand ?? ''}"`);
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
if (error instanceof CliUsageError || error instanceof TypeError) {
|
|
197
|
+
stderr(`${formatError(error)}\n\n${USAGE}`);
|
|
198
|
+
return 2;
|
|
199
|
+
}
|
|
200
|
+
stderr(`${formatError(error)}\n`);
|
|
201
|
+
return 1;
|
|
202
|
+
}
|
|
203
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA"}
|
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@taskset/cli",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"private": false,
|
|
5
|
+
"version": "0.1.2",
|
|
6
|
+
"description": "The scriptable command-line interface for Taskset.",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"src",
|
|
12
|
+
"!src/**/*.test.ts",
|
|
13
|
+
"README.md",
|
|
14
|
+
"CHANGELOG.md"
|
|
15
|
+
],
|
|
16
|
+
"bin": {
|
|
17
|
+
"taskset": "./dist/bin.js"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"development": "./src/index.ts",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=24.16.0"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@taskset/contracts": "0.1.2",
|
|
34
|
+
"@taskset/core": "0.1.2"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^25.9.3",
|
|
38
|
+
"typescript": "^6.0.3",
|
|
39
|
+
"vitest": "^4.1.8",
|
|
40
|
+
"@taskset/configs": "0.1.1"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "pnpm clean && tsc",
|
|
44
|
+
"clean": "node --eval \"import { rmSync } from 'node:fs'; rmSync('dist', { recursive: true, force: true })\"",
|
|
45
|
+
"test": "vitest run --root ../.. packages/cli/src",
|
|
46
|
+
"test:watch": "vitest --root ../.. packages/cli/src"
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/bin.ts
ADDED
package/src/cli.ts
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { parseArgs } from 'node:util'
|
|
3
|
+
import {
|
|
4
|
+
TASK_PRIORITIES,
|
|
5
|
+
TASK_STATUSES,
|
|
6
|
+
type TaskPriority,
|
|
7
|
+
type TaskStatus,
|
|
8
|
+
} from '@taskset/contracts'
|
|
9
|
+
import {
|
|
10
|
+
createTask,
|
|
11
|
+
discoverRepository,
|
|
12
|
+
initializeRepository,
|
|
13
|
+
listTasks,
|
|
14
|
+
readTask,
|
|
15
|
+
serializeTaskFile,
|
|
16
|
+
} from '@taskset/core'
|
|
17
|
+
|
|
18
|
+
const USAGE = `Usage:
|
|
19
|
+
taskset init [--cwd <path>]
|
|
20
|
+
taskset config [--json] [--cwd <path>]
|
|
21
|
+
taskset task create --title <title> [options]
|
|
22
|
+
taskset task list [--json] [--cwd <path>]
|
|
23
|
+
taskset task show <task-id> [--json] [--cwd <path>]
|
|
24
|
+
|
|
25
|
+
Create options:
|
|
26
|
+
--status <status>
|
|
27
|
+
--priority <priority>
|
|
28
|
+
--label <label> Repeatable
|
|
29
|
+
--depends-on <task-id> Repeatable
|
|
30
|
+
--file <path> Repeatable
|
|
31
|
+
--body <markdown>
|
|
32
|
+
`
|
|
33
|
+
|
|
34
|
+
export interface CliContext {
|
|
35
|
+
readonly cwd?: string
|
|
36
|
+
readonly stderr?: (value: string) => void
|
|
37
|
+
readonly stdout?: (value: string) => void
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
class CliUsageError extends Error {
|
|
41
|
+
constructor(message: string) {
|
|
42
|
+
super(message)
|
|
43
|
+
this.name = 'CliUsageError'
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function parseTaskStatus(value: string | undefined): TaskStatus | undefined {
|
|
48
|
+
if (value === undefined) {
|
|
49
|
+
return undefined
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!TASK_STATUSES.includes(value as TaskStatus)) {
|
|
53
|
+
throw new CliUsageError(`Invalid task status "${value}"`)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return value as TaskStatus
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function parseTaskPriority(value: string | undefined): TaskPriority | undefined {
|
|
60
|
+
if (value === undefined) {
|
|
61
|
+
return undefined
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!TASK_PRIORITIES.includes(value as TaskPriority)) {
|
|
65
|
+
throw new CliUsageError(`Invalid task priority "${value}"`)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return value as TaskPriority
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function resolveCommandCwd(baseDirectory: string, cwdOption: string | undefined): string {
|
|
72
|
+
return cwdOption ? path.resolve(baseDirectory, cwdOption) : baseDirectory
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function parseCommonOptions(args: readonly string[]) {
|
|
76
|
+
return parseArgs({
|
|
77
|
+
args,
|
|
78
|
+
allowPositionals: false,
|
|
79
|
+
options: {
|
|
80
|
+
cwd: { type: 'string' },
|
|
81
|
+
json: { type: 'boolean' },
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function requireSinglePositional(positionals: readonly string[], name: string): string {
|
|
87
|
+
if (positionals.length !== 1 || !positionals[0]) {
|
|
88
|
+
throw new CliUsageError(`Expected exactly one ${name}`)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return positionals[0]
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function formatError(error: unknown): string {
|
|
95
|
+
if (!(error instanceof Error)) {
|
|
96
|
+
return 'Unknown Taskset error'
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const issues =
|
|
100
|
+
'issues' in error && Array.isArray(error.issues)
|
|
101
|
+
? error.issues
|
|
102
|
+
.map((issue) =>
|
|
103
|
+
typeof issue === 'object' && issue !== null && 'field' in issue && 'message' in issue
|
|
104
|
+
? `\n ${String(issue.field)}: ${String(issue.message)}`
|
|
105
|
+
: '',
|
|
106
|
+
)
|
|
107
|
+
.join('')
|
|
108
|
+
: ''
|
|
109
|
+
|
|
110
|
+
return `${error.message}${issues}`
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function runCli(args: readonly string[], context: CliContext = {}): Promise<number> {
|
|
114
|
+
const cwd = path.resolve(context.cwd ?? process.cwd())
|
|
115
|
+
const stdout = context.stdout ?? ((value: string) => process.stdout.write(value))
|
|
116
|
+
const stderr = context.stderr ?? ((value: string) => process.stderr.write(value))
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
const [command, subcommand] = args
|
|
120
|
+
const commandArgs = args.slice(1)
|
|
121
|
+
const taskArgs = args.slice(2)
|
|
122
|
+
|
|
123
|
+
if (!command || command === 'help' || command === '--help' || command === '-h') {
|
|
124
|
+
stdout(USAGE)
|
|
125
|
+
return 0
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (command === 'init') {
|
|
129
|
+
const parsed = parseCommonOptions(commandArgs)
|
|
130
|
+
const repository = await initializeRepository(resolveCommandCwd(cwd, parsed.values.cwd))
|
|
131
|
+
stdout(`Initialized Taskset in ${repository.rootDirectory}\n`)
|
|
132
|
+
return 0
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (command === 'config') {
|
|
136
|
+
const parsed = parseCommonOptions(commandArgs)
|
|
137
|
+
const repository = await discoverRepository(resolveCommandCwd(cwd, parsed.values.cwd))
|
|
138
|
+
|
|
139
|
+
if (parsed.values.json) {
|
|
140
|
+
stdout(
|
|
141
|
+
`${JSON.stringify(
|
|
142
|
+
{
|
|
143
|
+
rootDirectory: repository.rootDirectory,
|
|
144
|
+
configPath: repository.configPath,
|
|
145
|
+
dataDirectory: repository.dataDirectory,
|
|
146
|
+
config: repository.config,
|
|
147
|
+
},
|
|
148
|
+
null,
|
|
149
|
+
2,
|
|
150
|
+
)}\n`,
|
|
151
|
+
)
|
|
152
|
+
} else {
|
|
153
|
+
stdout(`${repository.configPath}\n`)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return 0
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (command !== 'task') {
|
|
160
|
+
throw new CliUsageError(`Unknown command "${command}"`)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (subcommand === 'create') {
|
|
164
|
+
const parsed = parseArgs({
|
|
165
|
+
args: taskArgs,
|
|
166
|
+
allowPositionals: false,
|
|
167
|
+
options: {
|
|
168
|
+
body: { type: 'string' },
|
|
169
|
+
cwd: { type: 'string' },
|
|
170
|
+
'depends-on': { type: 'string', multiple: true },
|
|
171
|
+
file: { type: 'string', multiple: true },
|
|
172
|
+
json: { type: 'boolean' },
|
|
173
|
+
label: { type: 'string', multiple: true },
|
|
174
|
+
priority: { type: 'string' },
|
|
175
|
+
status: { type: 'string' },
|
|
176
|
+
title: { type: 'string' },
|
|
177
|
+
},
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
if (!parsed.values.title) {
|
|
181
|
+
throw new CliUsageError('The --title option is required')
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const status = parseTaskStatus(parsed.values.status)
|
|
185
|
+
const priority = parseTaskPriority(parsed.values.priority)
|
|
186
|
+
|
|
187
|
+
const repository = await discoverRepository(resolveCommandCwd(cwd, parsed.values.cwd))
|
|
188
|
+
const record = await createTask(repository, {
|
|
189
|
+
title: parsed.values.title,
|
|
190
|
+
...(status ? { status } : {}),
|
|
191
|
+
...(priority ? { priority } : {}),
|
|
192
|
+
...(parsed.values.label ? { labels: parsed.values.label } : {}),
|
|
193
|
+
...(parsed.values['depends-on'] ? { dependsOn: parsed.values['depends-on'] } : {}),
|
|
194
|
+
...(parsed.values.file ? { files: parsed.values.file } : {}),
|
|
195
|
+
...(parsed.values.body !== undefined ? { body: parsed.values.body } : {}),
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
if (parsed.values.json) {
|
|
199
|
+
stdout(
|
|
200
|
+
`${JSON.stringify(
|
|
201
|
+
{ relativePath: record.relativePath, ...record.task.metadata },
|
|
202
|
+
null,
|
|
203
|
+
2,
|
|
204
|
+
)}\n`,
|
|
205
|
+
)
|
|
206
|
+
} else {
|
|
207
|
+
stdout(`${record.task.metadata.id}\n`)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return 0
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (subcommand === 'list') {
|
|
214
|
+
const parsed = parseCommonOptions(taskArgs)
|
|
215
|
+
const repository = await discoverRepository(resolveCommandCwd(cwd, parsed.values.cwd))
|
|
216
|
+
const records = await listTasks(repository)
|
|
217
|
+
|
|
218
|
+
if (parsed.values.json) {
|
|
219
|
+
stdout(
|
|
220
|
+
`${JSON.stringify(
|
|
221
|
+
records.map((record) => ({
|
|
222
|
+
relativePath: record.relativePath,
|
|
223
|
+
...record.task.metadata,
|
|
224
|
+
})),
|
|
225
|
+
null,
|
|
226
|
+
2,
|
|
227
|
+
)}\n`,
|
|
228
|
+
)
|
|
229
|
+
} else {
|
|
230
|
+
for (const record of records) {
|
|
231
|
+
stdout(
|
|
232
|
+
`${record.task.metadata.id}\t${record.task.metadata.status}\t${record.task.metadata.title}\n`,
|
|
233
|
+
)
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return 0
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (subcommand === 'show') {
|
|
241
|
+
const parsed = parseArgs({
|
|
242
|
+
args: taskArgs,
|
|
243
|
+
allowPositionals: true,
|
|
244
|
+
options: {
|
|
245
|
+
cwd: { type: 'string' },
|
|
246
|
+
json: { type: 'boolean' },
|
|
247
|
+
},
|
|
248
|
+
})
|
|
249
|
+
const taskId = requireSinglePositional(parsed.positionals, 'task ID')
|
|
250
|
+
const repository = await discoverRepository(resolveCommandCwd(cwd, parsed.values.cwd))
|
|
251
|
+
const record = await readTask(repository, taskId)
|
|
252
|
+
|
|
253
|
+
if (parsed.values.json) {
|
|
254
|
+
stdout(
|
|
255
|
+
`${JSON.stringify(
|
|
256
|
+
{
|
|
257
|
+
relativePath: record.relativePath,
|
|
258
|
+
metadata: record.task.metadata,
|
|
259
|
+
body: record.task.body,
|
|
260
|
+
},
|
|
261
|
+
null,
|
|
262
|
+
2,
|
|
263
|
+
)}\n`,
|
|
264
|
+
)
|
|
265
|
+
} else {
|
|
266
|
+
stdout(serializeTaskFile(record.task, { filePath: record.relativePath }))
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return 0
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
throw new CliUsageError(`Unknown task command "${subcommand ?? ''}"`)
|
|
273
|
+
} catch (error) {
|
|
274
|
+
if (error instanceof CliUsageError || error instanceof TypeError) {
|
|
275
|
+
stderr(`${formatError(error)}\n\n${USAGE}`)
|
|
276
|
+
return 2
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
stderr(`${formatError(error)}\n`)
|
|
280
|
+
return 1
|
|
281
|
+
}
|
|
282
|
+
}
|
package/src/index.ts
ADDED