@hono/cli 0.1.0 → 0.1.2
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.
- package/README.md +1 -0
- package/dist/cli.js +22 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -156,6 +156,7 @@ hono request [file] [options]
|
|
|
156
156
|
- `-X, --method <method>` - HTTP method (default: GET)
|
|
157
157
|
- `-d, --data <data>` - Request body data
|
|
158
158
|
- `-H, --header <header>` - Custom headers (can be used multiple times)
|
|
159
|
+
- `-w, --watch` - Watch for changes and resend request
|
|
159
160
|
|
|
160
161
|
**Examples:**
|
|
161
162
|
|
package/dist/cli.js
CHANGED
|
@@ -269,11 +269,21 @@ async function executeRequest(appPath, requestPath, options) {
|
|
|
269
269
|
|
|
270
270
|
// src/commands/search/index.ts
|
|
271
271
|
function searchCommand(program2) {
|
|
272
|
-
program2.command("search").argument("<query>", "Search query for Hono documentation").option("-l, --limit <number>", "Number of results to show (default: 5)",
|
|
272
|
+
program2.command("search").argument("<query>", "Search query for Hono documentation").option("-l, --limit <number>", "Number of results to show (default: 5)", (value) => {
|
|
273
|
+
const parsed = parseInt(value, 10);
|
|
274
|
+
if (isNaN(parsed) || parsed < 1) {
|
|
275
|
+
throw new Error(`Limit must be a number between 1 and 20. Received: ${value}
|
|
276
|
+
`);
|
|
277
|
+
}
|
|
278
|
+
if (parsed > 20) {
|
|
279
|
+
console.warn("Limit must be a number between 1 and 20\n");
|
|
280
|
+
return 5;
|
|
281
|
+
}
|
|
282
|
+
return parsed;
|
|
283
|
+
}).option("-p, --pretty", "Display results in human-readable format").description("Search Hono documentation").action(async (query, options) => {
|
|
273
284
|
const ALGOLIA_APP_ID = "1GIFSU1REV";
|
|
274
285
|
const ALGOLIA_API_KEY = "c6a0f86b9a9f8551654600f28317a9e9";
|
|
275
286
|
const ALGOLIA_INDEX = "hono";
|
|
276
|
-
const limit = Math.max(1, Math.min(20, parseInt(options.limit, 10) || 5));
|
|
277
287
|
const searchUrl = `https://${ALGOLIA_APP_ID}-dsn.algolia.net/1/indexes/${ALGOLIA_INDEX}/query`;
|
|
278
288
|
try {
|
|
279
289
|
if (options.pretty) {
|
|
@@ -288,7 +298,7 @@ function searchCommand(program2) {
|
|
|
288
298
|
},
|
|
289
299
|
body: JSON.stringify({
|
|
290
300
|
query,
|
|
291
|
-
hitsPerPage: limit
|
|
301
|
+
hitsPerPage: options.limit || 5
|
|
292
302
|
})
|
|
293
303
|
});
|
|
294
304
|
if (!response.ok) {
|
|
@@ -460,7 +470,14 @@ var builtinMap = {
|
|
|
460
470
|
}
|
|
461
471
|
});
|
|
462
472
|
function serveCommand(program2) {
|
|
463
|
-
program2.command("serve").description("Start server").argument("[entry]", "entry file").option("-p, --port <port>", "port number"
|
|
473
|
+
program2.command("serve").description("Start server").argument("[entry]", "entry file").option("-p, --port <port>", "port number", (value) => {
|
|
474
|
+
const parsed = parseInt(value, 10);
|
|
475
|
+
if (!/^\d+$/.test(value) || parsed < 0 || parsed > 65535) {
|
|
476
|
+
throw new Error(`Port must be a number between 0 and 65535. Received: ${value}
|
|
477
|
+
`);
|
|
478
|
+
}
|
|
479
|
+
return parsed;
|
|
480
|
+
}).option("--show-routes", "show registered routes").option(
|
|
464
481
|
"--use <middleware>",
|
|
465
482
|
"use middleware",
|
|
466
483
|
(value, previous) => {
|
|
@@ -513,7 +530,7 @@ function serveCommand(program2) {
|
|
|
513
530
|
serve(
|
|
514
531
|
{
|
|
515
532
|
fetch: baseApp.fetch,
|
|
516
|
-
port: options.port
|
|
533
|
+
port: options.port ?? 7070
|
|
517
534
|
},
|
|
518
535
|
(info) => {
|
|
519
536
|
console.log(`Listening on http://localhost:${info.port}`);
|