@tiny-fish/cli 0.33.1-next.279 → 0.33.1-next.280

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.
@@ -1,9 +1,10 @@
1
1
  import { getApiKey } from '../lib/auth.js';
2
2
  import { searchQuery } from '../lib/client.js';
3
- import { handleApiError, out, outLine } from '../lib/output.js';
3
+ import { err, handleApiError, out, outLine } from '../lib/output.js';
4
4
  function printPrettySearch(response) {
5
5
  outLine(`Query: ${response.query}`);
6
6
  outLine(`Total results: ${response.total_results}`);
7
+ outLine(`Page: ${response.page}`);
7
8
  outLine('');
8
9
  if (response.results.length === 0) {
9
10
  outLine('No results.');
@@ -16,6 +17,16 @@ function printPrettySearch(response) {
16
17
  outLine('');
17
18
  }
18
19
  }
20
+ // Blank strings coerce to 0, a valid page.
21
+ function parsePageOption(value) {
22
+ if (value === undefined)
23
+ return undefined;
24
+ if (!/^\d+$/.test(value) || Number(value) > 10) {
25
+ err({ error: `Invalid --page "${value}". Must be an integer between 0 and 10.` });
26
+ process.exit(1);
27
+ }
28
+ return Number(value);
29
+ }
19
30
  export function registerSearch(program) {
20
31
  const searchCmd = program
21
32
  .command('search')
@@ -29,8 +40,10 @@ export function registerSearch(program) {
29
40
  .option('--language <value>', 'Search language hint')
30
41
  .option('--include-domains <value>', 'Comma-separated list of domains to restrict results to')
31
42
  .option('--exclude-domains <value>', 'Comma-separated list of domains to exclude from results')
43
+ .option('--page <value>', 'Page number for pagination, starting from 0')
32
44
  .option('--pretty', 'Human-readable output')
33
45
  .action(async (query, opts) => {
46
+ const page = parsePageOption(opts.page);
34
47
  const apiKey = getApiKey();
35
48
  try {
36
49
  const response = await searchQuery({
@@ -39,6 +52,7 @@ export function registerSearch(program) {
39
52
  ...(opts.language !== undefined ? { language: opts.language } : {}),
40
53
  ...(opts.includeDomains !== undefined ? { include_domains: opts.includeDomains } : {}),
41
54
  ...(opts.excludeDomains !== undefined ? { exclude_domains: opts.excludeDomains } : {}),
55
+ ...(page !== undefined ? { page } : {}),
42
56
  }, apiKey);
43
57
  if (opts.pretty) {
44
58
  printPrettySearch(response);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiny-fish/cli",
3
- "version": "0.33.1-next.279",
3
+ "version": "0.33.1-next.280",
4
4
  "description": "TinyFish CLI — run web automations from your terminal",
5
5
  "type": "module",
6
6
  "bin": {