tuturuuu 0.3.1 → 0.3.3

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.
@@ -4,46 +4,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.runCli = runCli;
7
- const node_util_1 = require("node:util");
8
7
  const package_json_1 = __importDefault(require("../../package.json"));
9
8
  const platform_1 = require("../platform");
9
+ const args_1 = require("./args");
10
10
  const auth_1 = require("./auth");
11
11
  const config_1 = require("./config");
12
+ const render_1 = require("./render");
13
+ const selection_1 = require("./selection");
12
14
  const update_1 = require("./update");
13
- function parseArgs(args) {
14
- const flags = {};
15
- const positionals = [];
16
- for (let i = 0; i < args.length; i++) {
17
- const arg = args[i];
18
- if (!arg.startsWith('--')) {
19
- positionals.push(arg);
20
- continue;
21
- }
22
- const [rawKey, inlineValue] = arg.slice(2).split(/=(.*)/su, 2);
23
- const key = rawKey || '';
24
- if (!key)
25
- continue;
26
- if (inlineValue !== undefined) {
27
- flags[key] = inlineValue;
28
- continue;
29
- }
30
- const next = args[i + 1];
31
- if (next && !next.startsWith('--')) {
32
- flags[key] = next;
33
- i += 1;
34
- continue;
35
- }
36
- flags[key] = true;
37
- }
38
- return { flags, positionals };
39
- }
40
- function getFlag(flags, key) {
41
- const value = flags[key];
42
- return typeof value === 'string' ? value : undefined;
43
- }
44
15
  function getWorkspaceId(config, flags) {
45
- const explicit = getFlag(flags, 'workspace') || getFlag(flags, 'ws');
46
- const workspaceId = explicit || config.currentWorkspaceId;
16
+ const explicit = (0, args_1.getFlag)(flags, 'workspace') || (0, args_1.getFlag)(flags, 'ws');
17
+ const workspaceId = explicit || config.currentWorkspaceId || 'personal';
47
18
  if (!workspaceId) {
48
19
  throw new Error('No workspace selected. Use --workspace or run `ttr workspaces use <id>`.');
49
20
  }
@@ -62,45 +33,49 @@ function getClient(config) {
62
33
  refreshToken: config.session.refreshToken,
63
34
  });
64
35
  }
65
- function render(data, json = false) {
66
- if (json) {
67
- process.stdout.write(`${JSON.stringify(data, null, 2)}\n`);
68
- return;
69
- }
70
- if (Array.isArray(data)) {
71
- console.table(data);
72
- return;
73
- }
74
- process.stdout.write(`${(0, node_util_1.inspect)(data, { colors: true, depth: 6 })}\n`);
75
- }
76
- function parseCsv(value) {
77
- return value
78
- ? value
79
- .split(',')
80
- .map((entry) => entry.trim())
81
- .filter(Boolean)
82
- : [];
83
- }
84
36
  async function saveSession(config, token) {
85
37
  const payload = await (0, auth_1.exchangeCliToken)({
86
38
  baseUrl: config.baseUrl,
87
39
  token,
88
40
  });
41
+ const session = {
42
+ accessToken: payload.session.access_token,
43
+ expiresAt: payload.session.expires_at,
44
+ refreshToken: payload.session.refresh_token,
45
+ tokenType: payload.session.token_type,
46
+ };
89
47
  const nextConfig = {
90
48
  ...config,
91
- session: {
92
- accessToken: payload.session.access_token,
93
- expiresAt: payload.session.expires_at,
94
- refreshToken: payload.session.refresh_token,
95
- tokenType: payload.session.token_type,
96
- },
49
+ currentBoardId: undefined,
50
+ currentLabelId: undefined,
51
+ currentListId: undefined,
52
+ currentProjectId: undefined,
53
+ currentTaskId: undefined,
54
+ currentWorkspaceId: 'personal',
55
+ session,
97
56
  };
98
57
  await (0, config_1.writeCliConfig)(nextConfig);
99
- process.stdout.write('Logged in with a dedicated Tuturuuu CLI session.\n');
58
+ const email = payload.email ??
59
+ (await new platform_1.TuturuuuUserClient({
60
+ accessToken: session.accessToken,
61
+ baseUrl: nextConfig.baseUrl,
62
+ refreshToken: session.refreshToken,
63
+ }).users
64
+ .profile()
65
+ .then((profile) => profile.email)
66
+ .catch(() => null));
67
+ process.stdout.write(`${[
68
+ email
69
+ ? `Logged in as ${email}.`
70
+ : 'Logged in with your Tuturuuu account.',
71
+ 'Session: Tuturuuu CLI',
72
+ 'Current workspace: personal',
73
+ `Config: ${(0, config_1.getDefaultConfigPath)()}`,
74
+ ].join('\n')}\n`);
100
75
  }
101
76
  async function login(flags, config) {
102
- config.baseUrl = (0, config_1.normalizeBaseUrl)(getFlag(flags, 'base-url') || config.baseUrl);
103
- const directToken = getFlag(flags, 'token');
77
+ config.baseUrl = (0, config_1.normalizeBaseUrl)((0, args_1.getFlag)(flags, 'base-url') || config.baseUrl);
78
+ const directToken = (0, args_1.getFlag)(flags, 'token');
104
79
  if (directToken) {
105
80
  await saveSession(config, directToken);
106
81
  return;
@@ -112,19 +87,26 @@ async function login(flags, config) {
112
87
  mode: 'copy',
113
88
  state,
114
89
  });
115
- process.stdout.write(`Open this URL and copy the CLI token:\n${url}\n`);
90
+ process.stdout.write(`Open this URL, copy the token, then paste it below:\n${url}\n`);
116
91
  await saveSession(config, await (0, auth_1.readTokenFromStdin)());
117
92
  return;
118
93
  }
119
94
  await saveSession(config, await (0, auth_1.receiveTokenFromBrowser)(config.baseUrl));
120
95
  }
121
96
  function getPayload(flags) {
122
- const payload = getFlag(flags, 'json-payload');
97
+ const payload = (0, args_1.getFlag)(flags, 'json-payload');
123
98
  return payload ? JSON.parse(payload) : {};
124
99
  }
125
100
  async function runCli(argv = process.argv.slice(2)) {
126
- const { flags, positionals } = parseArgs(argv);
127
- const [group, action, firstId] = positionals;
101
+ const { flags, positionals } = (0, args_1.parseArgs)(argv);
102
+ const [group, rawAction, rawFirstId] = positionals;
103
+ const relationshipAction = group === 'relationships' &&
104
+ rawAction &&
105
+ !['create', 'delete', 'list'].includes(rawAction)
106
+ ? 'list'
107
+ : undefined;
108
+ const action = relationshipAction || rawAction || (0, args_1.getDefaultAction)(group);
109
+ const firstId = relationshipAction ? rawAction : rawFirstId;
128
110
  const json = flags.json === true;
129
111
  if (!group || group === 'help' || flags.help) {
130
112
  process.stdout.write(`${[
@@ -135,13 +117,24 @@ async function runCli(argv = process.argv.slice(2)) {
135
117
  ' logout',
136
118
  ' whoami',
137
119
  ' config set-base-url <url>',
138
- ' workspaces list|use <id>',
139
- ' boards list|create|update|delete',
140
- ' lists list|create|update|delete',
141
- ' tasks list|get|create|update|delete|move|bulk',
142
- ' labels list|create',
143
- ' projects list|create|get|tasks',
144
- ' relationships list|create|delete',
120
+ ' workspaces [list]|use [id]',
121
+ ' boards [list]|use|create|update|delete',
122
+ ' lists [list]|use|create|update|delete --board <id>',
123
+ ' tasks [list]|use|get|create|update|delete|move|bulk',
124
+ ' labels [list]|use|create',
125
+ ' projects [list]|use|create|get|tasks',
126
+ ' relationships [list]|create|delete <task-id>',
127
+ '',
128
+ 'Selection:',
129
+ ' Omit an id on use/get/update/delete/move to pick with up/down/space/enter.',
130
+ ' The personal workspace is selected by default.',
131
+ '',
132
+ 'Task list filters:',
133
+ ' tasks open tasks only',
134
+ ' tasks --all include done and closed tasks',
135
+ ' tasks --done completed tasks',
136
+ ' tasks --closed closed tasks',
137
+ ' tasks --compact title, list, and workspace only',
145
138
  ].join('\n')}\n`);
146
139
  return;
147
140
  }
@@ -166,11 +159,42 @@ async function runCli(argv = process.argv.slice(2)) {
166
159
  return;
167
160
  }
168
161
  if (group === 'whoami') {
169
- render({
162
+ const loggedIn = !!config.session?.accessToken;
163
+ let profile = null;
164
+ let currentWorkspace = null;
165
+ let defaultWorkspace = null;
166
+ if (loggedIn) {
167
+ const client = getClient(config);
168
+ const currentWorkspaceId = config.currentWorkspaceId || 'personal';
169
+ const [loadedProfile, loadedDefaultWorkspace, workspaces] = await Promise.all([
170
+ client.users.profile(),
171
+ client.users.defaultWorkspace(),
172
+ client.workspaces.list(),
173
+ ]);
174
+ profile = loadedProfile;
175
+ defaultWorkspace = loadedDefaultWorkspace;
176
+ currentWorkspace = currentWorkspaceId
177
+ ? (workspaces.find((workspace) => workspace.id === currentWorkspaceId ||
178
+ (currentWorkspaceId === 'personal' && workspace.personal === true)) ?? {
179
+ id: currentWorkspaceId,
180
+ name: currentWorkspaceId,
181
+ })
182
+ : null;
183
+ }
184
+ (0, render_1.renderWhoami)({
170
185
  baseUrl: config.baseUrl,
171
- currentWorkspaceId: config.currentWorkspaceId,
172
- loggedIn: !!config.session?.accessToken,
186
+ configPath: (0, config_1.getDefaultConfigPath)(),
187
+ currentBoardId: config.currentBoardId,
188
+ currentLabelId: config.currentLabelId,
189
+ currentListId: config.currentListId,
190
+ currentProjectId: config.currentProjectId,
191
+ currentTaskId: config.currentTaskId,
192
+ currentWorkspace,
193
+ currentWorkspaceId: config.currentWorkspaceId || 'personal',
194
+ defaultWorkspace,
195
+ loggedIn,
173
196
  session: config.session ? 'Tuturuuu CLI' : null,
197
+ user: profile,
174
198
  }, json);
175
199
  return;
176
200
  }
@@ -182,170 +206,318 @@ async function runCli(argv = process.argv.slice(2)) {
182
206
  const client = getClient(config);
183
207
  if (group === 'workspaces') {
184
208
  if (action === 'list') {
185
- render(await client.workspaces.list(), json);
209
+ (0, render_1.render)(await client.workspaces.list(), {
210
+ currentWorkspaceId: config.currentWorkspaceId || 'personal',
211
+ group,
212
+ json,
213
+ });
186
214
  return;
187
215
  }
188
- if (action === 'use' && firstId) {
189
- await (0, config_1.writeCliConfig)({ ...config, currentWorkspaceId: firstId });
190
- process.stdout.write(`Current workspace set to ${firstId}\n`);
216
+ if (action === 'use') {
217
+ const workspace = firstId
218
+ ? null
219
+ : await (0, selection_1.chooseWorkspace)(client, config, json);
220
+ const nextWorkspaceId = workspace
221
+ ? (0, selection_1.getWorkspaceConfigId)(workspace)
222
+ : firstId;
223
+ if (!nextWorkspaceId)
224
+ throw new Error('Missing workspace id.');
225
+ config = {
226
+ ...config,
227
+ currentBoardId: undefined,
228
+ currentLabelId: undefined,
229
+ currentListId: undefined,
230
+ currentProjectId: undefined,
231
+ currentTaskId: undefined,
232
+ currentWorkspaceId: nextWorkspaceId,
233
+ };
234
+ await (0, config_1.writeCliConfig)(config);
235
+ process.stdout.write(`Current workspace set to ${nextWorkspaceId}\n`);
191
236
  return;
192
237
  }
193
238
  }
194
239
  const workspaceId = getWorkspaceId(config, flags);
195
240
  if (group === 'boards') {
196
241
  if (action === 'list') {
197
- render(await client.tasks.listBoards(workspaceId), json);
242
+ (0, render_1.render)(await client.tasks.listBoards(workspaceId), { group, json });
243
+ return;
244
+ }
245
+ if (action === 'use' || action === 'select') {
246
+ const board = firstId
247
+ ? { id: firstId }
248
+ : await (0, selection_1.chooseBoard)(client, workspaceId, config, json);
249
+ config = {
250
+ ...config,
251
+ currentBoardId: board.id,
252
+ currentListId: undefined,
253
+ currentTaskId: undefined,
254
+ };
255
+ await (0, config_1.writeCliConfig)(config);
256
+ process.stdout.write(`Current board set to ${board.id}\n`);
198
257
  return;
199
258
  }
200
259
  if (action === 'create') {
201
- render(await client.tasks.createBoard(workspaceId, {
202
- icon: (getFlag(flags, 'icon') || null),
203
- name: getFlag(flags, 'name') || 'Untitled Board',
204
- template_id: getFlag(flags, 'template-id'),
205
- }), json);
260
+ (0, render_1.render)(await client.tasks.createBoard(workspaceId, {
261
+ icon: ((0, args_1.getFlag)(flags, 'icon') || null),
262
+ name: (0, args_1.getFlag)(flags, 'name') || 'Untitled Board',
263
+ template_id: (0, args_1.getFlag)(flags, 'template-id'),
264
+ }), { group, json });
206
265
  return;
207
266
  }
208
- if (action === 'update' && firstId) {
209
- render(await client.tasks.updateBoard(workspaceId, firstId, getPayload(flags)), json);
267
+ if (action === 'update') {
268
+ const selection = firstId
269
+ ? { boardId: firstId, config }
270
+ : await (0, selection_1.selectBoardId)(client, config, workspaceId, flags, json);
271
+ config = selection.config;
272
+ (0, render_1.render)(await client.tasks.updateBoard(workspaceId, selection.boardId, getPayload(flags)), { group, json });
210
273
  return;
211
274
  }
212
- if (action === 'delete' && firstId) {
213
- render(await client.tasks.deleteBoard(workspaceId, firstId), json);
275
+ if (action === 'delete') {
276
+ const selection = firstId
277
+ ? { boardId: firstId, config }
278
+ : await (0, selection_1.selectBoardId)(client, config, workspaceId, flags, json);
279
+ config = {
280
+ ...selection.config,
281
+ currentBoardId: undefined,
282
+ currentListId: undefined,
283
+ currentTaskId: undefined,
284
+ };
285
+ await (0, config_1.writeCliConfig)(config);
286
+ (0, render_1.render)(await client.tasks.deleteBoard(workspaceId, selection.boardId), {
287
+ group,
288
+ json,
289
+ });
214
290
  return;
215
291
  }
216
292
  }
217
293
  if (group === 'lists') {
218
- const boardId = getFlag(flags, 'board') || getFlag(flags, 'board-id');
219
- if (!boardId)
220
- throw new Error('Missing --board.');
294
+ const boardSelection = await (0, selection_1.selectBoardId)(client, config, workspaceId, flags, json);
295
+ config = boardSelection.config;
296
+ const boardId = boardSelection.boardId;
221
297
  if (action === 'list') {
222
- render(await client.tasks.listLists(workspaceId, boardId), json);
298
+ (0, render_1.render)(await client.tasks.listLists(workspaceId, boardId), {
299
+ group,
300
+ json,
301
+ });
302
+ return;
303
+ }
304
+ if (action === 'use' || action === 'select') {
305
+ const list = firstId
306
+ ? { id: firstId }
307
+ : await (0, selection_1.chooseList)(client, workspaceId, boardId, config, json);
308
+ config = {
309
+ ...config,
310
+ currentBoardId: boardId,
311
+ currentListId: list.id,
312
+ currentTaskId: undefined,
313
+ };
314
+ await (0, config_1.writeCliConfig)(config);
315
+ process.stdout.write(`Current list set to ${list.id}\n`);
223
316
  return;
224
317
  }
225
318
  if (action === 'create') {
226
- render(await client.tasks.createList(workspaceId, boardId, {
227
- color: getFlag(flags, 'color'),
228
- name: getFlag(flags, 'name') || 'Untitled List',
229
- status: getFlag(flags, 'status'),
230
- }), json);
319
+ (0, render_1.render)(await client.tasks.createList(workspaceId, boardId, {
320
+ color: (0, args_1.getFlag)(flags, 'color'),
321
+ name: (0, args_1.getFlag)(flags, 'name') || 'Untitled List',
322
+ status: (0, args_1.getFlag)(flags, 'status'),
323
+ }), { group, json });
231
324
  return;
232
325
  }
233
- if (action === 'update' && firstId) {
234
- render(await client.tasks.updateList(workspaceId, boardId, firstId, getPayload(flags)), json);
326
+ if (action === 'update') {
327
+ const listSelection = firstId
328
+ ? { config, listId: firstId }
329
+ : await (0, selection_1.selectListId)(client, config, workspaceId, flags, json);
330
+ config = listSelection.config;
331
+ (0, render_1.render)(await client.tasks.updateList(workspaceId, boardId, listSelection.listId, getPayload(flags)), { group, json });
235
332
  return;
236
333
  }
237
334
  }
238
335
  if (group === 'tasks') {
239
336
  if (action === 'list') {
240
- render(await client.tasks.list(workspaceId, {
241
- boardId: getFlag(flags, 'board'),
337
+ const workspaceName = flags.compact === true
338
+ ? (0, selection_1.resolveWorkspaceName)(workspaceId, await client.workspaces.list())
339
+ : undefined;
340
+ (0, render_1.render)(await client.tasks.list(workspaceId, {
341
+ boardId: (0, args_1.getFlag)(flags, 'board') || config.currentBoardId,
342
+ ...(0, args_1.getTaskStateFilters)(flags),
242
343
  includeCount: flags.count === true,
243
344
  includeDeleted: flags.deleted === true,
244
- limit: getFlag(flags, 'limit')
245
- ? Number(getFlag(flags, 'limit'))
345
+ limit: (0, args_1.getFlag)(flags, 'limit')
346
+ ? Number((0, args_1.getFlag)(flags, 'limit'))
246
347
  : undefined,
247
- listId: getFlag(flags, 'list'),
248
- offset: getFlag(flags, 'offset')
249
- ? Number(getFlag(flags, 'offset'))
348
+ listId: (0, args_1.getFlag)(flags, 'list') || config.currentListId,
349
+ offset: (0, args_1.getFlag)(flags, 'offset')
350
+ ? Number((0, args_1.getFlag)(flags, 'offset'))
250
351
  : undefined,
251
- q: getFlag(flags, 'q'),
252
- }), json);
352
+ q: (0, args_1.getFlag)(flags, 'q'),
353
+ }), {
354
+ compact: flags.compact === true,
355
+ currentWorkspaceId: workspaceId,
356
+ group,
357
+ json,
358
+ workspaceName,
359
+ });
253
360
  return;
254
361
  }
255
- if (action === 'get' && firstId) {
256
- render(await client.tasks.get(workspaceId, firstId), json);
362
+ if (action === 'use' || action === 'select') {
363
+ const selection = await (0, selection_1.selectTaskId)(client, config, workspaceId, flags, json, firstId);
364
+ config = selection.config;
365
+ process.stdout.write(`Current task set to ${selection.taskId}\n`);
366
+ return;
367
+ }
368
+ if (action === 'get') {
369
+ const selection = await (0, selection_1.selectTaskId)(client, config, workspaceId, flags, json, firstId);
370
+ config = selection.config;
371
+ (0, render_1.render)(await client.tasks.get(workspaceId, selection.taskId), {
372
+ group,
373
+ json,
374
+ });
257
375
  return;
258
376
  }
259
377
  if (action === 'create') {
260
- const listId = getFlag(flags, 'list');
261
- if (!listId)
262
- throw new Error('Missing --list.');
263
- render(await client.tasks.create(workspaceId, {
264
- assignee_ids: parseCsv(getFlag(flags, 'assignees')),
265
- end_date: getFlag(flags, 'end-date') || null,
266
- label_ids: parseCsv(getFlag(flags, 'labels')),
267
- listId,
268
- name: getFlag(flags, 'name') || 'Untitled Task',
269
- priority: getFlag(flags, 'priority') || null,
270
- project_ids: parseCsv(getFlag(flags, 'projects')),
271
- start_date: getFlag(flags, 'start-date') || null,
272
- }), json);
378
+ const listSelection = await (0, selection_1.selectListId)(client, config, workspaceId, flags, json);
379
+ config = listSelection.config;
380
+ (0, render_1.render)(await client.tasks.create(workspaceId, {
381
+ assignee_ids: (0, args_1.parseCsv)((0, args_1.getFlag)(flags, 'assignees')),
382
+ end_date: (0, args_1.getFlag)(flags, 'end-date') || null,
383
+ label_ids: (0, args_1.parseCsv)((0, args_1.getFlag)(flags, 'labels')),
384
+ listId: listSelection.listId,
385
+ name: (0, args_1.getFlag)(flags, 'name') || 'Untitled Task',
386
+ priority: (0, args_1.getFlag)(flags, 'priority') || null,
387
+ project_ids: (0, args_1.parseCsv)((0, args_1.getFlag)(flags, 'projects')),
388
+ start_date: (0, args_1.getFlag)(flags, 'start-date') || null,
389
+ }), { group, json });
273
390
  return;
274
391
  }
275
- if (action === 'update' && firstId) {
276
- render(await client.tasks.update(workspaceId, firstId, getPayload(flags)), json);
392
+ if (action === 'update') {
393
+ const selection = await (0, selection_1.selectTaskId)(client, config, workspaceId, flags, json, firstId);
394
+ config = selection.config;
395
+ (0, render_1.render)(await client.tasks.update(workspaceId, selection.taskId, getPayload(flags)), { group, json });
277
396
  return;
278
397
  }
279
- if (action === 'delete' && firstId) {
280
- render(await client.tasks.delete(workspaceId, firstId), json);
398
+ if (action === 'delete') {
399
+ const selection = await (0, selection_1.selectTaskId)(client, config, workspaceId, flags, json, firstId);
400
+ config = { ...selection.config, currentTaskId: undefined };
401
+ await (0, config_1.writeCliConfig)(config);
402
+ (0, render_1.render)(await client.tasks.delete(workspaceId, selection.taskId), {
403
+ group,
404
+ json,
405
+ });
281
406
  return;
282
407
  }
283
- if (action === 'move' && firstId) {
284
- const listId = getFlag(flags, 'list');
285
- if (!listId)
286
- throw new Error('Missing --list.');
287
- render(await client.tasks.move(workspaceId, firstId, {
288
- list_id: listId,
289
- target_board_id: getFlag(flags, 'target-board'),
290
- }), json);
408
+ if (action === 'move') {
409
+ const taskSelection = await (0, selection_1.selectTaskId)(client, config, workspaceId, flags, json, firstId);
410
+ config = taskSelection.config;
411
+ const targetFlags = { ...flags };
412
+ const targetBoardId = (0, args_1.getFlag)(flags, 'target-board') || (0, args_1.getFlag)(flags, 'board');
413
+ const targetListId = (0, args_1.getFlag)(flags, 'list');
414
+ if (targetBoardId) {
415
+ targetFlags.board = targetBoardId;
416
+ }
417
+ if (targetListId) {
418
+ targetFlags.list = targetListId;
419
+ }
420
+ const listSelection = await (0, selection_1.selectListId)(client, config, workspaceId, targetFlags, json);
421
+ config = listSelection.config;
422
+ (0, render_1.render)(await client.tasks.move(workspaceId, taskSelection.taskId, {
423
+ list_id: listSelection.listId,
424
+ target_board_id: (0, args_1.getFlag)(flags, 'target-board'),
425
+ }), { group, json });
291
426
  return;
292
427
  }
293
428
  if (action === 'bulk') {
294
- render(await client.tasks.bulk(workspaceId, {
429
+ (0, render_1.render)(await client.tasks.bulk(workspaceId, {
295
430
  operation: getPayload(flags),
296
- taskIds: parseCsv(getFlag(flags, 'ids')),
297
- }), json);
431
+ taskIds: (0, args_1.parseCsv)((0, args_1.getFlag)(flags, 'ids')),
432
+ }), { group, json });
298
433
  return;
299
434
  }
300
435
  }
301
436
  if (group === 'labels') {
302
437
  if (action === 'list') {
303
- render(await client.tasks.listLabels(workspaceId), json);
438
+ (0, render_1.render)(await client.tasks.listLabels(workspaceId), { group, json });
439
+ return;
440
+ }
441
+ if (action === 'use' || action === 'select') {
442
+ const label = firstId
443
+ ? { id: firstId }
444
+ : await (0, selection_1.chooseLabel)(client, workspaceId, config, json);
445
+ config = { ...config, currentLabelId: label.id };
446
+ await (0, config_1.writeCliConfig)(config);
447
+ process.stdout.write(`Current label set to ${label.id}\n`);
304
448
  return;
305
449
  }
306
450
  if (action === 'create') {
307
- render(await client.tasks.createLabel(workspaceId, {
308
- color: getFlag(flags, 'color') || 'gray',
309
- name: getFlag(flags, 'name') || 'Untitled Label',
310
- }), json);
451
+ (0, render_1.render)(await client.tasks.createLabel(workspaceId, {
452
+ color: (0, args_1.getFlag)(flags, 'color') || 'gray',
453
+ name: (0, args_1.getFlag)(flags, 'name') || 'Untitled Label',
454
+ }), { group, json });
311
455
  return;
312
456
  }
313
457
  }
314
458
  if (group === 'projects') {
315
459
  if (action === 'list') {
316
- render(await client.tasks.listProjects(workspaceId), json);
460
+ (0, render_1.render)(await client.tasks.listProjects(workspaceId), { group, json });
461
+ return;
462
+ }
463
+ if (action === 'use' || action === 'select') {
464
+ const project = firstId
465
+ ? { id: firstId }
466
+ : await (0, selection_1.chooseProject)(client, workspaceId, config, json);
467
+ config = { ...config, currentProjectId: project.id };
468
+ await (0, config_1.writeCliConfig)(config);
469
+ process.stdout.write(`Current project set to ${project.id}\n`);
317
470
  return;
318
471
  }
319
472
  if (action === 'create') {
320
- render(await client.tasks.createProject(workspaceId, {
321
- description: getFlag(flags, 'description'),
322
- name: getFlag(flags, 'name') || 'Untitled Project',
323
- }), json);
473
+ (0, render_1.render)(await client.tasks.createProject(workspaceId, {
474
+ description: (0, args_1.getFlag)(flags, 'description'),
475
+ name: (0, args_1.getFlag)(flags, 'name') || 'Untitled Project',
476
+ }), { group, json });
324
477
  return;
325
478
  }
326
- if (action === 'get' && firstId) {
327
- render(await client.tasks.getProject(workspaceId, firstId), json);
479
+ if (action === 'get') {
480
+ const projectId = firstId ||
481
+ config.currentProjectId ||
482
+ (await (0, selection_1.chooseProject)(client, workspaceId, config, json)).id;
483
+ config = { ...config, currentProjectId: projectId };
484
+ await (0, config_1.writeCliConfig)(config);
485
+ (0, render_1.render)(await client.tasks.getProject(workspaceId, projectId), {
486
+ group,
487
+ json,
488
+ });
328
489
  return;
329
490
  }
330
- if (action === 'tasks' && firstId) {
331
- render(await client.tasks.getProjectTasks(workspaceId, firstId), json);
491
+ if (action === 'tasks') {
492
+ const projectId = firstId ||
493
+ config.currentProjectId ||
494
+ (await (0, selection_1.chooseProject)(client, workspaceId, config, json)).id;
495
+ config = { ...config, currentProjectId: projectId };
496
+ await (0, config_1.writeCliConfig)(config);
497
+ (0, render_1.render)(await client.tasks.getProjectTasks(workspaceId, projectId), {
498
+ group,
499
+ json,
500
+ });
332
501
  return;
333
502
  }
334
503
  }
335
504
  if (group === 'relationships') {
336
- const taskId = firstId || getFlag(flags, 'task');
337
- if (!taskId)
338
- throw new Error('Missing task id.');
505
+ const taskSelection = await (0, selection_1.selectTaskId)(client, config, workspaceId, flags, json, firstId || (0, args_1.getFlag)(flags, 'task'));
506
+ config = taskSelection.config;
507
+ const taskId = taskSelection.taskId;
339
508
  if (action === 'list') {
340
- render(await client.tasks.getRelationships(workspaceId, taskId), json);
509
+ (0, render_1.render)(await client.tasks.getRelationships(workspaceId, taskId), {
510
+ group,
511
+ json,
512
+ });
341
513
  return;
342
514
  }
343
515
  if (action === 'create') {
344
- render(await client.tasks.createRelationship(workspaceId, taskId, getPayload(flags)), json);
516
+ (0, render_1.render)(await client.tasks.createRelationship(workspaceId, taskId, getPayload(flags)), { group, json });
345
517
  return;
346
518
  }
347
519
  if (action === 'delete') {
348
- render(await client.tasks.deleteRelationship(workspaceId, taskId, getPayload(flags)), json);
520
+ (0, render_1.render)(await client.tasks.deleteRelationship(workspaceId, taskId, getPayload(flags)), { group, json });
349
521
  return;
350
522
  }
351
523
  }