fix: search pagination output (#42) (thanks @pjtf93)

This commit is contained in:
Peter Steinberger
2026-01-12 06:30:20 +00:00
parent e23c20a6a2
commit a782ca5d3a
3 changed files with 64 additions and 47 deletions
+1
View File
@@ -10,6 +10,7 @@
- `replies` and `thread` now support pagination (`--all`, `--max-pages`, `--cursor`, `--delay`) (#35) — thanks @crcatala. - `replies` and `thread` now support pagination (`--all`, `--max-pages`, `--cursor`, `--delay`) (#35) — thanks @crcatala.
- Long-form article tweets now render rich Draft.js content blocks/entities (#36) — thanks @crcatala. - Long-form article tweets now render rich Draft.js content blocks/entities (#36) — thanks @crcatala.
- `news`/`trending` command for Explore tabs with AI-curated headlines (#39) — thanks @aavetis. - `news`/`trending` command for Explore tabs with AI-curated headlines (#39) — thanks @aavetis.
- `search` now supports pagination (`--all`, `--max-pages`, `--cursor`) (#42) — thanks @pjtf93.
### Changed ### Changed
- Library typing: `SearchResult` is now a discriminated union (so `error` only exists when `success: false`). - Library typing: `SearchResult` is now a discriminated union (so `error` only exists when `success: false`).
+14 -2
View File
@@ -14,7 +14,18 @@ export function registerSearchCommands(program: Command, ctx: CliContext): void
.option('--cursor <string>', 'Resume pagination from a cursor') .option('--cursor <string>', 'Resume pagination from a cursor')
.option('--json', 'Output as JSON') .option('--json', 'Output as JSON')
.option('--json-full', 'Output as JSON with full raw API response in _raw field') .option('--json-full', 'Output as JSON with full raw API response in _raw field')
.action(async (query: string, cmdOpts: { count?: string; all?: boolean; maxPages?: string; cursor?: string; json?: boolean; jsonFull?: boolean }) => { .action(
async (
query: string,
cmdOpts: {
count?: string;
all?: boolean;
maxPages?: string;
cursor?: string;
json?: boolean;
jsonFull?: boolean;
},
) => {
const opts = program.opts(); const opts = program.opts();
const timeoutMs = ctx.resolveTimeoutFromOptions(opts); const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts); const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
@@ -65,7 +76,8 @@ export function registerSearchCommands(program: Command, ctx: CliContext): void
console.error(`${ctx.p('err')}Search failed: ${result.error}`); console.error(`${ctx.p('err')}Search failed: ${result.error}`);
process.exit(1); process.exit(1);
} }
}); },
);
program program
.command('mentions') .command('mentions')
+5 -1
View File
@@ -68,7 +68,11 @@ export function withSearch<TBase extends AbstractConstructor<TwitterClientBase>>
return this.searchPaged(query, Number.POSITIVE_INFINITY, options); return this.searchPaged(query, Number.POSITIVE_INFINITY, options);
} }
private async searchPaged(query: string, limit: number, options: SearchPaginationOptions = {}): Promise<SearchResult> { private async searchPaged(
query: string,
limit: number,
options: SearchPaginationOptions = {},
): Promise<SearchResult> {
const features = buildSearchFeatures(); const features = buildSearchFeatures();
const pageSize = 20; const pageSize = 20;
const seen = new Set<string>(); const seen = new Set<string>();