@@ -9,6 +9,7 @@ import { FilePath } from "../../types/file/filePath.js";
99import { FileName } from "../../types/file/fileName.js" ;
1010import { FileService } from "../../infrastructure/file-service.js" ;
1111import { LauncherService } from "../../infrastructure/launcher-service.js" ;
12+ import { format } from "../../prompts/format.js" ;
1213
1314export class CopilotAction {
1415 private readonly apiService = new ApiService ( ) ;
@@ -26,25 +27,31 @@ export class CopilotAction {
2627 public async execute ( buildDirectory : DirectoryPath , force : boolean , enable : boolean ) : Promise < ActionResult > {
2728 const buildContext = new BuildContext ( buildDirectory ) ;
2829
29- if ( ! ( await buildContext . validate ( ) ) ) {
30- return ActionResult . error ( "'src' directory is empty or not valid." ) ;
30+ if ( ! await buildContext . validate ( ) ) {
31+ this . prompts . srcDirectoryEmpty ( buildDirectory ) ;
32+ return ActionResult . failed ( ) ;
3133 }
3234
3335 const buildJson = await buildContext . getBuildFileContents ( ) ;
3436
35- if ( ! force && buildJson . apiCopilotConfig != null && ! ( await this . prompts . confirmOverwrite ( ) ) )
36- return ActionResult . error ( "Exiting without making any change." ) ;
37+ if ( ! force && buildJson . apiCopilotConfig != null && ! ( await this . prompts . confirmOverwrite ( ) ) ) {
38+ this . prompts . cancelled ( ) ;
39+ return ActionResult . cancelled ( ) ;
40+ }
3741
3842 const response = await this . prompts . spinnerAccountInfo (
39- ( ) => this . apiService . getAccountInfo ( this . configDir , this . authKey ) ) ;
43+ this . apiService . getAccountInfo ( this . configDir , this . authKey ) ) ;
4044
4145 if ( response . isErr ( ) ) {
42- return ActionResult . error ( response . _unsafeUnwrapErr ( ) ) ;
46+ // TODO: add error prompt response._unsafeUnwrapErr()
47+ return ActionResult . failed ( ) ;
4348 }
4449
4550 const apiCopilotKey = await this . selectCopilotKey ( response . _unsafeUnwrap ( ) , force ) ;
4651 if ( apiCopilotKey instanceof Error ) {
47- return ActionResult . error ( apiCopilotKey . message ) ;
52+
53+ // return ActionResult.error(apiCopilotKey.message);
54+ return ActionResult . failed ( ) ;
4855 }
4956
5057 const welcomeMessage = await this . getWelcomeMessage ( ) ;
@@ -59,7 +66,6 @@ export class CopilotAction {
5966
6067 this . prompts . copilotConfigured ( enable , apiCopilotKey ) ;
6168
62-
6369 return ActionResult . success ( ) ;
6470 }
6571
@@ -69,7 +75,7 @@ export class CopilotAction {
6975 subscription . ApiCopilotKeys === undefined ||
7076 subscription . ApiCopilotKeys . length === 0
7177 ) {
72- return new Error ( " No copilot key found for the current subscription. Please contact support at support@apimatic.io." ) ;
78+ return new Error ( ` No copilot key found for the current subscription. Please contact support at ${ format . var ( ' support@apimatic.io' ) } .` ) ;
7379 }
7480
7581 if ( subscription . ApiCopilotKeys . length === 1 ) {
0 commit comments