azdo-cli 0.2.0-develop.97 → 0.2.0-develop.98

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.
Files changed (3) hide show
  1. package/README.md +13 -0
  2. package/dist/index.js +68 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -16,6 +16,7 @@ Azure DevOps CLI focused on work item read/write workflows.
16
16
  - Read rich-text fields as markdown (`get-md-field`)
17
17
  - Set rich-text fields as markdown from inline text, file, or stdin (`set-md-field`)
18
18
  - Persist org/project/default fields in local config (`config`)
19
+ - List all fields of a work item (`list-fields`)
19
20
  - Store PAT in OS credential store (or use `AZDO_PAT`)
20
21
 
21
22
  ## Installation
@@ -64,6 +65,7 @@ azdo upsert --content $'---\nTitle: Improve markdown import UX\nState: New\n---'
64
65
  | `azdo upsert [id]` | Create or update a Task from markdown | `--content`, `--file`, `--json`, `--org`, `--project` |
65
66
  | `azdo get-md-field <id> <field>` | Get field as markdown | `--org`, `--project` |
66
67
  | `azdo set-md-field <id> <field> [content]` | Set markdown field | `--file`, `--json`, `--org`, `--project` |
68
+ | `azdo list-fields <id>` | List all fields of a work item | `--json`, `--org`, `--project` |
67
69
  | `azdo config <subcommand>` | Manage saved settings | `set`, `get`, `list`, `unset`, `wizard`, `--json` |
68
70
  | `azdo clear-pat` | Remove stored PAT | none |
69
71
 
@@ -100,6 +102,16 @@ azdo assign 12345 --unassign
100
102
  azdo set-field 12345 System.Title "Updated title"
101
103
  ```
102
104
 
105
+ ### List Fields
106
+
107
+ ```bash
108
+ # List all fields of a work item
109
+ azdo list-fields 12345
110
+
111
+ # JSON output
112
+ azdo list-fields 12345 --json
113
+ ```
114
+
103
115
  ### Markdown Display
104
116
 
105
117
  The `get-item` command can convert HTML rich-text fields to readable markdown. Resolution order:
@@ -232,6 +244,7 @@ azdo clear-pat
232
244
  ## JSON Output
233
245
 
234
246
  These commands support `--json` for machine-readable output:
247
+ - `list-fields`
235
248
  - `set-state`
236
249
  - `assign`
237
250
  - `set-field`
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- import { Command as Command10 } from "commander";
4
+ import { Command as Command11 } from "commander";
5
5
 
6
6
  // src/version.ts
7
7
  import { readFileSync } from "fs";
@@ -92,6 +92,25 @@ async function readWriteResponse(response, errorCode) {
92
92
  fields: data.fields
93
93
  };
94
94
  }
95
+ async function getWorkItemFields(context, id, pat) {
96
+ const url = new URL(
97
+ `https://dev.azure.com/${encodeURIComponent(context.org)}/${encodeURIComponent(context.project)}/_apis/wit/workitems/${id}`
98
+ );
99
+ url.searchParams.set("api-version", "7.1");
100
+ url.searchParams.set("$expand", "all");
101
+ const response = await fetchWithErrors(url.toString(), { headers: authHeaders(pat) });
102
+ if (response.status === 400) {
103
+ const serverMessage = await readResponseMessage(response);
104
+ if (serverMessage) {
105
+ throw new Error(`BAD_REQUEST: ${serverMessage}`);
106
+ }
107
+ }
108
+ if (!response.ok) {
109
+ throw new Error(`HTTP_${response.status}`);
110
+ }
111
+ const data = await response.json();
112
+ return data.fields;
113
+ }
95
114
  async function getWorkItem(context, id, pat, extraFields) {
96
115
  const url = new URL(
97
116
  `https://dev.azure.com/${encodeURIComponent(context.org)}/${encodeURIComponent(context.project)}/_apis/wit/workitems/${id}`
@@ -1422,8 +1441,54 @@ function createUpsertCommand() {
1422
1441
  return command;
1423
1442
  }
1424
1443
 
1444
+ // src/commands/list-fields.ts
1445
+ import { Command as Command10 } from "commander";
1446
+ function stringifyValue(value) {
1447
+ if (value === null || value === void 0) return "";
1448
+ if (typeof value === "object") return JSON.stringify(value);
1449
+ return String(value);
1450
+ }
1451
+ function formatFieldList(fields) {
1452
+ const entries = Object.entries(fields).sort(([a], [b]) => a.localeCompare(b));
1453
+ const maxKeyLen = Math.min(
1454
+ Math.max(...entries.map(([k]) => k.length)),
1455
+ 50
1456
+ );
1457
+ return entries.map(([key, value]) => {
1458
+ const display = stringifyValue(value);
1459
+ const truncated = display.length > 120 ? display.slice(0, 117) + "..." : display;
1460
+ return `${key.padEnd(maxKeyLen + 2)}${truncated}`;
1461
+ }).join("\n");
1462
+ }
1463
+ function createListFieldsCommand() {
1464
+ const command = new Command10("list-fields");
1465
+ command.description("List all fields of an Azure DevOps work item").argument("<id>", "work item ID").option("--org <org>", "Azure DevOps organization").option("--project <project>", "Azure DevOps project").option("--json", "output result as JSON").action(
1466
+ async (idStr, options) => {
1467
+ const id = parseWorkItemId(idStr);
1468
+ validateOrgProjectPair(options);
1469
+ let context;
1470
+ try {
1471
+ context = resolveContext(options);
1472
+ const credential = await resolvePat();
1473
+ const fields = await getWorkItemFields(context, id, credential.pat);
1474
+ if (options.json) {
1475
+ process.stdout.write(JSON.stringify({ id, fields }, null, 2) + "\n");
1476
+ } else {
1477
+ process.stdout.write(`Work Item ${id} \u2014 ${Object.keys(fields).length} fields
1478
+
1479
+ `);
1480
+ process.stdout.write(formatFieldList(fields) + "\n");
1481
+ }
1482
+ } catch (err) {
1483
+ handleCommandError(err, id, context, "read");
1484
+ }
1485
+ }
1486
+ );
1487
+ return command;
1488
+ }
1489
+
1425
1490
  // src/index.ts
1426
- var program = new Command10();
1491
+ var program = new Command11();
1427
1492
  program.name("azdo").description("Azure DevOps CLI tool").version(version, "-v, --version");
1428
1493
  program.addCommand(createGetItemCommand());
1429
1494
  program.addCommand(createClearPatCommand());
@@ -1434,6 +1499,7 @@ program.addCommand(createSetFieldCommand());
1434
1499
  program.addCommand(createGetMdFieldCommand());
1435
1500
  program.addCommand(createSetMdFieldCommand());
1436
1501
  program.addCommand(createUpsertCommand());
1502
+ program.addCommand(createListFieldsCommand());
1437
1503
  program.showHelpAfterError();
1438
1504
  program.parse();
1439
1505
  if (process.argv.length <= 2) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azdo-cli",
3
- "version": "0.2.0-develop.97",
3
+ "version": "0.2.0-develop.98",
4
4
  "description": "Azure DevOps CLI tool",
5
5
  "type": "module",
6
6
  "bin": {