@@ -2,7 +2,7 @@ import { Command, Flags } from "@oclif/core";
22import { readAuthConfig } from "../../utils/utils.js" ;
33import chalk from "chalk" ;
44import inquirer from "inquirer" ;
5- import { getProject , getProjects } from "../../utils/shared.js" ;
5+ import { getProject , getProjects , type Application } from "../../utils/shared.js" ;
66import type { Answers } from "./create.js" ;
77import axios from "axios" ;
88
@@ -17,6 +17,11 @@ export default class AppStop extends Command {
1717 description : 'ID of the project' ,
1818 required : false ,
1919 } ) ,
20+ environmentId : Flags . string ( {
21+ char : 'e' ,
22+ description : 'ID of the environment' ,
23+ required : false ,
24+ } ) ,
2025 applicationId : Flags . string ( {
2126 char : 'a' ,
2227 description : 'ID of the application to stop' ,
@@ -32,13 +37,17 @@ export default class AppStop extends Command {
3237 public async run ( ) : Promise < void > {
3338 const auth = await readAuthConfig ( this ) ;
3439 const { flags } = await this . parse ( AppStop ) ;
35- let { projectId, applicationId } = flags ;
40+ let { projectId, environmentId , applicationId } = flags ;
3641
3742 // Modo interactivo si no se proporcionan los flags necesarios
38- if ( ! projectId || ! applicationId ) {
43+ if ( ! projectId || ! environmentId || ! applicationId ) {
3944 console . log ( chalk . blue . bold ( "\n Listing all Projects \n" ) ) ;
4045 const projects = await getProjects ( auth , this ) ;
4146
47+ let selectedProject ;
48+ let selectedEnvironment ;
49+
50+ // 1. Seleccionar proyecto
4251 if ( ! projectId ) {
4352 const { project } = await inquirer . prompt < Answers > ( [
4453 {
@@ -51,19 +60,44 @@ export default class AppStop extends Command {
5160 type : "list" ,
5261 } ,
5362 ] ) ;
63+ selectedProject = project ;
5464 projectId = project . projectId ;
65+ } else {
66+ selectedProject = projects . find ( p => p . projectId === projectId ) ;
5567 }
5668
57- const projectSelected = await getProject ( projectId , auth , this ) ;
69+ // 2. Seleccionar environment del proyecto
70+ if ( ! environmentId ) {
71+ if ( ! selectedProject ?. environments || selectedProject . environments . length === 0 ) {
72+ this . error ( chalk . yellow ( "No environments found in this project." ) ) ;
73+ }
5874
59- if ( projectSelected . applications . length === 0 ) {
60- this . error ( chalk . yellow ( "No applications found in this project." ) ) ;
75+ const { environment } = await inquirer . prompt ( [
76+ {
77+ choices : selectedProject . environments . map ( ( env ) => ( {
78+ name : `${ env . name } (${ env . description } )` ,
79+ value : env ,
80+ } ) ) ,
81+ message : "Select an environment:" ,
82+ name : "environment" ,
83+ type : "list" ,
84+ } ,
85+ ] ) ;
86+ selectedEnvironment = environment ;
87+ environmentId = environment . environmentId ;
88+ } else {
89+ selectedEnvironment = selectedProject ?. environments ?. find ( e => e . environmentId === environmentId ) ;
6190 }
6291
92+ // 3. Seleccionar application del environment
6393 if ( ! applicationId ) {
94+ if ( ! selectedEnvironment ?. applications || selectedEnvironment . applications . length === 0 ) {
95+ this . error ( chalk . yellow ( "No applications found in this environment." ) ) ;
96+ }
97+
6498 const appAnswers = await inquirer . prompt ( [
6599 {
66- choices : projectSelected . applications . map ( ( app : { name : string ; applicationId : string } ) => ( {
100+ choices : selectedEnvironment . applications . map ( ( app : Application ) => ( {
67101 name : app . name ,
68102 value : app . applicationId ,
69103 } ) ) ,
0 commit comments