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
26 changes: 16 additions & 10 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@

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 @@
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 @@
if (options.swagger) {
await generateFromSwagger({ url: options.url });
} else if (options.type) {
await handleTypeGeneration(options);

Check failure on line 80 in src/cli/index.ts

View workflow job for this annotation

GitHub Actions / coverage

Argument of type 'CliOptions' is not assignable to parameter of type 'CliOptions & { url: string; }'.

Check failure on line 80 in src/cli/index.ts

View workflow job for this annotation

GitHub Actions / Run Tests (20.x)

Argument of type 'CliOptions' is not assignable to parameter of type 'CliOptions & { url: string; }'.

Check failure on line 80 in src/cli/index.ts

View workflow job for this annotation

GitHub Actions / build (22.x, ubuntu-latest)

Argument of type 'CliOptions' is not assignable to parameter of type 'CliOptions & { url: string; }'.

Check failure on line 80 in src/cli/index.ts

View workflow job for this annotation

GitHub Actions / Run Tests (22.x)

Argument of type 'CliOptions' is not assignable to parameter of type 'CliOptions & { url: string; }'.

Check failure on line 80 in src/cli/index.ts

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

Argument of type 'CliOptions' is not assignable to parameter of type 'CliOptions & { url: string; }'.

Check failure on line 80 in src/cli/index.ts

View workflow job for this annotation

GitHub Actions / build (20.x, macos-latest)

Argument of type 'CliOptions' is not assignable to parameter of type 'CliOptions & { url: string; }'.

Check failure on line 80 in src/cli/index.ts

View workflow job for this annotation

GitHub Actions / size

Argument of type 'CliOptions' is not assignable to parameter of type 'CliOptions & { url: string; }'.

Check failure on line 80 in src/cli/index.ts

View workflow job for this annotation

GitHub Actions / build (22.x, macos-latest)

Argument of type 'CliOptions' is not assignable to parameter of type 'CliOptions & { url: string; }'.
} else {
// Simple fetch/curl behavior if --type is not present
await handleSimpleFetch(options);

Check failure on line 83 in src/cli/index.ts

View workflow job for this annotation

GitHub Actions / coverage

Argument of type 'CliOptions' is not assignable to parameter of type 'CliOptions & { url: string; }'.

Check failure on line 83 in src/cli/index.ts

View workflow job for this annotation

GitHub Actions / Run Tests (20.x)

Argument of type 'CliOptions' is not assignable to parameter of type 'CliOptions & { url: string; }'.

Check failure on line 83 in src/cli/index.ts

View workflow job for this annotation

GitHub Actions / build (22.x, ubuntu-latest)

Argument of type 'CliOptions' is not assignable to parameter of type 'CliOptions & { url: string; }'.

Check failure on line 83 in src/cli/index.ts

View workflow job for this annotation

GitHub Actions / Run Tests (22.x)

Argument of type 'CliOptions' is not assignable to parameter of type 'CliOptions & { url: string; }'.

Check failure on line 83 in src/cli/index.ts

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

Argument of type 'CliOptions' is not assignable to parameter of type 'CliOptions & { url: string; }'.

Check failure on line 83 in src/cli/index.ts

View workflow job for this annotation

GitHub Actions / build (20.x, macos-latest)

Argument of type 'CliOptions' is not assignable to parameter of type 'CliOptions & { url: string; }'.

Check failure on line 83 in src/cli/index.ts

View workflow job for this annotation

GitHub Actions / size

Argument of type 'CliOptions' is not assignable to parameter of type 'CliOptions & { url: string; }'.

Check failure on line 83 in src/cli/index.ts

View workflow job for this annotation

GitHub Actions / build (22.x, macos-latest)

Argument of type 'CliOptions' is not assignable to parameter of type '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 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