From c4a9fe0a1414a9c6744b97395d5583c398fedeaa Mon Sep 17 00:00:00 2001 From: yearthmain Date: Fri, 7 Aug 2026 11:21:20 +0800 Subject: [PATCH] fix(cli): reject pagination modifiers with --count --- src/commands/root.ts | 14 ++++++++++++++ test/cli.test.ts | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/commands/root.ts b/src/commands/root.ts index e6df521..3b1a7e9 100644 --- a/src/commands/root.ts +++ b/src/commands/root.ts @@ -758,6 +758,20 @@ export async function root(argv: string[]) { 'use it with --row, --table, --locate, or a selector; fetch mode already returns JSON' ) } + const countModifiers = [ + ['--limit', flags.limit !== undefined], + ['--offset', flags.offset !== undefined], + ['--budget', flags.budget !== undefined], + ['--all', flags.all === true], + ] + .filter(([, active]) => active) + .map(([flag]) => flag) + if (flags.count === true && countModifiers.length > 0) { + fail( + `--count cannot be combined with ${countModifiers.join(', ')}`, + '--count always reports total matches; remove pagination modifiers or choose a list output mode' + ) + } const fetchOnlyOutputMode = typeof flags.output === 'string' ? '--output' : flags.body === true ? '--body' : null if (fetchOnlyOutputMode && (!isUrl || selector !== undefined)) { diff --git a/test/cli.test.ts b/test/cli.test.ts index f905d97..5df0fad 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -608,6 +608,18 @@ test('fetch-only output modes fail in parse mode before source I/O', () => { } }) +test('--count rejects pagination modifiers before source I/O', () => { + const cases = [['--limit', '1'], ['--offset', '1'], ['--budget', '1'], ['--all']] + + for (const modifier of cases) { + const r = ax(['missing.html', '.x', '--count', ...modifier]) + expect(r.code).toBe(1) + expect(r.out).toBe('') + expect(r.err).toContain(`ax: error: --count cannot be combined with ${modifier[0]}`) + expect(r.err).not.toContain('ENOENT') + } +}) + test('cap: default limit with stderr note', () => { const r = ax(['many.html', '.x']) expect(r.out.split('\n')).toHaveLength(50)