@@ -3,8 +3,10 @@ import type * as yargs from "yargs";
3
3
import { API } from "../../API" ;
4
4
import { getInferredApiKey } from "../../utils/constants" ;
5
5
6
- const apiKey = getInferredApiKey ( ) ;
7
- const api = new API ( { apiKey } ) ;
6
+ function getAPI ( ) {
7
+ const apiKey = getInferredApiKey ( ) ;
8
+ return new API ( { apiKey } ) ;
9
+ }
8
10
9
11
export const previewHostsCommand : yargs . CommandModule = {
10
12
command : "preview-hosts" ,
@@ -16,6 +18,7 @@ export const previewHostsCommand: yargs.CommandModule = {
16
18
command : "list" ,
17
19
describe : "List current preview hosts" ,
18
20
handler : async ( ) => {
21
+ const api = getAPI ( ) ;
19
22
const response = await api . listPreviewHosts ( ) ;
20
23
const hosts = response . preview_hosts . map ( ( { host } ) => host ) ;
21
24
if ( hosts . length ) {
@@ -35,6 +38,7 @@ export const previewHostsCommand: yargs.CommandModule = {
35
38
demandOption : true ,
36
39
} ) ,
37
40
handler : async ( argv ) => {
41
+ const api = getAPI ( ) ;
38
42
const response = await api . listPreviewHosts ( ) ;
39
43
let hosts = response . preview_hosts . map ( ( { host } ) => host ) ;
40
44
const hostToAdd = ( argv . host as string ) . trim ( ) ;
@@ -57,6 +61,7 @@ export const previewHostsCommand: yargs.CommandModule = {
57
61
demandOption : true ,
58
62
} ) ,
59
63
handler : async ( argv ) => {
64
+ const api = getAPI ( ) ;
60
65
const response = await api . listPreviewHosts ( ) ;
61
66
let hosts = response . preview_hosts . map ( ( { host } ) => host ) ;
62
67
const hostToRemove = ( argv . host as string ) . trim ( ) ;
@@ -73,6 +78,7 @@ export const previewHostsCommand: yargs.CommandModule = {
73
78
command : "clear" ,
74
79
describe : "Clear all preview hosts" ,
75
80
handler : async ( ) => {
81
+ const api = getAPI ( ) ;
76
82
const response = await api . listPreviewHosts ( ) ;
77
83
const hosts = response . preview_hosts . map ( ( { host } ) => host ) ;
78
84
if ( hosts . length === 0 ) {
0 commit comments