diff --git a/src/delete.ts b/src/delete.ts index 7bde802..79406ab 100644 --- a/src/delete.ts +++ b/src/delete.ts @@ -35,16 +35,28 @@ export const deleteBySelection = async (api: APIInterface): Promise => { 'Select the deployment to delete:' ); - const app = deployments.filter( - dep => - dep.suffix === project.split(' ')[0] && - dep.version === project.split(' ')[1] - )[0]; + // Parse the selected project string + const parts = project.split(' '); + const selectedSuffix = parts[0]; + const selectedVersion = parts[1]; + + if (!selectedSuffix || !selectedVersion) { + error('Invalid deployment selection format'); + } + + // Find the matching deployment + const app = deployments.find( + dep => dep.suffix === selectedSuffix && dep.version === selectedVersion + ); + + if (!app) { + error( + 'Selected deployment not found. It may have been deleted already.' + ); + } info(await del(app.prefix, app.suffix, app.version, api)); } catch (err) { error(String(err)); } }; - -// This can be better diff --git a/src/logs.ts b/src/logs.ts index 178710e..3d14afb 100644 --- a/src/logs.ts +++ b/src/logs.ts @@ -27,12 +27,19 @@ const showLogs = async ( let logsTill: string[] = ['']; - let app: Deployment; + let app: Deployment | undefined; let status: DeployStatus = 'create'; while (status !== 'ready') { - app = (await api.inspect()).filter(dep => dep.suffix === suffix)[0]; + const deployments = (await api.inspect()).filter( + dep => dep.suffix === suffix + ); + + if (deployments.length === 0) { + error(`Deployment with suffix "${suffix}" not found`); + } + app = deployments[0]; status = app.status; const prefix = app.prefix;