Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/commands/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
12 changes: 12 additions & 0 deletions test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading