diff --git a/src/cli/index.ts b/src/cli/index.ts index 9010526..72525d3 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -6,6 +6,15 @@ import { generateFromSwagger } from "./swagger-generator.js"; type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE"; +interface CliOptions { + type?: boolean; + swagger?: boolean; + method: HttpMethod; + body?: string; + url?: string; + headers: Record; +} + /** * Main CLI entry point for bytekit */ @@ -15,14 +24,7 @@ export async function runCli(argv: string[]): Promise { return; } - const options: { - type?: boolean; - swagger?: boolean; - method: HttpMethod; - body?: string; - url?: string; - headers: Record; - } = { + const options: CliOptions = { method: "GET", headers: {}, }; @@ -75,14 +77,16 @@ export async function runCli(argv: string[]): Promise { if (options.swagger) { await generateFromSwagger({ url: options.url }); } else if (options.type) { - await handleTypeGeneration(options); + await handleTypeGeneration(options as CliOptions & { url: string }); } else { // Simple fetch/curl behavior if --type is not present - await handleSimpleFetch(options); + await handleSimpleFetch(options as CliOptions & { url: string }); } } -async function handleTypeGeneration(options: any): Promise { +async function handleTypeGeneration( + options: CliOptions & { url: string } +): Promise { const url = new URL(options.url); const endpointName = url.pathname.split("/").filter(Boolean).pop() || "api"; @@ -104,7 +108,9 @@ async function handleTypeGeneration(options: any): Promise { }); } -async function handleSimpleFetch(options: any): Promise { +async function handleSimpleFetch( + options: CliOptions & { url: string } +): Promise { console.log(`\n📡 Fetching ${options.method} ${options.url}...`); try { const response = await fetch(options.url, {