|
1 | | -import { printWranglerBanner } from ".."; |
2 | | -import { readConfig } from "../config"; |
| 1 | +import { defineCommand } from "../core"; |
3 | 2 | import { logger } from "../logger"; |
4 | 3 | import * as metrics from "../metrics"; |
5 | 4 | import openInBrowser from "../open-in-browser"; |
6 | 5 | import { runSearch } from "./helpers"; |
7 | | -import type { |
8 | | - CommonYargsArgv, |
9 | | - StrictYargsOptionsToInterface, |
10 | | -} from "../yargs-types"; |
11 | 6 |
|
12 | | -export function docsOptions(yargs: CommonYargsArgv) { |
13 | | - return yargs |
14 | | - .positional("search", { |
| 7 | +defineCommand({ |
| 8 | + command: "wrangler docs", |
| 9 | + metadata: { |
| 10 | + description: "📚 Open Wrangler's command documentation in your browser\n", |
| 11 | + owner: "Workers: Authoring and Testing", |
| 12 | + status: "stable", |
| 13 | + }, |
| 14 | + args: { |
| 15 | + search: { |
15 | 16 | describe: |
16 | 17 | "Enter search terms (e.g. the wrangler command) you want to know more about", |
17 | 18 | type: "string", |
18 | 19 | array: true, |
19 | | - }) |
20 | | - .option("yes", { |
| 20 | + }, |
| 21 | + yes: { |
21 | 22 | alias: "y", |
22 | 23 | type: "boolean", |
23 | | - description: "Takes you to the docs, even if search fails", |
24 | | - }); |
25 | | -} |
26 | | - |
27 | | -export async function docsHandler( |
28 | | - args: StrictYargsOptionsToInterface<typeof docsOptions> |
29 | | -) { |
30 | | - //if no command is provided, open the docs homepage |
31 | | - //or, if a command IS provided, but we can't find anything, open the docs homepage |
32 | | - let urlToOpen = |
33 | | - args.yes || !args.search || args.search.length === 0 |
34 | | - ? "https://developers.cloudflare.com/workers/wrangler/commands/" |
35 | | - : ""; |
| 24 | + describe: "Takes you to the docs, even if search fails", |
| 25 | + }, |
| 26 | + }, |
| 27 | + positionalArgs: ["search"], |
| 28 | + async handler(args, { config }) { |
| 29 | + //if no command is provided, open the docs homepage |
| 30 | + //or, if a command IS provided, but we can't find anything, open the docs homepage |
| 31 | + let urlToOpen = |
| 32 | + args.yes || !args.search || args.search.length === 0 |
| 33 | + ? "https://developers.cloudflare.com/workers/wrangler/commands/" |
| 34 | + : ""; |
36 | 35 |
|
37 | | - if (args.search && args.search.length > 0) { |
38 | | - const searchTerm = args.search.join(" "); |
39 | | - const searchResult = await runSearch(searchTerm); |
| 36 | + if (args.search && args.search.length > 0) { |
| 37 | + const searchTerm = args.search.join(" "); |
| 38 | + const searchResult = await runSearch(searchTerm); |
40 | 39 |
|
41 | | - urlToOpen = searchResult ?? urlToOpen; |
42 | | - } |
| 40 | + urlToOpen = searchResult ?? urlToOpen; |
| 41 | + } |
43 | 42 |
|
44 | | - if (!urlToOpen) { |
45 | | - return; |
46 | | - } |
47 | | - await printWranglerBanner(); |
| 43 | + if (!urlToOpen) { |
| 44 | + return; |
| 45 | + } |
48 | 46 |
|
49 | | - logger.log(`Opening a link in your default browser: ${urlToOpen}`); |
50 | | - await openInBrowser(urlToOpen); |
51 | | - const config = readConfig(undefined, args); |
52 | | - await metrics.sendMetricsEvent("view docs", { |
53 | | - sendMetrics: config.send_metrics, |
54 | | - }); |
55 | | -} |
| 47 | + logger.log(`Opening a link in your default browser: ${urlToOpen}`); |
| 48 | + await openInBrowser(urlToOpen); |
| 49 | + await metrics.sendMetricsEvent("view docs", { |
| 50 | + sendMetrics: config.send_metrics, |
| 51 | + }); |
| 52 | + }, |
| 53 | +}); |
0 commit comments