@@ -3,8 +3,10 @@ import type * as yargs from "yargs";
33import { API } from "../../API" ;
44import { 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
911export 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 ) {
0 commit comments