Skip to content

Commit

Permalink
Ask to use default endpoint first
Browse files Browse the repository at this point in the history
  • Loading branch information
macmv committed Oct 10, 2023
1 parent d341011 commit aacafa5
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/lib/stack-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ export class StackFactory {
this.cmd = cmd;
this.config = config;
}

async askEndpoint(): Promise<string> {
const useDefault =
this.config.rootConfig.defaultEndpoint !== undefined &&
(await confirm({
message: `Use the default endpoint [${this.config.rootConfig.defaultEndpoint}]`,
}));

if (useDefault) {
return this.config.rootConfig.defaultEndpoint!;
}

return searchSelect({
message: "Select an endpoint",
choices: Object.keys(this.config.rootConfig.endpoints).map(
(endpoint) => ({
value: endpoint,
})
),
});
}

/**
*
* @param cmd - used to send info/errors to the user.
Expand Down Expand Up @@ -59,16 +81,7 @@ export class StackFactory {
this.cmd.error(res as string);
}

const endpointName =
params?.endpoint ??
(await searchSelect({
message: "Select an endpoint",
choices: Object.keys(this.config.rootConfig.endpoints).map(
(endpoint) => ({
value: endpoint,
})
),
}));
const endpointName = params?.endpoint ?? (await this.askEndpoint());

if (!Object.keys(this.config.rootConfig.endpoints).includes(endpointName)) {
this.cmd.error(`No such endpoint '${endpointName}'`);
Expand Down

0 comments on commit aacafa5

Please sign in to comment.