Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;
}

/**
* Main CLI entry point for bytekit
*/
Expand All @@ -15,14 +24,7 @@ export async function runCli(argv: string[]): Promise<void> {
return;
}

const options: {
type?: boolean;
swagger?: boolean;
method: HttpMethod;
body?: string;
url?: string;
headers: Record<string, string>;
} = {
const options: CliOptions = {
method: "GET",
headers: {},
};
Expand Down Expand Up @@ -75,14 +77,16 @@ export async function runCli(argv: string[]): Promise<void> {
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<void> {
async function handleTypeGeneration(
options: CliOptions & { url: string }
): Promise<void> {
const url = new URL(options.url);
const endpointName = url.pathname.split("/").filter(Boolean).pop() || "api";

Expand All @@ -104,7 +108,9 @@ async function handleTypeGeneration(options: any): Promise<void> {
});
}

async function handleSimpleFetch(options: any): Promise<void> {
async function handleSimpleFetch(
options: CliOptions & { url: string }
): Promise<void> {
console.log(`\n馃摗 Fetching ${options.method} ${options.url}...`);
try {
const response = await fetch(options.url, {
Expand Down
Loading