@shortcut-cli/shortcut-cli 3.4.0 → 3.5.0

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/README.md CHANGED
@@ -18,6 +18,7 @@ This is a community-driven command line interface for [Shortcut](https://shortcu
18
18
  - [Epics](#epics)
19
19
  - [Workflows](#workflows)
20
20
  - [Projects](#projects)
21
+ - [API](#api)
21
22
  - [Development](#development)
22
23
  - [Acknowledgments](#acknowledgments)
23
24
 
@@ -74,6 +75,7 @@ SHORTCUT_API_TOKEN=foobar short story 3300
74
75
  epics list epics and their states
75
76
  projects list or search projects
76
77
  workspace list stories matching saved workspace query
78
+ api make a request to the Shortcut API
77
79
  help [cmd] display help for [cmd]
78
80
  ```
79
81
 
@@ -354,6 +356,29 @@ Templating variables:
354
356
  -h, --help output usage information
355
357
  ```
356
358
 
359
+ ### API
360
+
361
+ ```
362
+ Usage: short api <path> [options]
363
+
364
+ Make a request to the Shortcut API.
365
+
366
+
367
+ Options:
368
+
369
+ -X, --method <method> The HTTP method to use. (default: "GET")
370
+ -H, --header <header> Add a header to the request (e.g., "Content-Type: application/json"). Can be specified multiple times.
371
+ -f, --raw-field <key=value> Add a string parameter. Can be specified multiple times.
372
+ -h, --help output usage information
373
+
374
+
375
+ Examples:
376
+ $ short api /search/iterations -f page_size=10 -f query=123
377
+ $ short api /stories -X POST -f 'name=My new story' -f project_id=123
378
+ # jq can be used to shorten the response output.
379
+ $ short api /search/iterations -f page_size=10 -f query=123 | jq '.data[] | {id, name}'
380
+ ```
381
+
357
382
  ## Development
358
383
 
359
384
  You can use TypeScript watcher which will recompile your code automatically:
@@ -0,0 +1,25 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+
25
+ exports.__toESM = __toESM;
@@ -0,0 +1,78 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
2
+ const require_lib_spinner = require('../lib/spinner.js');
3
+ const require_lib_client = require('../lib/client.js');
4
+ const commander = require_rolldown_runtime.__toESM(require("commander"));
5
+ const debug = require_rolldown_runtime.__toESM(require("debug"));
6
+
7
+ //#region src/bin/short-api.ts
8
+ const debug$1 = (0, debug.default)("short-api");
9
+ const log = console.log;
10
+ const logError = console.error;
11
+ const spin = require_lib_spinner.default();
12
+ const parseKeyVal = (input, separator = "=") => {
13
+ const parts = input.split(separator);
14
+ const key = parts.shift();
15
+ const value = parts.join(separator);
16
+ return [key, value];
17
+ };
18
+ const collect = (val, memo) => {
19
+ memo.push(val);
20
+ return memo;
21
+ };
22
+ const program = commander.default.description("Make a request to the Shortcut API.").arguments("<path>").option("-X, --method <method>", "The HTTP method to use.", "GET").option("-H, --header <header>", "Add a header to the request (e.g., \"Content-Type: application/json\"). Can be specified multiple times.", collect, []).option("-f, --raw-field <key=value>", "Add a string parameter. Can be specified multiple times.", collect, []).on("--help", () => {
23
+ log("");
24
+ log("Examples:");
25
+ log(` $ short api /search/iterations -f page_size=10 -f query=123`);
26
+ log(` $ short api /stories -X POST -f 'name=My new story' -f project_id=123`);
27
+ log(" # jq can be used to shorten the response output.");
28
+ log(` $ short api /search/iterations -f page_size=10 -f query=123 | jq '.data[] | {id, name}'`);
29
+ }).parse(process.argv);
30
+ const main = async () => {
31
+ const [path] = program.args;
32
+ if (!path) {
33
+ logError("Error path argument is required");
34
+ program.help();
35
+ process.exit(1);
36
+ }
37
+ const method = (program.method || "GET").toUpperCase();
38
+ const headers = {};
39
+ const params = {};
40
+ if (program.header) program.header.forEach((h) => {
41
+ const [key, value] = parseKeyVal(h, ":");
42
+ headers[key] = value;
43
+ debug$1(`adding header: ${key}: ${value}`);
44
+ });
45
+ if (program.rawField) program.rawField.forEach((f) => {
46
+ const [key, value] = parseKeyVal(f);
47
+ params[key] = value;
48
+ debug$1(`adding raw field: ${key}: ${value}`);
49
+ });
50
+ const requestOptions = {
51
+ path: "/api/v3" + (path.startsWith("/") ? "" : "/") + path,
52
+ method,
53
+ headers
54
+ };
55
+ const bodyMethods = [
56
+ "POST",
57
+ "PUT",
58
+ "PATCH"
59
+ ];
60
+ if (bodyMethods.includes(method)) {
61
+ requestOptions.body = params;
62
+ if (!headers["Content-Type"]) headers["Content-Type"] = "application/json";
63
+ } else requestOptions.query = params;
64
+ try {
65
+ debug$1("request options:", requestOptions);
66
+ spin.start();
67
+ const response = await require_lib_client.default.request(requestOptions);
68
+ spin.stop(true);
69
+ log(JSON.stringify(response.data, null, 2));
70
+ } catch (err) {
71
+ spin.stop(true);
72
+ logError("Error calling API:", err.response ? JSON.stringify(err.response.data, null, 2) : err.message);
73
+ process.exit(1);
74
+ }
75
+ };
76
+ main();
77
+
78
+ //#endregion