@atlaskit/ads-cli 0.6.0 → 0.7.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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @atlaskit/ads-cli
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`70516acb1b138`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/70516acb1b138) -
8
+ Support complete-string child requests in `ads-cli batch` while preserving the canonical tokenized
9
+ form.
10
+
11
+ ```sh
12
+ # Canonical tokenized form
13
+ npx @atlaskit/ads-cli batch --command component "Inline Dialog"
14
+
15
+ # Complete-string compatibility form
16
+ npx @atlaskit/ads-cli batch --command 'component "Inline Dialog"'
17
+ ```
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies
22
+
3
23
  ## 0.6.0
4
24
 
5
25
  ### Minor Changes
package/README.md CHANGED
@@ -24,7 +24,7 @@ The CLI has these commands:
24
24
  | Command | Description |
25
25
  | ---------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
26
26
  | `search <query...>` | **Unified** fuzzy-search across components, tokens, icons, and foundations docs at once. Narrow results with `--type component\|token\|icon\|docs`; limit with `--limit N`. |
27
- | `batch --command <command> [args...]...` | Run multiple ADS CLI queries, including different command types, in one process. Repeat `--command` once per child; each keeps its normal arguments, flags, and response envelope. |
27
+ | `batch --command <command> [args...]...` | Run multiple ADS CLI queries, including different command types, in one process. Repeat `--command` once per child; each keeps its normal arguments, flags, and response envelope. Tokenized requests are canonical; complete quoted requests are also accepted. |
28
28
  | `component <name>` | Detail for a single component. Exact name → detail; ambiguous → a "did you mean?" list. `--all` lists every component. |
29
29
  | `token <name>` | Detail for a single token. Exact name → detail; ambiguous → a "did you mean?" list. `--all` lists every token. |
30
30
  | `icon <name>` | Detail for a single icon (with a copy-paste import). Exact name → detail; ambiguous → a "did you mean?" list. `--all` lists every icon. |
@@ -55,6 +55,11 @@ npx @atlaskit/ads-cli batch \
55
55
  --command docs spacing \
56
56
  --command search contrast --type docs
57
57
 
58
+ # Complete-string compatibility form (tokenized input above remains canonical)
59
+ npx @atlaskit/ads-cli batch \
60
+ --command 'component "Inline Dialog"' \
61
+ --command "search contrast" --type docs
62
+
58
63
  # Detail for a single component, token, or icon
59
64
  npx @atlaskit/ads-cli component Avatar
60
65
  npx @atlaskit/ads-cli token space.100
@@ -92,12 +97,16 @@ npx @atlaskit/ads-cli manifest --json
92
97
  is no exact match but several candidates, they print a `Did you mean?` list (each with a
93
98
  `→ ads-cli <command>` follow-up) and exit `0` — under `--json` this is
94
99
  `{ "ambiguous": true, "query", "noun", "candidates": [...] }`.
95
- - **Batch commands are independent.** Each repeated `--command` starts a tokenized child request;
96
- `batch` runs those commands concurrently through the existing command registry in one CLI process.
97
- Each item includes its original tokenized `request`, a `status` (`success`, `ambiguous`, or
98
- `failure`), and the child command's unchanged success or error `response` envelope. A failed or
99
- ambiguous child does not discard successful sibling results. A syntactically valid batch exits
100
- `0`; inspect each item's status or nested envelope.
100
+ - **Batch commands are independent.** Each repeated `--command` starts a child request. Passing its
101
+ command and arguments as separate, tokenized argv is the canonical form. A complete quoted request
102
+ is also accepted, including inner quoting and already-tokenized trailing flags; it is normalized
103
+ to argv without invoking a shell. Shell operators, pipes, redirects, environment expansion, and
104
+ command substitution are rejected with a usage error. `batch` runs valid commands concurrently
105
+ through the existing command registry in one CLI process. Each item includes its normalized
106
+ tokenized `request`, a `status` (`success`, `ambiguous`, or `failure`), and the child command's
107
+ unchanged success or error `response` envelope. A failed or ambiguous child does not discard
108
+ successful sibling results. A syntactically valid batch exits `0`; inspect each item's status or
109
+ nested envelope.
101
110
  - **Data is written to stdout only.** Logs, hints, and errors go to **stderr**. This keeps `--json`
102
111
  output clean for piping. `batch` is the one deliberate exception: a child's failure is part of the
103
112
  aggregate result rather than a failure of the batch itself, so per-child errors stay inline on
package/dist/cjs/cli.js CHANGED
@@ -72,7 +72,10 @@ var buildHelpText = function buildHelpText(invocation) {
72
72
  comment: 'unified: components, tokens, icons & docs'
73
73
  }, {
74
74
  command: 'batch --command search button --type icon --command token space.200',
75
- comment: 'independent commands in one process'
75
+ comment: 'canonical tokenized batch form'
76
+ }, {
77
+ command: 'batch --command "search button" --type icon --command "token space.200"',
78
+ comment: 'complete-string compatibility form'
76
79
  }, {
77
80
  command: 'search button --type component'
78
81
  }, {
@@ -23,6 +23,7 @@ var _formatToken = require("../output/format-token");
23
23
  var _parseLintRuleRecords = require("../output/parse-lint-rule-records");
24
24
  var _buildManifest = require("./build-manifest");
25
25
  var _getVersion = require("./get-version");
26
+ var _normalizeBatchRequest = require("./normalize-batch-request");
26
27
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
27
28
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
28
29
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
@@ -471,9 +472,9 @@ var resolveUnifiedSearch = function resolveUnifiedSearch(input) {
471
472
  };
472
473
 
473
474
  /**
474
- * Split a batch invocation into argv groups introduced by repeated `--command` flags. The groups
475
- * remain tokenized, so child commands can be routed through the existing parser without evaluating
476
- * shell strings.
475
+ * Split a batch invocation into argv groups introduced by repeated `--command` flags. Canonical
476
+ * tokenized groups remain unchanged; a complete request in the first token is safely normalized
477
+ * to argv without evaluating shell strings.
477
478
  */
478
479
  var resolveBatch = function resolveBatch(input) {
479
480
  var _input$rawArgs;
@@ -508,9 +509,11 @@ var resolveBatch = function resolveBatch(input) {
508
509
  error: '`--command` must be followed by a non-empty command request.'
509
510
  };
510
511
  }
511
- requests.push({
512
- argv: current
513
- });
512
+ var _normalized = (0, _normalizeBatchRequest.normalizeBatchRequest)(current);
513
+ if ('error' in _normalized) {
514
+ return _normalized;
515
+ }
516
+ requests.push(_normalized);
514
517
  current = [];
515
518
  continue;
516
519
  }
@@ -526,9 +529,11 @@ var resolveBatch = function resolveBatch(input) {
526
529
  error: '`--command` must be followed by a non-empty command request.'
527
530
  };
528
531
  }
529
- requests.push({
530
- argv: current
531
- });
532
+ var normalized = (0, _normalizeBatchRequest.normalizeBatchRequest)(current);
533
+ if ('error' in normalized) {
534
+ return normalized;
535
+ }
536
+ requests.push(normalized);
532
537
  return {
533
538
  tools: [],
534
539
  batch: requests,
@@ -601,15 +606,15 @@ var commands = exports.commands = [{
601
606
  }
602
607
  }, {
603
608
  name: 'batch',
604
- description: 'Run multiple ADS CLI queries, including different command types, in one process.',
609
+ description: 'Run multiple ADS CLI queries in one process. Tokenized child requests are canonical; complete-request strings are also accepted.',
605
610
  usage: 'batch [--json] --command <command> [args...] [--command <command> [args...]]...',
606
611
  arguments: [],
607
612
  flags: [{
608
613
  name: 'command',
609
614
  type: 'string[]',
610
- description: 'A child command name followed by its arguments. Repeat once per child command.'
615
+ description: 'Canonical: a tokenized child command and its arguments. A complete quoted request is also accepted. Repeat once per child command.'
611
616
  }],
612
- examples: ['batch --command search button --type icon --command token space.200', 'batch --json --command component Button --command docs spacing'],
617
+ examples: ['batch --command search button --type icon --command token space.200', 'batch --command "search button" --type icon --command "token space.200"', 'batch --json --command component Button --command docs spacing'],
613
618
  responseTypes: ['ads-cli/batch'],
614
619
  envelopeType: function envelopeType() {
615
620
  return 'batch';
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.normalizeBatchRequest = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray"));
10
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
11
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
12
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
13
+ /**
14
+ * Normalise one batch child request without involving a shell.
15
+ *
16
+ * The canonical form is already-tokenized argv, for example
17
+ * `['search', 'Grid', '--type', 'component']`. For compatibility with agent-generated commands,
18
+ * the first token may instead contain a complete request, for example `['search Grid', '--type',
19
+ * 'component']`. Only that first token is split; trailing tokens have already been tokenized by the
20
+ * caller and must remain unchanged so multi-word arguments keep their boundaries.
21
+ */
22
+
23
+ var shellSyntaxError = function shellSyntaxError(syntax) {
24
+ return {
25
+ error: "Shell syntax ".concat(syntax, " is not supported in batch requests. Pass child commands as argv only; pipes, redirects, expansion, and command substitution are not allowed.")
26
+ };
27
+ };
28
+
29
+ /**
30
+ * Reject syntax that would have special meaning to a shell even though this parser never invokes
31
+ * one. Failing closed gives callers an actionable error instead of accepting input that only looks
32
+ * safe because it currently remains an argv array.
33
+ */
34
+ var findShellSyntax = function findShellSyntax(value) {
35
+ var _value$match;
36
+ if (value.includes('$(')) {
37
+ return 'command substitution (`$(...)`)';
38
+ }
39
+ if (value.includes('`')) {
40
+ return 'command substitution (backticks)';
41
+ }
42
+ if (value.includes('$')) {
43
+ return 'environment expansion (`$`)';
44
+ }
45
+ if (/\r|\n/.test(value)) {
46
+ return 'a command separator (line break)';
47
+ }
48
+ if (value.includes('&&')) {
49
+ return 'the `&&` operator';
50
+ }
51
+ if (value.includes('||')) {
52
+ return 'the `||` operator';
53
+ }
54
+ var operator = (_value$match = value.match(/[|&;<>()]/)) === null || _value$match === void 0 ? void 0 : _value$match[0];
55
+ return operator ? "the `".concat(operator, "` operator") : null;
56
+ };
57
+
58
+ /**
59
+ * Split a complete child request into argv using quoting and escaping rules only. This is
60
+ * intentionally not a shell grammar: it performs no expansion, substitution, redirection, or
61
+ * operator evaluation.
62
+ */
63
+ var tokenizeCompleteRequest = function tokenizeCompleteRequest(value) {
64
+ var argv = [];
65
+ var current = '';
66
+ var quote = null;
67
+ var escaped = false;
68
+ var tokenStarted = false;
69
+ var _iterator = _createForOfIteratorHelper(value),
70
+ _step;
71
+ try {
72
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
73
+ var character = _step.value;
74
+ if (escaped) {
75
+ current += character;
76
+ escaped = false;
77
+ tokenStarted = true;
78
+ continue;
79
+ }
80
+ if (character === '\\') {
81
+ escaped = true;
82
+ tokenStarted = true;
83
+ continue;
84
+ }
85
+ if (quote !== null) {
86
+ if (character === quote) {
87
+ quote = null;
88
+ } else {
89
+ current += character;
90
+ }
91
+ continue;
92
+ }
93
+ if (character === "'" || character === '"') {
94
+ quote = character;
95
+ tokenStarted = true;
96
+ continue;
97
+ }
98
+ if (/\s/.test(character)) {
99
+ if (tokenStarted) {
100
+ argv.push(current);
101
+ current = '';
102
+ tokenStarted = false;
103
+ }
104
+ continue;
105
+ }
106
+ current += character;
107
+ tokenStarted = true;
108
+ }
109
+ } catch (err) {
110
+ _iterator.e(err);
111
+ } finally {
112
+ _iterator.f();
113
+ }
114
+ if (escaped) {
115
+ return {
116
+ error: 'Invalid complete batch request: it ends with an escape character.'
117
+ };
118
+ }
119
+ if (quote !== null) {
120
+ return {
121
+ error: "Invalid complete batch request: unterminated ".concat(quote, " quote.")
122
+ };
123
+ }
124
+ if (tokenStarted) {
125
+ argv.push(current);
126
+ }
127
+ if (argv.length === 0) {
128
+ return {
129
+ error: 'Invalid complete batch request: a command name is required.'
130
+ };
131
+ }
132
+ return {
133
+ argv: argv
134
+ };
135
+ };
136
+ var normalizeBatchRequest = exports.normalizeBatchRequest = function normalizeBatchRequest(argv) {
137
+ var _iterator2 = _createForOfIteratorHelper(argv),
138
+ _step2;
139
+ try {
140
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
141
+ var token = _step2.value;
142
+ var syntax = findShellSyntax(token);
143
+ if (syntax !== null) {
144
+ return shellSyntaxError(syntax);
145
+ }
146
+ }
147
+ } catch (err) {
148
+ _iterator2.e(err);
149
+ } finally {
150
+ _iterator2.f();
151
+ }
152
+ var _argv = (0, _toArray2.default)(argv),
153
+ first = _argv[0],
154
+ trailing = _arrayLikeToArray(_argv).slice(1);
155
+ if (first === undefined) {
156
+ return {
157
+ error: '`--command` must be followed by a non-empty command request.'
158
+ };
159
+ }
160
+
161
+ // A normal command name cannot contain whitespace, quotes, or escapes. Their presence in the
162
+ // first argv entry therefore identifies the complete-string compatibility form. Tokenized
163
+ // trailing entries are never re-split.
164
+ if (!/[\s'"\\]/.test(first)) {
165
+ return {
166
+ argv: (0, _toConsumableArray2.default)(argv)
167
+ };
168
+ }
169
+ var normalized = tokenizeCompleteRequest(first);
170
+ if ('error' in normalized) {
171
+ return normalized;
172
+ }
173
+ return {
174
+ argv: [].concat((0, _toConsumableArray2.default)(normalized.argv), (0, _toConsumableArray2.default)(trailing))
175
+ };
176
+ };
@@ -56,7 +56,10 @@ const buildHelpText = invocation => {
56
56
  comment: 'unified: components, tokens, icons & docs'
57
57
  }, {
58
58
  command: 'batch --command search button --type icon --command token space.200',
59
- comment: 'independent commands in one process'
59
+ comment: 'canonical tokenized batch form'
60
+ }, {
61
+ command: 'batch --command "search button" --type icon --command "token space.200"',
62
+ comment: 'complete-string compatibility form'
60
63
  }, {
61
64
  command: 'search button --type component'
62
65
  }, {
@@ -28,6 +28,7 @@ import { formatToken } from '../output/format-token';
28
28
  import { parseLintRuleRecords } from '../output/parse-lint-rule-records';
29
29
  import { buildManifest } from './build-manifest';
30
30
  import { getVersion } from './get-version';
31
+ import { normalizeBatchRequest } from './normalize-batch-request';
31
32
  /**
32
33
  * Shared `--limit` flag definition reused across the search-style commands.
33
34
  */
@@ -446,9 +447,9 @@ const resolveUnifiedSearch = input => {
446
447
  };
447
448
 
448
449
  /**
449
- * Split a batch invocation into argv groups introduced by repeated `--command` flags. The groups
450
- * remain tokenized, so child commands can be routed through the existing parser without evaluating
451
- * shell strings.
450
+ * Split a batch invocation into argv groups introduced by repeated `--command` flags. Canonical
451
+ * tokenized groups remain unchanged; a complete request in the first token is safely normalized
452
+ * to argv without evaluating shell strings.
452
453
  */
453
454
  const resolveBatch = input => {
454
455
  var _input$rawArgs;
@@ -477,9 +478,11 @@ const resolveBatch = input => {
477
478
  error: '`--command` must be followed by a non-empty command request.'
478
479
  };
479
480
  }
480
- requests.push({
481
- argv: current
482
- });
481
+ const normalized = normalizeBatchRequest(current);
482
+ if ('error' in normalized) {
483
+ return normalized;
484
+ }
485
+ requests.push(normalized);
483
486
  current = [];
484
487
  continue;
485
488
  }
@@ -490,9 +493,11 @@ const resolveBatch = input => {
490
493
  error: '`--command` must be followed by a non-empty command request.'
491
494
  };
492
495
  }
493
- requests.push({
494
- argv: current
495
- });
496
+ const normalized = normalizeBatchRequest(current);
497
+ if ('error' in normalized) {
498
+ return normalized;
499
+ }
500
+ requests.push(normalized);
496
501
  return {
497
502
  tools: [],
498
503
  batch: requests,
@@ -562,15 +567,15 @@ export const commands = [{
562
567
  }
563
568
  }, {
564
569
  name: 'batch',
565
- description: 'Run multiple ADS CLI queries, including different command types, in one process.',
570
+ description: 'Run multiple ADS CLI queries in one process. Tokenized child requests are canonical; complete-request strings are also accepted.',
566
571
  usage: 'batch [--json] --command <command> [args...] [--command <command> [args...]]...',
567
572
  arguments: [],
568
573
  flags: [{
569
574
  name: 'command',
570
575
  type: 'string[]',
571
- description: 'A child command name followed by its arguments. Repeat once per child command.'
576
+ description: 'Canonical: a tokenized child command and its arguments. A complete quoted request is also accepted. Repeat once per child command.'
572
577
  }],
573
- examples: ['batch --command search button --type icon --command token space.200', 'batch --json --command component Button --command docs spacing'],
578
+ examples: ['batch --command search button --type icon --command token space.200', 'batch --command "search button" --type icon --command "token space.200"', 'batch --json --command component Button --command docs spacing'],
574
579
  responseTypes: ['ads-cli/batch'],
575
580
  envelopeType: () => 'batch',
576
581
  resolve: resolveBatch
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Normalise one batch child request without involving a shell.
3
+ *
4
+ * The canonical form is already-tokenized argv, for example
5
+ * `['search', 'Grid', '--type', 'component']`. For compatibility with agent-generated commands,
6
+ * the first token may instead contain a complete request, for example `['search Grid', '--type',
7
+ * 'component']`. Only that first token is split; trailing tokens have already been tokenized by the
8
+ * caller and must remain unchanged so multi-word arguments keep their boundaries.
9
+ */
10
+
11
+ const shellSyntaxError = syntax => ({
12
+ error: `Shell syntax ${syntax} is not supported in batch requests. Pass child commands as argv only; pipes, redirects, expansion, and command substitution are not allowed.`
13
+ });
14
+
15
+ /**
16
+ * Reject syntax that would have special meaning to a shell even though this parser never invokes
17
+ * one. Failing closed gives callers an actionable error instead of accepting input that only looks
18
+ * safe because it currently remains an argv array.
19
+ */
20
+ const findShellSyntax = value => {
21
+ var _value$match;
22
+ if (value.includes('$(')) {
23
+ return 'command substitution (`$(...)`)';
24
+ }
25
+ if (value.includes('`')) {
26
+ return 'command substitution (backticks)';
27
+ }
28
+ if (value.includes('$')) {
29
+ return 'environment expansion (`$`)';
30
+ }
31
+ if (/\r|\n/.test(value)) {
32
+ return 'a command separator (line break)';
33
+ }
34
+ if (value.includes('&&')) {
35
+ return 'the `&&` operator';
36
+ }
37
+ if (value.includes('||')) {
38
+ return 'the `||` operator';
39
+ }
40
+ const operator = (_value$match = value.match(/[|&;<>()]/)) === null || _value$match === void 0 ? void 0 : _value$match[0];
41
+ return operator ? `the \`${operator}\` operator` : null;
42
+ };
43
+
44
+ /**
45
+ * Split a complete child request into argv using quoting and escaping rules only. This is
46
+ * intentionally not a shell grammar: it performs no expansion, substitution, redirection, or
47
+ * operator evaluation.
48
+ */
49
+ const tokenizeCompleteRequest = value => {
50
+ const argv = [];
51
+ let current = '';
52
+ let quote = null;
53
+ let escaped = false;
54
+ let tokenStarted = false;
55
+ for (const character of value) {
56
+ if (escaped) {
57
+ current += character;
58
+ escaped = false;
59
+ tokenStarted = true;
60
+ continue;
61
+ }
62
+ if (character === '\\') {
63
+ escaped = true;
64
+ tokenStarted = true;
65
+ continue;
66
+ }
67
+ if (quote !== null) {
68
+ if (character === quote) {
69
+ quote = null;
70
+ } else {
71
+ current += character;
72
+ }
73
+ continue;
74
+ }
75
+ if (character === "'" || character === '"') {
76
+ quote = character;
77
+ tokenStarted = true;
78
+ continue;
79
+ }
80
+ if (/\s/.test(character)) {
81
+ if (tokenStarted) {
82
+ argv.push(current);
83
+ current = '';
84
+ tokenStarted = false;
85
+ }
86
+ continue;
87
+ }
88
+ current += character;
89
+ tokenStarted = true;
90
+ }
91
+ if (escaped) {
92
+ return {
93
+ error: 'Invalid complete batch request: it ends with an escape character.'
94
+ };
95
+ }
96
+ if (quote !== null) {
97
+ return {
98
+ error: `Invalid complete batch request: unterminated ${quote} quote.`
99
+ };
100
+ }
101
+ if (tokenStarted) {
102
+ argv.push(current);
103
+ }
104
+ if (argv.length === 0) {
105
+ return {
106
+ error: 'Invalid complete batch request: a command name is required.'
107
+ };
108
+ }
109
+ return {
110
+ argv
111
+ };
112
+ };
113
+ export const normalizeBatchRequest = argv => {
114
+ for (const token of argv) {
115
+ const syntax = findShellSyntax(token);
116
+ if (syntax !== null) {
117
+ return shellSyntaxError(syntax);
118
+ }
119
+ }
120
+ const [first, ...trailing] = argv;
121
+ if (first === undefined) {
122
+ return {
123
+ error: '`--command` must be followed by a non-empty command request.'
124
+ };
125
+ }
126
+
127
+ // A normal command name cannot contain whitespace, quotes, or escapes. Their presence in the
128
+ // first argv entry therefore identifies the complete-string compatibility form. Tokenized
129
+ // trailing entries are never re-split.
130
+ if (!/[\s'"\\]/.test(first)) {
131
+ return {
132
+ argv: [...argv]
133
+ };
134
+ }
135
+ const normalized = tokenizeCompleteRequest(first);
136
+ if ('error' in normalized) {
137
+ return normalized;
138
+ }
139
+ return {
140
+ argv: [...normalized.argv, ...trailing]
141
+ };
142
+ };
package/dist/esm/cli.js CHANGED
@@ -68,7 +68,10 @@ var buildHelpText = function buildHelpText(invocation) {
68
68
  comment: 'unified: components, tokens, icons & docs'
69
69
  }, {
70
70
  command: 'batch --command search button --type icon --command token space.200',
71
- comment: 'independent commands in one process'
71
+ comment: 'canonical tokenized batch form'
72
+ }, {
73
+ command: 'batch --command "search button" --type icon --command "token space.200"',
74
+ comment: 'complete-string compatibility form'
72
75
  }, {
73
76
  command: 'search button --type component'
74
77
  }, {
@@ -37,6 +37,7 @@ import { formatToken } from '../output/format-token';
37
37
  import { parseLintRuleRecords } from '../output/parse-lint-rule-records';
38
38
  import { buildManifest } from './build-manifest';
39
39
  import { getVersion } from './get-version';
40
+ import { normalizeBatchRequest } from './normalize-batch-request';
40
41
  /**
41
42
  * Shared `--limit` flag definition reused across the search-style commands.
42
43
  */
@@ -466,9 +467,9 @@ var resolveUnifiedSearch = function resolveUnifiedSearch(input) {
466
467
  };
467
468
 
468
469
  /**
469
- * Split a batch invocation into argv groups introduced by repeated `--command` flags. The groups
470
- * remain tokenized, so child commands can be routed through the existing parser without evaluating
471
- * shell strings.
470
+ * Split a batch invocation into argv groups introduced by repeated `--command` flags. Canonical
471
+ * tokenized groups remain unchanged; a complete request in the first token is safely normalized
472
+ * to argv without evaluating shell strings.
472
473
  */
473
474
  var resolveBatch = function resolveBatch(input) {
474
475
  var _input$rawArgs;
@@ -503,9 +504,11 @@ var resolveBatch = function resolveBatch(input) {
503
504
  error: '`--command` must be followed by a non-empty command request.'
504
505
  };
505
506
  }
506
- requests.push({
507
- argv: current
508
- });
507
+ var _normalized = normalizeBatchRequest(current);
508
+ if ('error' in _normalized) {
509
+ return _normalized;
510
+ }
511
+ requests.push(_normalized);
509
512
  current = [];
510
513
  continue;
511
514
  }
@@ -521,9 +524,11 @@ var resolveBatch = function resolveBatch(input) {
521
524
  error: '`--command` must be followed by a non-empty command request.'
522
525
  };
523
526
  }
524
- requests.push({
525
- argv: current
526
- });
527
+ var normalized = normalizeBatchRequest(current);
528
+ if ('error' in normalized) {
529
+ return normalized;
530
+ }
531
+ requests.push(normalized);
527
532
  return {
528
533
  tools: [],
529
534
  batch: requests,
@@ -596,15 +601,15 @@ export var commands = [{
596
601
  }
597
602
  }, {
598
603
  name: 'batch',
599
- description: 'Run multiple ADS CLI queries, including different command types, in one process.',
604
+ description: 'Run multiple ADS CLI queries in one process. Tokenized child requests are canonical; complete-request strings are also accepted.',
600
605
  usage: 'batch [--json] --command <command> [args...] [--command <command> [args...]]...',
601
606
  arguments: [],
602
607
  flags: [{
603
608
  name: 'command',
604
609
  type: 'string[]',
605
- description: 'A child command name followed by its arguments. Repeat once per child command.'
610
+ description: 'Canonical: a tokenized child command and its arguments. A complete quoted request is also accepted. Repeat once per child command.'
606
611
  }],
607
- examples: ['batch --command search button --type icon --command token space.200', 'batch --json --command component Button --command docs spacing'],
612
+ examples: ['batch --command search button --type icon --command token space.200', 'batch --command "search button" --type icon --command "token space.200"', 'batch --json --command component Button --command docs spacing'],
608
613
  responseTypes: ['ads-cli/batch'],
609
614
  envelopeType: function envelopeType() {
610
615
  return 'batch';
@@ -0,0 +1,169 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _toArray from "@babel/runtime/helpers/toArray";
3
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
4
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
5
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
6
+ /**
7
+ * Normalise one batch child request without involving a shell.
8
+ *
9
+ * The canonical form is already-tokenized argv, for example
10
+ * `['search', 'Grid', '--type', 'component']`. For compatibility with agent-generated commands,
11
+ * the first token may instead contain a complete request, for example `['search Grid', '--type',
12
+ * 'component']`. Only that first token is split; trailing tokens have already been tokenized by the
13
+ * caller and must remain unchanged so multi-word arguments keep their boundaries.
14
+ */
15
+
16
+ var shellSyntaxError = function shellSyntaxError(syntax) {
17
+ return {
18
+ error: "Shell syntax ".concat(syntax, " is not supported in batch requests. Pass child commands as argv only; pipes, redirects, expansion, and command substitution are not allowed.")
19
+ };
20
+ };
21
+
22
+ /**
23
+ * Reject syntax that would have special meaning to a shell even though this parser never invokes
24
+ * one. Failing closed gives callers an actionable error instead of accepting input that only looks
25
+ * safe because it currently remains an argv array.
26
+ */
27
+ var findShellSyntax = function findShellSyntax(value) {
28
+ var _value$match;
29
+ if (value.includes('$(')) {
30
+ return 'command substitution (`$(...)`)';
31
+ }
32
+ if (value.includes('`')) {
33
+ return 'command substitution (backticks)';
34
+ }
35
+ if (value.includes('$')) {
36
+ return 'environment expansion (`$`)';
37
+ }
38
+ if (/\r|\n/.test(value)) {
39
+ return 'a command separator (line break)';
40
+ }
41
+ if (value.includes('&&')) {
42
+ return 'the `&&` operator';
43
+ }
44
+ if (value.includes('||')) {
45
+ return 'the `||` operator';
46
+ }
47
+ var operator = (_value$match = value.match(/[|&;<>()]/)) === null || _value$match === void 0 ? void 0 : _value$match[0];
48
+ return operator ? "the `".concat(operator, "` operator") : null;
49
+ };
50
+
51
+ /**
52
+ * Split a complete child request into argv using quoting and escaping rules only. This is
53
+ * intentionally not a shell grammar: it performs no expansion, substitution, redirection, or
54
+ * operator evaluation.
55
+ */
56
+ var tokenizeCompleteRequest = function tokenizeCompleteRequest(value) {
57
+ var argv = [];
58
+ var current = '';
59
+ var quote = null;
60
+ var escaped = false;
61
+ var tokenStarted = false;
62
+ var _iterator = _createForOfIteratorHelper(value),
63
+ _step;
64
+ try {
65
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
66
+ var character = _step.value;
67
+ if (escaped) {
68
+ current += character;
69
+ escaped = false;
70
+ tokenStarted = true;
71
+ continue;
72
+ }
73
+ if (character === '\\') {
74
+ escaped = true;
75
+ tokenStarted = true;
76
+ continue;
77
+ }
78
+ if (quote !== null) {
79
+ if (character === quote) {
80
+ quote = null;
81
+ } else {
82
+ current += character;
83
+ }
84
+ continue;
85
+ }
86
+ if (character === "'" || character === '"') {
87
+ quote = character;
88
+ tokenStarted = true;
89
+ continue;
90
+ }
91
+ if (/\s/.test(character)) {
92
+ if (tokenStarted) {
93
+ argv.push(current);
94
+ current = '';
95
+ tokenStarted = false;
96
+ }
97
+ continue;
98
+ }
99
+ current += character;
100
+ tokenStarted = true;
101
+ }
102
+ } catch (err) {
103
+ _iterator.e(err);
104
+ } finally {
105
+ _iterator.f();
106
+ }
107
+ if (escaped) {
108
+ return {
109
+ error: 'Invalid complete batch request: it ends with an escape character.'
110
+ };
111
+ }
112
+ if (quote !== null) {
113
+ return {
114
+ error: "Invalid complete batch request: unterminated ".concat(quote, " quote.")
115
+ };
116
+ }
117
+ if (tokenStarted) {
118
+ argv.push(current);
119
+ }
120
+ if (argv.length === 0) {
121
+ return {
122
+ error: 'Invalid complete batch request: a command name is required.'
123
+ };
124
+ }
125
+ return {
126
+ argv: argv
127
+ };
128
+ };
129
+ export var normalizeBatchRequest = function normalizeBatchRequest(argv) {
130
+ var _iterator2 = _createForOfIteratorHelper(argv),
131
+ _step2;
132
+ try {
133
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
134
+ var token = _step2.value;
135
+ var syntax = findShellSyntax(token);
136
+ if (syntax !== null) {
137
+ return shellSyntaxError(syntax);
138
+ }
139
+ }
140
+ } catch (err) {
141
+ _iterator2.e(err);
142
+ } finally {
143
+ _iterator2.f();
144
+ }
145
+ var _argv = _toArray(argv),
146
+ first = _argv[0],
147
+ trailing = _arrayLikeToArray(_argv).slice(1);
148
+ if (first === undefined) {
149
+ return {
150
+ error: '`--command` must be followed by a non-empty command request.'
151
+ };
152
+ }
153
+
154
+ // A normal command name cannot contain whitespace, quotes, or escapes. Their presence in the
155
+ // first argv entry therefore identifies the complete-string compatibility form. Tokenized
156
+ // trailing entries are never re-split.
157
+ if (!/[\s'"\\]/.test(first)) {
158
+ return {
159
+ argv: _toConsumableArray(argv)
160
+ };
161
+ }
162
+ var normalized = tokenizeCompleteRequest(first);
163
+ if ('error' in normalized) {
164
+ return normalized;
165
+ }
166
+ return {
167
+ argv: [].concat(_toConsumableArray(normalized.argv), _toConsumableArray(trailing))
168
+ };
169
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Normalise one batch child request without involving a shell.
3
+ *
4
+ * The canonical form is already-tokenized argv, for example
5
+ * `['search', 'Grid', '--type', 'component']`. For compatibility with agent-generated commands,
6
+ * the first token may instead contain a complete request, for example `['search Grid', '--type',
7
+ * 'component']`. Only that first token is split; trailing tokens have already been tokenized by the
8
+ * caller and must remain unchanged so multi-word arguments keep their boundaries.
9
+ */
10
+ type NormalizedBatchRequest = {
11
+ argv: string[];
12
+ } | {
13
+ error: string;
14
+ };
15
+ export declare const normalizeBatchRequest: (argv: string[]) => NormalizedBatchRequest;
16
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/ads-cli",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "An npx-runnable command-line tool to query Atlassian Design System (ADS) structured content — components, tokens, icons, and guidelines — from the terminal.",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",