Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(cli): make search --limit accept what search({limit}) accepts (#6528)

Joeydea6813146d2
diff --git a/.changeset/cli-spec-search-limit-parity.md b/.changeset/cli-spec-search-limit-parity.md
new file mode 100644
index 0000000000..90c957ea1d
--- /dev/null
+++ b/.changeset/cli-spec-search-limit-parity.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[fix] `astryx search --limit` now refuses a value that is not a positive integer, such as `1.5` or `5abc`, with `ERR_INVALID_ARGUMENT` and exit 1, as `search({limit})` already did, instead of silently truncating it.
+
+@josephfarina
diff --git a/packages/cli/clients/cli/commands/search.doc.mjs b/packages/cli/clients/cli/commands/search.doc.mjs
index 19d8b3ec37..ff46f6c32e 100644
--- a/packages/cli/clients/cli/commands/search.doc.mjs
+++ b/packages/cli/clients/cli/commands/search.doc.mjs
@@ -29,7 +29,7 @@ export const doc = {
{
flag: '--limit <n>',
param: 'options.limit',
- description: 'Max number of results (default 20)',
+ description: 'Max number of results, a positive integer (default 20)',
},
{
flag: '--verbose',
@@ -47,7 +47,7 @@ export const doc = {
{code: 0, when: 'success (including zero matches)'},
{
code: 1,
- when: 'invalid --type or a non-positive --limit, or @astryxdesign/core cannot be found',
+ when: 'invalid --type, a --limit that is not a positive integer, or @astryxdesign/core cannot be found',
},
],
related: ['component', 'hook', 'docs', 'template', 'build'],
diff --git a/packages/cli/clients/cli/commands/search.mjs b/packages/cli/clients/cli/commands/search.mjs
index 6961379e82..e8b77d4d83 100644
--- a/packages/cli/clients/cli/commands/search.mjs
+++ b/packages/cli/clients/cli/commands/search.mjs
@@ -54,11 +54,10 @@ export function registerSearch(program) {
// Never let the nudge break the command.
}
- // Parse --limit to a number; the API validates it (positive integer) and
- // throws ERR_INVALID_ARGUMENT, so we pass NaN through rather than
- // pre-rejecting with a generic code here.
- const limit =
- options.limit != null ? Number.parseInt(options.limit, 10) : 20;
+ // Number(), not parseInt(): parseInt truncates `1.5` and `5abc` into
+ // integers the API would reject. The API validates the value, so the
+ // flag and `search({limit})` accept and refuse the same inputs.
+ const limit = options.limit != null ? Number(options.limit) : 20;
/** @type {import('../../../api/search/search.type.mjs').SearchResponse} */
let result;
diff --git a/packages/cli/clients/cli/commands/search.test.mjs b/packages/cli/clients/cli/commands/search.test.mjs
index cb1b1f326c..8c1c668c32 100644
--- a/packages/cli/clients/cli/commands/search.test.mjs
+++ b/packages/cli/clients/cli/commands/search.test.mjs
@@ -201,6 +201,20 @@ describe('search CLI — exit codes + JSON contract', () => {
expect(r.status).toBe(1);
});
+ it.each(['1.5', '5abc'])(
+ 'refuses --limit %s like search({limit}) does, in both modes',
+ async value => {
+ await expect(
+ search('x', {...OPTS, limit: Number(value)}),
+ ).rejects.toMatchObject({code: 'ERR_INVALID_ARGUMENT'});
+ const json = await runCli(['--json', 'search', 'x', '--limit', value], REPO_ROOT);
+ expect(json.status).toBe(1);
+ expect(JSON.parse(json.stdout)).toMatchObject({code: 'ERR_INVALID_ARGUMENT'});
+ const text = await runCli(['search', 'x', '--limit', value], REPO_ROOT);
+ expect(text.status).toBe(1);
+ },
+ );
+
it('emits a valid --json envelope', async () => {
const r = await runCli(['--json', 'search', 'button'], REPO_ROOT);
expect(r.status).toBe(0);