Skip to content

Commit 3f14843

Browse files
fix: allow --help without api key (#190)
1 parent 7f6f7b4 commit 3f14843

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/bin/commands/previewHosts.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import type * as yargs from "yargs";
33
import { API } from "../../API";
44
import { getInferredApiKey } from "../../utils/constants";
55

6-
const apiKey = getInferredApiKey();
7-
const api = new API({ apiKey });
6+
function getAPI() {
7+
const apiKey = getInferredApiKey();
8+
return new API({ apiKey });
9+
}
810

911
export const previewHostsCommand: yargs.CommandModule = {
1012
command: "preview-hosts",
@@ -16,6 +18,7 @@ export const previewHostsCommand: yargs.CommandModule = {
1618
command: "list",
1719
describe: "List current preview hosts",
1820
handler: async () => {
21+
const api = getAPI();
1922
const response = await api.listPreviewHosts();
2023
const hosts = response.preview_hosts.map(({ host }) => host);
2124
if (hosts.length) {
@@ -35,6 +38,7 @@ export const previewHostsCommand: yargs.CommandModule = {
3538
demandOption: true,
3639
}),
3740
handler: async (argv) => {
41+
const api = getAPI();
3842
const response = await api.listPreviewHosts();
3943
let hosts = response.preview_hosts.map(({ host }) => host);
4044
const hostToAdd = (argv.host as string).trim();
@@ -57,6 +61,7 @@ export const previewHostsCommand: yargs.CommandModule = {
5761
demandOption: true,
5862
}),
5963
handler: async (argv) => {
64+
const api = getAPI();
6065
const response = await api.listPreviewHosts();
6166
let hosts = response.preview_hosts.map(({ host }) => host);
6267
const hostToRemove = (argv.host as string).trim();
@@ -73,6 +78,7 @@ export const previewHostsCommand: yargs.CommandModule = {
7378
command: "clear",
7479
describe: "Clear all preview hosts",
7580
handler: async () => {
81+
const api = getAPI();
7682
const response = await api.listPreviewHosts();
7783
const hosts = response.preview_hosts.map(({ host }) => host);
7884
if (hosts.length === 0) {

src/bin/ui/sdkContext.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ import { API } from "../../API";
55
import { getInferredApiKey } from "../../utils/constants";
66
import { instrumentedFetch } from "../utils/sentry";
77

8-
const apiKey = getInferredApiKey();
9-
const sdk = new CodeSandbox(apiKey);
10-
const api = new API({ apiKey, instrumentation: instrumentedFetch });
11-
12-
export const SDKContext = createContext<{ sdk: CodeSandbox; api: API }>({
13-
sdk,
14-
api,
15-
});
8+
export const SDKContext = createContext(
9+
null as unknown as { sdk: CodeSandbox; api: API }
10+
);
1611

1712
export const SDKProvider = ({ children }: { children: React.ReactNode }) => {
13+
const apiKey = getInferredApiKey();
14+
const sdk = new CodeSandbox(apiKey);
15+
const api = new API({ apiKey, instrumentation: instrumentedFetch });
16+
1817
return (
1918
<SDKContext.Provider value={{ sdk, api }}>{children}</SDKContext.Provider>
2019
);

0 commit comments

Comments
 (0)