import { ICli, ICliRoutes } from '../types'; import { TryCatch } from '../helpers'; import { ProjectService, InquirerService } from '../services'; import Config from '../config'; class ProjectsCli implements ICli { public routes: ICliRoutes[] = []; constructor() { this.routes.push({ command: 'projects', description: 'Get list of projects', subCommands: [ { command: 'list', description: 'Get list of projects', handler: this.getProjects, }, { command: 'create', description: 'Create project', handler: this.createProject, options: [ { flags: '-n, --project_name ', } ] } ] }); this.routes.push({ command: 'project', description: 'Get project by id', handler: this.getProject, options: [ { flags: '-i, --id ' }, ], }); } @TryCatch() public async getProjects() { const response = await ProjectService.getProjects(); console.log(response); } @TryCatch() public async getProject(option) { if (!option.id) { option.option.id = await InquirerService.takeInput('Type project id : '); } const response = await ProjectService.getProject(option.id); console.log(response?.project); } @TryCatch() public async createProject(option) { if (!option.project_name) { option.project_name = await InquirerService.takeInput('Type project name : '); } const project = await ProjectService.createProject(option.project_name); console.log(project); } public async selectProjectInteractive() { const projects = await ProjectService.getProjects().then(x => x.projects); if (!projects.length) { console.log(`Oops.. you don\'t have any projects created.\n Create project by running ${Config.PROJECT_NAME} projects create --project_name `); return; } const projectId = await InquirerService.askProject(projects); return projectId; } } export default new ProjectsCli();